-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
Adding TTL to Create and Update
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,13 +465,12 @@ public async Task TestMessageTTL() | |
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
var cancellationToken = cts.Token; | ||
|
||
await using var server = NatsServer.StartJS(); | ||
await using var server = NatsServer.StartJSWithTrace(_output); | ||
await using var nats = server.CreateClientConnection(); | ||
|
||
var js = new NatsJSContext(nats); | ||
var kv = new NatsKVContext(js); | ||
|
||
await kv.DeleteStoreAsync("kv1"); | ||
var store = await kv.CreateStoreAsync(new NatsKVConfig("kv1") { AllowMsgTTL = true }, cancellationToken: cancellationToken); | ||
|
||
for (var i = 0; i < 10; i++) | ||
|
@@ -484,13 +483,6 @@ public async Task TestMessageTTL() | |
Assert.Equal(1ul, state.Info.State.FirstSeq); | ||
Assert.Equal(10ul, state.Info.State.LastSeq); | ||
|
||
// Sleep for half a second, all the messages should still be there | ||
await Task.Delay(500); | ||
state = await store.GetStatusAsync(); | ||
Assert.Equal(10, state.Info.State.Messages); | ||
Assert.Equal(1ul, state.Info.State.FirstSeq); | ||
Assert.Equal(10ul, state.Info.State.LastSeq); | ||
|
||
// Sleep for two seconds, now all the messages should be gone | ||
await Task.Delay(2000); | ||
state = await store.GetStatusAsync(); | ||
|
@@ -499,6 +491,41 @@ public async Task TestMessageTTL() | |
Assert.Equal(10ul, state.Info.State.LastSeq); | ||
} | ||
|
||
[Fact] | ||
public async Task TestMessageNeverExpire() | ||
{ | ||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
var cancellationToken = cts.Token; | ||
|
||
await using var server = NatsServer.StartJSWithTrace(_output); | ||
await using var nats = server.CreateClientConnection(); | ||
|
||
Check warning on line 502 in tests/NATS.Client.KeyValueStore.Tests/KeyValueStoreTest.cs
|
||
var js = new NatsJSContext(nats); | ||
var kv = new NatsKVContext(js); | ||
|
||
var store = await kv.CreateStoreAsync(new NatsKVConfig("kv1") { AllowMsgTTL = true, MaxAge = TimeSpan.FromSeconds(1) }, cancellationToken: cancellationToken); | ||
|
||
// The first message we publish is set to "never expire", therefore it won't age out with the MaxAge policy. | ||
await store.PutAsync($"k0", $"v0", TimeSpan.MaxValue, cancellationToken: cancellationToken); | ||
|
||
for (var i = 1; i < 11; i++) | ||
{ | ||
await store.PutAsync($"k{i}", $"v{i}", TimeSpan.FromSeconds(1), cancellationToken: cancellationToken); | ||
} | ||
|
||
var state = await store.GetStatusAsync(); | ||
Assert.Equal(11, state.Info.State.Messages); | ||
Assert.Equal(1ul, state.Info.State.FirstSeq); | ||
Assert.Equal(11ul, state.Info.State.LastSeq); | ||
|
||
// Sleep for two seconds, only the first message should be there | ||
await Task.Delay(2000); | ||
state = await store.GetStatusAsync(); | ||
Assert.Equal(1, state.Info.State.Messages); | ||
Assert.Equal(1ul, state.Info.State.FirstSeq); | ||
Assert.Equal(11ul, state.Info.State.LastSeq); | ||
} | ||
|
||
[Fact] | ||
public async Task History() | ||
{ | ||
|