public void CanStoreAndRemoveTimeouts() { var someUtcTimeStamp = new DateTime(2010, 3, 10, 12, 30, 15, DateTimeKind.Utc); var anotherUtcTimeStamp = someUtcTimeStamp.AddHours(2); var thirtytwoKilobytesOfDollarSigns = new string('$', 32768); storage.Add(new Timeout.Timeout { SagaId = new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), CorrelationId = "first", ReplyTo = "somebody", TimeToReturn = someUtcTimeStamp, CustomData = null, }); storage.Add(new Timeout.Timeout { SagaId = new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), CorrelationId = "second", ReplyTo = "somebody", TimeToReturn = anotherUtcTimeStamp, CustomData = thirtytwoKilobytesOfDollarSigns, }); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(-1)); var dueTimeoutsBeforeTimeout = storage.RemoveDueTimeouts(); dueTimeoutsBeforeTimeout.Count().ShouldBe(0); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(1)); var dueTimeoutsAfterFirstTimeout = storage.RemoveDueTimeouts(); var firstTimeout = dueTimeoutsAfterFirstTimeout.SingleOrDefault(); firstTimeout.ShouldNotBe(null); firstTimeout.SagaId.ShouldBe(new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")); firstTimeout.CorrelationId.ShouldBe("first"); firstTimeout.ReplyTo.ShouldBe("somebody"); firstTimeout.TimeToReturn.ShouldBe(someUtcTimeStamp); TimeMachine.FixTo(anotherUtcTimeStamp.AddSeconds(1)); var dueTimeoutsAfterSecondTimeout = storage.RemoveDueTimeouts(); var secondTimeout = dueTimeoutsAfterSecondTimeout.SingleOrDefault(); secondTimeout.ShouldNotBe(null); secondTimeout.SagaId.ShouldBe(new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")); secondTimeout.CorrelationId.ShouldBe("second"); secondTimeout.ReplyTo.ShouldBe("somebody"); secondTimeout.TimeToReturn.ShouldBe(anotherUtcTimeStamp); secondTimeout.CustomData.ShouldBe(thirtytwoKilobytesOfDollarSigns); }
void CheckCallbacks(object sender, ElapsedEventArgs e) { using (var tx = new TransactionScope()) { var dueTimeouts = storeTimeouts.RemoveDueTimeouts(); foreach (var timeout in dueTimeouts) { log.Info("Timeout!: {0} -> {1}", timeout.CorrelationId, timeout.ReplyTo); bus.Routing.Send(timeout.ReplyTo, new TimeoutReply { SagaId = timeout.SagaId, CorrelationId = timeout.CorrelationId, DueTime = timeout.TimeToReturn, CustomData = timeout.CustomData, }); } tx.Complete(); } }