feat(store-and-forward): GetAllMessagesAsync/ReplaceAllAsync storage primitives for standby buffer resync
This commit is contained in:
@@ -748,4 +748,46 @@ public class StoreAndForwardStorageTests : IAsyncLifetime, IDisposable
|
||||
var result = await cmd.ExecuteScalarAsync();
|
||||
return result is DBNull ? null : result;
|
||||
}
|
||||
|
||||
// ── Task 20: buffer-resync storage primitives ──
|
||||
|
||||
private static StoreAndForwardMessage NewMsg(
|
||||
string id,
|
||||
StoreAndForwardMessageStatus status = StoreAndForwardMessageStatus.Pending,
|
||||
DateTimeOffset? createdAt = null) => new()
|
||||
{
|
||||
Id = id,
|
||||
Category = StoreAndForwardCategory.ExternalSystem,
|
||||
Target = "t",
|
||||
PayloadJson = "{}",
|
||||
RetryCount = 0,
|
||||
MaxRetries = 50,
|
||||
RetryIntervalMs = 30000,
|
||||
CreatedAt = createdAt ?? DateTimeOffset.UtcNow,
|
||||
Status = status,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllMessages_ReturnsEveryStatus_OldestFirst_UpToLimit()
|
||||
{
|
||||
var @base = DateTimeOffset.UtcNow;
|
||||
await _storage.EnqueueAsync(NewMsg("p1", StoreAndForwardMessageStatus.Pending, @base));
|
||||
await _storage.EnqueueAsync(NewMsg("k1", StoreAndForwardMessageStatus.Parked, @base.AddSeconds(1)));
|
||||
await _storage.EnqueueAsync(NewMsg("p2", StoreAndForwardMessageStatus.Pending, @base.AddSeconds(2)));
|
||||
|
||||
var (all, truncated) = await _storage.GetAllMessagesAsync(limit: 2);
|
||||
Assert.Equal(new[] { "p1", "k1" }, all.Select(m => m.Id)); // every status, oldest-first
|
||||
Assert.True(truncated); // a third row exists beyond the limit
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReplaceAll_SwapsTheEntireBuffer_Atomically()
|
||||
{
|
||||
await _storage.EnqueueAsync(NewMsg("stale"));
|
||||
await _storage.ReplaceAllAsync(new[] { NewMsg("fresh-1"), NewMsg("fresh-2") });
|
||||
|
||||
Assert.Null(await _storage.GetMessageByIdAsync("stale"));
|
||||
Assert.NotNull(await _storage.GetMessageByIdAsync("fresh-1"));
|
||||
Assert.NotNull(await _storage.GetMessageByIdAsync("fresh-2"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user