Skip to content

Commit

Permalink
Configure KV streams the same way as the Nats GO lib (history = 1 and…
Browse files Browse the repository at this point in the history
… DiscardPolicy = NEW)

Fixes #37
  • Loading branch information
Christoffer Lindahl authored and nekufa committed Jan 17, 2024
1 parent 735b49f commit 2eaf2fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/KeyValue/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Basis\Nats\KeyValue;

use Basis\Nats\Stream\Configuration as StreamConfiguration;
use Basis\Nats\Stream\DiscardPolicy;

class Configuration
{
Expand All @@ -22,11 +23,12 @@ public function configureStream(StreamConfiguration $configuration): self
{
$configuration
->setAllowRollupHeaders(true)
->setDiscardPolicy(DiscardPolicy::NEW)
->setDenyDelete(false)
->setMaxAge($this->getTtl() ?? 0)
->setMaxBytes($this->getMaxBytes())
->setMaxMessageSize($this->getMaxValueSize())
->setMaxMessagesPerSubject($this->getHistory())
->setMaxMessagesPerSubject($this->getHistory() ?? 1)
->setReplicas($this->getReplicas() ?? 1)
->setSubjects([strtoupper("\$kv.$this->name.*")]);

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/KeyValue/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function testBasics()

$bucket->update('username', 'bazyaba', $bucket->getEntry('username')->revision);
$this->assertSame($bucket->get('username'), 'bazyaba');
$this->assertSame(2, $bucket->getStatus()->values);
$this->assertSame(1, $bucket->getStatus()->values);

$bucket->delete('username');

// username null value in history
$this->assertSame($bucket->get('username'), null);
$this->assertSame(3, $bucket->getStatus()->values);
$this->assertSame(1, $bucket->getStatus()->values);

// purge key logs
$bucket->purge('username');
Expand Down

0 comments on commit 2eaf2fd

Please sign in to comment.