From 2634235eb5a2c65a17ea3f1ec4d851190fc4f1ab Mon Sep 17 00:00:00 2001 From: Martin Beukman Date: Wed, 3 Jul 2024 12:15:10 +0200 Subject: [PATCH] add some documentation and test to set MaxAge --- src/Stream/Configuration.php | 7 +++-- tests/Functional/StreamTest.php | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Stream/Configuration.php b/src/Stream/Configuration.php index 5179e11..3c5c779 100644 --- a/src/Stream/Configuration.php +++ b/src/Stream/Configuration.php @@ -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; } diff --git a/tests/Functional/StreamTest.php b/tests/Functional/StreamTest.php index 8a4d471..261f5e5 100644 --- a/tests/Functional/StreamTest.php +++ b/tests/Functional/StreamTest.php @@ -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');