Path: redb-route/tests/redb.Route.Tests.Sql/SqlConsumerListDeliveryTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Sql/SqlConsumerListDeliveryTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Sql;
using redb.Route.Tests.Sql.E2E.Infrastructure;
namespace redb.Route.Tests.Sql;
///
/// A poll that delivers one list (pollDelivery=List, Apache Camel useIterator=false): one exchange carries every
/// polled row; onSuccess / onFailure and onBatchComplete run once for it, with values from headers and
/// param.* — a list has no row columns to bind.
///
public sealed class SqlConsumerListDeliveryTests : IDisposable
{
private readonly SqliteTestHelper _db = new();
public SqlConsumerListDeliveryTests()
{
_db.Execute("CREATE TABLE outbox (id INTEGER PRIMARY KEY, message TEXT NOT NULL, processed INTEGER NOT NULL DEFAULT 0)");
_db.Execute("CREATE TABLE poll_log (note TEXT)");
_db.Execute("INSERT INTO outbox (id, message) VALUES (1, 'm1'), (2, 'm2'), (3, 'm3')");
}
public void Dispose() => _db.Dispose();
[Fact]
public async Task ListDelivery_OneExchangeWithAllRows()
{
var received = new List();
await PollAsync(new(), received);
received.Should().ContainSingle("the whole poll is one exchange");
var rows = received[0].In.Body.Should().BeAssignableTo>>().Subject;
rows.Select(r => r["message"]).Should().Equal("m1", "m2", "m3");
received[0].In.Headers[SqlHeaders.RowCount].Should().Be(3);
}
[Fact]
public async Task ListDelivery_OutputClass_TypedList()
{
var received = new List();
await PollAsync(new() { ["outputClass"] = typeof(OutboxRow).AssemblyQualifiedName! }, received);
received.Should().ContainSingle();
received[0].In.Body.Should().BeAssignableTo>()
.Which.Select(r => r.Message).Should().Equal("m1", "m2", "m3");
}
[Fact]
public async Task ListDelivery_MaxMessagesPerPoll_LimitsRows()
{
var received = new List();
await PollAsync(new() { ["maxMessagesPerPoll"] = "2" }, received);
received.Should().ContainSingle();
received[0].In.Body.Should().BeAssignableTo>>().Which.Should().HaveCount(2);
}
[Fact]
public async Task ListDelivery_OnSuccessAndOnBatchComplete_RunOnce()
{
await PollAsync(new()
{
["onSuccess"] = "INSERT INTO poll_log (note) VALUES ('success')",
["onBatchComplete"] = "INSERT INTO poll_log (note) VALUES ('complete')",
}, []);
Notes().Should().Equal(new object?[] { "success", "complete" }, "the list is one exchange: one onSuccess, one onBatchComplete");
}
[Fact]
public async Task ListDelivery_ProcessorFails_OnFailureOnce_TransactedRollsBack()
{
await PollAsync(new()
{
["transacted"] = "true",
["onSuccess"] = "UPDATE outbox SET processed = 1",
["onFailure"] = "INSERT INTO poll_log (note) VALUES (:#redbError)",
}, [], fail: true);
Convert.ToInt64(_db.ExecuteScalar("SELECT COUNT(*) FROM outbox WHERE processed = 1")).Should().Be(0);
Notes().Should().BeEmpty("onFailure ran in the consumer transaction, which the failure rolled back");
}
[Fact]
public async Task ListDelivery_ProcessorFails_OnFailureOnce_NotTransacted()
{
await PollAsync(new() { ["onFailure"] = "INSERT INTO poll_log (note) VALUES (:#redbError)" }, [], fail: true);
Notes().Should().ContainSingle("the list failed once").Which.Should().Be("route failed");
}
[Fact]
public async Task ListDelivery_EmptyResult_RouteEmptyResultSet_DeliversEmptyList()
{
_db.Execute("DELETE FROM outbox");
var received = new List();
await PollAsync(new() { ["routeEmptyResultSet"] = "true" }, received);
received.Should().ContainSingle();
received[0].In.Body.Should().BeAssignableTo>>().Which.Should().BeEmpty();
}
[Fact]
public async Task ListDelivery_StreamList_BodyIsAStreamTheRouteReads()
{
var read = new List