Files
natsnet/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/JetStream/NatsConsumerTests.cs

39 lines
1.3 KiB
C#

// Copyright 2012-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0
using Shouldly;
using ZB.MOM.NatsNet.Server;
namespace ZB.MOM.NatsNet.Server.Tests.JetStream;
public sealed class NatsConsumerTests
{
[Fact]
public void Create_SetLeader_UpdateConfig_AndStop_ShouldBehave()
{
var account = new Account { Name = "A" };
var streamCfg = new StreamConfig { Name = "S", Subjects = ["foo"], Storage = StorageType.FileStorage };
var stream = NatsStream.Create(account, streamCfg, null, null, null, null);
stream.ShouldNotBeNull();
var cfg = new ConsumerConfig { Durable = "D", AckPolicy = AckPolicy.AckExplicit };
var consumer = NatsConsumer.Create(stream!, cfg, ConsumerAction.CreateOrUpdate, null);
consumer.ShouldNotBeNull();
consumer!.IsLeader().ShouldBeFalse();
consumer.SetLeader(true, 3);
consumer.IsLeader().ShouldBeTrue();
var updated = new ConsumerConfig { Durable = "D", AckPolicy = AckPolicy.AckAll };
consumer.UpdateConfig(updated);
consumer.GetConfig().AckPolicy.ShouldBe(AckPolicy.AckAll);
var info = consumer.GetInfo();
info.Stream.ShouldBe("S");
info.Name.ShouldBe("D");
consumer.Stop();
consumer.IsLeader().ShouldBeFalse();
}
}