public async Task Should_delete_all_OutboxRecords_that_have_been_dispatched() { var id = Guid.NewGuid().ToString("N"); var context = new ContextBag(); var persister = new OutboxPersister(store, "TestEndpoint", CreateTestSessionOpener()); using (var transaction = await persister.BeginTransaction(context)) { await persister.Store(new OutboxMessage("NotDispatched", new TransportOperation[0]), transaction, context); await transaction.Commit(); } var outboxMessage = new OutboxMessage(id, new [] { new TransportOperation(id, new Dictionary <string, string>(), new byte[1024 * 5], new Dictionary <string, string>()) }); using (var transaction = await persister.BeginTransaction(context)) { await persister.Store(outboxMessage, transaction, context); await transaction.Commit(); } await persister.SetAsDispatched(id, context); await Task.Delay(TimeSpan.FromSeconds(1)); //Need to wait for dispatch logic to finish //WaitForUserToContinueTheTest(store); WaitForIndexing(); var cleaner = new OutboxRecordsCleaner(store); await cleaner.RemoveEntriesOlderThan(DateTime.UtcNow.AddMinutes(1)); using (var s = store.OpenAsyncSession()) { var result = await s.Query <OutboxRecord>().ToListAsync(); Assert.AreEqual(1, result.Count); Assert.AreEqual("NotDispatched", result[0].MessageId); } }
public async Task Should_delete_all_dispatched_outbox_records() { // arrange var persister = new OutboxPersister("TestEndpoint", CreateTestSessionOpener(), default); var context = new ContextBag(); var incomingMessageId = SimulateIncomingMessage(context).MessageId; var dispatchedOutboxMessage = new OutboxMessage(incomingMessageId, new TransportOperation[0]); var notDispatchedOutgoingMessage = new OutboxMessage("NotDispatched", new TransportOperation[0]); using (var transaction = await persister.BeginTransaction(context)) { await persister.Store(dispatchedOutboxMessage, transaction, context); await persister.Store(notDispatchedOutgoingMessage, transaction, context); await transaction.Commit(); } await persister.SetAsDispatched(dispatchedOutboxMessage.MessageId, context); await Task.Delay(TimeSpan.FromSeconds(1)); // wait for dispatch logic to finish WaitForIndexing(); var cleaner = new OutboxRecordsCleaner(store); // act await cleaner.RemoveEntriesOlderThan(DateTime.UtcNow.AddMinutes(1)); // assert using (var session = store.OpenAsyncSession()) { var outboxRecords = await session.Query <OutboxRecord>().ToListAsync(); Assert.AreEqual(1, outboxRecords.Count); Assert.AreEqual(notDispatchedOutgoingMessage.MessageId, outboxRecords.Single().MessageId); } }
public OutboxCleaner(OutboxRecordsCleaner cleaner, ReadOnlySettings settings) { this.cleaner = cleaner; this.settings = settings; this.logger = LogManager.GetLogger<OutboxCleaner>(); }