feat: define jetstream storage interfaces
This commit is contained in:
31
tests/NATS.Server.Tests/StreamStoreContractTests.cs
Normal file
31
tests/NATS.Server.Tests/StreamStoreContractTests.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using NATS.Server.JetStream.Models;
|
||||
using NATS.Server.JetStream.Storage;
|
||||
|
||||
namespace NATS.Server.Tests;
|
||||
|
||||
public class StreamStoreContractTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Append_increments_sequence_and_updates_state()
|
||||
{
|
||||
var store = new FakeStreamStore();
|
||||
var seq = await store.AppendAsync("foo", "bar"u8.ToArray(), default);
|
||||
|
||||
seq.ShouldBe((ulong)1);
|
||||
(await store.GetStateAsync(default)).Messages.ShouldBe((ulong)1);
|
||||
}
|
||||
|
||||
private sealed class FakeStreamStore : IStreamStore
|
||||
{
|
||||
private ulong _last;
|
||||
|
||||
public ValueTask<ulong> AppendAsync(string subject, ReadOnlyMemory<byte> payload, CancellationToken ct)
|
||||
{
|
||||
_last++;
|
||||
return ValueTask.FromResult(_last);
|
||||
}
|
||||
|
||||
public ValueTask<StreamState> GetStateAsync(CancellationToken ct)
|
||||
=> ValueTask.FromResult(new StreamState { Messages = _last });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user