task6: implement batch38 group E state snapshot and wait queue

This commit is contained in:
Joseph Doherty
2026-03-01 00:39:08 -05:00
parent 9fbcafb2a3
commit df3b44789b
7 changed files with 291 additions and 0 deletions

View File

@@ -78,4 +78,52 @@ public sealed class ConsumerStateTests
state.Delivered.Stream.ShouldBe(100UL);
state.AckFloor.Stream.ShouldBe(99UL);
}
[Fact]
public void StoreStateAndInfoSamplingAndFiltering_ShouldBehave()
{
var consumer = CreateConsumer();
var state = new ConsumerState
{
Delivered = new SequencePair { Consumer = 11, Stream = 22 },
AckFloor = new SequencePair { Consumer = 10, Stream = 21 },
Pending = new Dictionary<ulong, Pending> { [22] = new Pending { Sequence = 11, Timestamp = 1 } },
};
consumer.ApplyState(state);
consumer.SetStoreState(state);
consumer.WriteStoreState().Delivered.Stream.ShouldBe(22UL);
consumer.WriteStoreStateUnlocked().Delivered.Stream.ShouldBe(22UL);
consumer.ReadStoredState().Delivered.Stream.ShouldBe(22UL);
consumer.InitialInfo().Stream.ShouldBe("S");
consumer.ClearInitialInfo();
consumer.Info().Name.ShouldBe("D");
consumer.InfoWithSnap(state).Delivered.Stream.ShouldBe(22UL);
var (info, reply) = consumer.InfoWithSnapAndReply("r", state);
info.Stream.ShouldBe("S");
reply.ShouldBe("r");
consumer.SignalNewMessages();
consumer.UpdateConfig(new ConsumerConfig { Durable = "D", SampleFrequency = "100%", FilterSubject = "foo.*", AckPolicy = AckPolicy.AckExplicit });
consumer.ShouldSample().ShouldBeTrue();
consumer.SampleAck("reply").ShouldBeTrue();
consumer.ProcessAckMsg(22, 11, 2, "reply", doSample: true).ShouldBeTrue();
consumer.IsFiltered("foo.bar").ShouldBeTrue();
consumer.NeedAck().ShouldBeTrue();
}
[Fact]
public void NextReqFromMsg_ShouldParseBatchAndJson()
{
var (simple, simpleErr) = NatsConsumer.NextReqFromMsg("5"u8);
simpleErr.ShouldBeNull();
simple.ShouldNotBeNull();
simple!.Batch.ShouldBe(5);
var (jsonReq, jsonErr) = NatsConsumer.NextReqFromMsg("{\"batch\":2,\"expires\":\"00:00:01\"}"u8);
jsonErr.ShouldBeNull();
jsonReq.ShouldNotBeNull();
jsonReq!.Batch.ShouldBe(2);
}
}