Skip to content

Commit

Permalink
add some documentation and test to set MaxAge
Browse files Browse the repository at this point in the history
  • Loading branch information
digibeuk committed Jul 3, 2024
1 parent 702b29f commit 2634235
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Stream/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ public function setDuplicateWindow(?float $seconds): self
return $this;
}

public function setMaxAge(int $maxAge): self
/**
* set the max age in nanoSeconds
*/
public function setMaxAge(int $maxAgeNanoSeconds): self
{
$this->maxAge = $maxAge;
$this->maxAge = $maxAgeNanoSeconds;
return $this;
}

Expand Down
49 changes: 49 additions & 0 deletions tests/Functional/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,55 @@ public function testConsumerExpiration()
$this->assertSame($info, $client->connection->getInfoMessage());
}

public function testSetConfigRetentionPolicyToMaxAge(): void
{
$api = $this->createClient()
->getApi();
$stream = $api->getStream('tester');

$stream->getConfiguration()
->setRetentionPolicy(RetentionPolicy::LIMITS)
->setMaxAge(3_600_000_000_000)
->setStorageBackend(StorageBackend::MEMORY)
->setSubjects(['tester.greet', 'tester.bye']);

$stream->create();

$config = $stream->info()->config;

self::assertSame($config->retention, 'limits');
self::assertSame($config->storage, 'memory');
self::assertSame($config->subjects, ['tester.greet', 'tester.bye']);
self::assertSame($config->max_age, 3_600_000_000_000);

$stream->getConfiguration()
->setSubjects(['tester.greet']);
$stream->update();

self::assertSame($stream->info()->config->subjects, ['tester.greet']);

$stream->getConfiguration()
->setMaxAge(3_600_000_000_001)
->setSubjects(['tester.greet', 'tester.bye']);
$stream->update();

$api = $this->createClient()
->getApi();

$api->getStream('tester')
->getConfiguration()
->fromArray(
$stream->getConfiguration()
->toArray()
);

$configuration = $api->getStream('tester')
->getConfiguration();
self::assertSame($configuration->getRetentionPolicy(), 'limits');
self::assertSame($configuration->getStorageBackend(), 'memory');
self::assertSame($configuration->getSubjects(), ['tester.greet', 'tester.bye']);
}

public function testDeduplication()
{
$stream = $this->getClient()->getApi()->getStream('tester');
Expand Down

0 comments on commit 2634235

Please sign in to comment.