public async Task Should_only_return_timeouts_for_time_slice() { const int numberOfTimeoutsToAdd = 10; for (var i = 0; i < numberOfTimeoutsToAdd; i++) { await persister.Add(new TimeoutData { OwningTimeoutManager = string.Empty, Time = DateTime.UtcNow.AddHours(-1) }, new ContextBag()); } for (var i = 0; i < numberOfTimeoutsToAdd; i++) { await persister.Add(new TimeoutData { OwningTimeoutManager = string.Empty, Time = DateTime.UtcNow.AddHours(1) }, new ContextBag()); } var nextChunk = await GetNextChunk(); Assert.AreEqual(numberOfTimeoutsToAdd, nextChunk.DueTimeouts.Count()); }
void Add(InMemoryTimeoutPersister inMemoryTimeoutPersister) { inMemoryTimeoutPersister.Add(new TimeoutData { Time = DateTime.Now, Id = Thread.CurrentThread.Name }); }
public async Task When_multiple_NextTimeToRunQuery_is_min_date() { var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(2) }, new ContextBag()); var expectedDate = DateTime.Now.AddDays(1); await persister.Add(new TimeoutData { Time = expectedDate }, new ContextBag()); var result = await persister.GetNextChunk(now); Assert.AreEqual(expectedDate, result.NextTimeToQuery); }
public async Task TryRemove_when_non_existing_is_removed_should_return_false() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var inputTimeout = new TimeoutData(); await persister.Add(inputTimeout, new ContextBag()); var result = await persister.TryRemove(Guid.NewGuid().ToString(), new ContextBag()); Assert.False(result); }
public async Task TryRemove_when_existing_is_removed_should_return_true() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var inputTimeout = new TimeoutData(); await persister.Add(inputTimeout, new ContextBag()); var result = await persister.TryRemove(inputTimeout.Id, new ContextBag()); Assert.IsTrue(result); }
public async Task Peek_when_timeout_exists_should_return_timeout() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var inputTimeout = new TimeoutData(); await persister.Add(inputTimeout, new ContextBag()); var result = await persister.Peek(inputTimeout.Id, new ContextBag()); Assert.AreSame(inputTimeout, result); }
public void When_multiple_NextTimeToRunQuery_is_min_date() { DateTime nextTimeToRunQuery; var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(2) }); var expectedDate = DateTime.Now.AddDays(1); persister.Add(new TimeoutData { Time = expectedDate }); persister.GetNextChunk(now, out nextTimeToRunQuery); Assert.AreEqual(expectedDate, nextTimeToRunQuery); }
public async Task Peek_when_timeout_does_not_exist_should_return_null() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var inputTimeout = new TimeoutData(); await persister.Add(inputTimeout, new ContextBag()); var result = await persister.Peek(Guid.NewGuid().ToString(), new ContextBag()); Assert.IsNull(result); }
public async Task When_multiple_future_are_returned() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-4) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }, new ContextBag()); var result = await persister.GetNextChunk(DateTime.Now.AddDays(-3)); Assert.AreEqual(2, result.DueTimeouts.Count()); }
public void When_all_in_past_NextTimeToRunQuery_is_1_minute() { DateTime nextTimeToRunQuery; var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-3) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }); persister.GetNextChunk(now, out nextTimeToRunQuery); Assert.That(nextTimeToRunQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds); }
public void When_existing_is_removed_existing_is_outted() { var persister = new InMemoryTimeoutPersister(); var inputTimeout = new TimeoutData(); persister.Add(inputTimeout); TimeoutData removedTimeout; var removed = persister.TryRemove(inputTimeout.Id, out removedTimeout); Assert.IsTrue(removed); Assert.AreSame(inputTimeout, removedTimeout); }
public void When_multiple_future_are_returned() { DateTime nextTime; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-4) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }); var nextChunk = persister.GetNextChunk(DateTime.Now.AddDays(-3), out nextTime); Assert.AreEqual(2, nextChunk.Count()); }
public async Task Invoke_when_using_dtc_should_enlist_dispatch_in_transaction() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); await behavior.Invoke(CreateContext(timeoutData.Id)); var transportOperation = messageDispatcher.OutgoingTransportOperations.UnicastTransportOperations.Single(); Assert.AreEqual(DispatchConsistency.Default, transportOperation.RequiredDispatchConsistency); }
public async Task Invoke_when_dispatching_message_fails_should_keep_timeout_in_storage() { var messageDispatcher = new FailingMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); Assert.That(async () => await behavior.Invoke(CreateContext(timeoutData.Id)), Throws.InstanceOf<Exception>()); var result = await timeoutPersister.Peek(timeoutData.Id, null); Assert.NotNull(result); }
public async Task Invoke_when_message_dispatched_should_remove_timeout_from_timeout_storage() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); await behavior.Invoke(CreateContext(timeoutData.Id)); var result = await timeoutPersister.Peek(timeoutData.Id, null); Assert.Null(result); }
public async Task When_all_in_past_NextTimeToRunQuery_is_1_minute() { var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-3) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }, new ContextBag()); var result = await persister.GetNextChunk(now); Assert.That(result.NextTimeToQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds); }
public async Task Invoke_should_pass_transport_transaction_from_message_context() { var messageDispatcher = new FakeMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); var context = CreateContext(timeoutData.Id); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); await behavior.Invoke(context); Assert.AreSame(context.TransportTransaction, messageDispatcher.TransportTransactionUsed, "Wrong transport transaction passed to the dispatcher"); }
public async Task Invoke_when_dispatching_message_fails_should_keep_timeout_in_storage() { var messageDispatcher = new FailingMessageDispatcher(); var timeoutPersister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var behavior = new DispatchTimeoutBehavior(messageDispatcher, timeoutPersister, TransportTransactionMode.TransactionScope); var timeoutData = CreateTimeout(); await timeoutPersister.Add(timeoutData, null); Assert.That(async() => await behavior.Invoke(CreateContext(timeoutData.Id)), Throws.InstanceOf <Exception>()); var result = await timeoutPersister.Peek(timeoutData.Id, null); Assert.NotNull(result); }
public void When_existing_is_removed_by_saga_id() { var persister = new InMemoryTimeoutPersister(); var newGuid = Guid.NewGuid(); var inputTimeout = new TimeoutData { SagaId = newGuid }; persister.Add(inputTimeout); persister.RemoveTimeoutBy(newGuid); TimeoutData removedTimeout; var removed = persister.TryRemove(inputTimeout.Id, out removedTimeout); Assert.False(removed); }
public async Task When_existing_is_removed_by_saga_id() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var newGuid = Guid.NewGuid(); var inputTimeout = new TimeoutData { SagaId = newGuid }; await persister.Add(inputTimeout, new ContextBag()); await persister.RemoveTimeoutBy(newGuid, new ContextBag()); var result = await persister.TryRemove(inputTimeout.Id, new ContextBag()); Assert.IsFalse(result); }