public void CanCopySuccessfullyHandledMessageToAuditQueue() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); var resetEvent = new ManualResetEvent(false); adapter.Handle<string>(str => resetEvent.Set()); // act adapter.Bus.SendLocal("yo!"); // assert var message = GetMessageFromAuditQueue(); message.ShouldNotBe(null); var logicalMessages = message.Messages; var headers = message.Headers; logicalMessages.Length.ShouldBe(1); logicalMessages[0].ShouldBe("yo!"); headers.ShouldContainKeyAndValue(Headers.AuditReason, Headers.AuditReasons.Handled); headers.ShouldContainKeyAndValue(Headers.AuditMessageCopyTime, fakeTime.ToString("u")); headers.ShouldContainKeyAndValue(Headers.AuditSourceQueue, InputQueueAddress); }
public void CanRemoveMultipleTimeoutsAtOnce() { var justSomeUtcTimeStamp = new DateTime(2010, 3, 10, 12, 30, 15, DateTimeKind.Utc); storage.Add(new Timeout.Timeout { CorrelationId = "first", ReplyTo = "somebody", TimeToReturn = justSomeUtcTimeStamp, CustomData = null, }); storage.Add(new Timeout.Timeout { CorrelationId = "second", ReplyTo = "somebody", TimeToReturn = justSomeUtcTimeStamp, CustomData = null, }); TimeMachine.FixTo(justSomeUtcTimeStamp.AddSeconds(1)); var dueTimeoutsAfterFirstTimeout = storage.RemoveDueTimeouts(); dueTimeoutsAfterFirstTimeout.Count().ShouldBe(2); }
public void DoesNotActuallyRemoveTimeoutUntilItIsMarkedAsProcessed() { // arrange const string someRecognizablePieceOfCustomData = "this custom dizzle can be recognizzle!!"; var actualTimeWhenIWroteThis = new DateTime(2012, 11, 30, 22, 13, 00, DateTimeKind.Utc); storage.Add(new Rebus.Timeout.Timeout("someone", "wham!", actualTimeWhenIWroteThis.AddSeconds(20), Guid.Empty, someRecognizablePieceOfCustomData)); TimeMachine.FixTo(actualTimeWhenIWroteThis.AddSeconds(25)); // act List <DueTimeout> dueTimeoutsFromFirstCall; using (var dueTimeoutsResult = storage.GetDueTimeouts()) { dueTimeoutsFromFirstCall = dueTimeoutsResult.DueTimeouts.ToList(); } // this is where we'd have marked the due timeout as processed - instead, we pretend that didn't happen // (perhaps because the timeout service was interrupted) ... List <DueTimeout> dueTimeoutsFromSecondCall; using (var nextDueTimeoutsResult = storage.GetDueTimeouts()) { dueTimeoutsFromSecondCall = nextDueTimeoutsResult.DueTimeouts.ToList(); } // assert dueTimeoutsFromFirstCall.Count.ShouldBe(1); dueTimeoutsFromFirstCall.Single().CustomData.ShouldBe(someRecognizablePieceOfCustomData); dueTimeoutsFromSecondCall.Count().ShouldBe(1); dueTimeoutsFromSecondCall.Single().CustomData.ShouldBe(someRecognizablePieceOfCustomData); }
public void CanCopyPublishedMessageToAuditQueue() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); // act adapter.Bus.Publish("yo!"); // assert var message = GetMessageFromAuditQueue(); message.ShouldNotBe(null); var logicalMessages = message.Messages; var headers = message.Headers; logicalMessages.Length.ShouldBe(1); logicalMessages[0].ShouldBe("yo!"); headers.ShouldContainKeyAndValue(Headers.AuditReason, Headers.AuditReasons.Published); headers.ShouldContainKeyAndValue(Headers.AuditMessageCopyTime, fakeTime.ToString("u")); headers.ShouldContainKeyAndValue(Headers.AuditSourceQueue, InputQueueAddress); }
public void PublishedMessageIsCopiedOnlyOnceRegardlessOfNumberOfSubscribers() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber1"); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber2"); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber3"); // act adapter.Bus.Publish("yo!"); // assert var messages = MsmqTestHelper.GetMessagesFrom(AuditQueueName).ToList(); Console.WriteLine(string.Join(Environment.NewLine, messages)); messages.Count.ShouldBe(4); var stringMessages = messages.Where(m => m.Messages[0] is string).ToList(); Assert.That(stringMessages.Count, Is.EqualTo(1), "We should have only one single copy of the published messages!"); }
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 Rebus.Timeout.Timeout("somebody", "first", someUtcTimeStamp, new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), null)); storage.Add(new Rebus.Timeout.Timeout("somebody", "second", anotherUtcTimeStamp, new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), thirtytwoKilobytesOfDollarSigns)); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(-1)); var dueTimeoutsBeforeTimeout = GetTimeouts(); dueTimeoutsBeforeTimeout.Count().ShouldBe(0); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(1)); using (var firstTimeoutsResult = storage.GetDueTimeouts()) { var dueTimeoutsAfterFirstTimeout = firstTimeoutsResult.DueTimeouts; 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); firstTimeout.MarkAsProcessed(); } var dueTimeoutsAfterHavingMarkingTheFirstTimeoutAsProcessed = GetTimeouts(); dueTimeoutsAfterHavingMarkingTheFirstTimeoutAsProcessed.Count().ShouldBe(0); TimeMachine.FixTo(anotherUtcTimeStamp.AddSeconds(1)); using (var secondTimeoutsResult = storage.GetDueTimeouts()) { var dueTimeoutsAfterSecondTimeout = secondTimeoutsResult.DueTimeouts; 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); secondTimeout.MarkAsProcessed(); } GetTimeouts().Count().ShouldBe(0); }
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); }
public void CanRemoveMultipleTimeoutsAtOnce() { var justSomeUtcTimeStamp = new DateTime(2010, 3, 10, 12, 30, 15, DateTimeKind.Utc); storage.Add(new Rebus.Timeout.Timeout("somebody", "first", justSomeUtcTimeStamp, Guid.Empty, null)); storage.Add(new Rebus.Timeout.Timeout("somebody", "second", justSomeUtcTimeStamp, Guid.Empty, null)); TimeMachine.FixTo(justSomeUtcTimeStamp.AddSeconds(1)); var dueTimeoutsAfterFirstTimeout = storage.GetDueTimeouts(); dueTimeoutsAfterFirstTimeout.Count().ShouldBe(2); }
public void ErrorTrackerRemovesAMessageWhichTimedOut() { //Arrange const string messageId = "testId"; var fakeTime = RebusTimeMachine.Now(); TimeMachine.FixTo(fakeTime); //Act errorTracker.TrackDeliveryFail(messageId, new Exception()); errorTracker.TrackDeliveryFail(messageId, new Exception()); TimeMachine.FixTo(fakeTime.Add(timeoutSpan)); errorTracker.CheckForMessageTimeout(); var errorText = errorTracker.GetErrorText(messageId); //Assert Assert.That(errorText, Is.Empty); }
public void ErrorTrackerRemovesMultipleMessagesWhichTimedOut() { //Arrange const string messageId = "testId"; const string messageId2 = "testId2"; var fakeTime = RebusTimeMachine.Now(); TimeMachine.FixTo(fakeTime); //Act errorTracker.TrackDeliveryFail(messageId, new Exception()); TimeMachine.FixTo(fakeTime.Add(TimeSpan.FromMinutes(10))); errorTracker.TrackDeliveryFail(messageId2, new Exception()); TimeMachine.FixTo(fakeTime.AddDays(1).AddMinutes(10)); errorTracker.CheckForMessageTimeout(); var errorText1 = errorTracker.GetErrorText(messageId); var errorText2 = errorTracker.GetErrorText(messageId2); //Assert Assert.That(errorText1, Is.Empty); Assert.That(errorText2, Is.Empty); }
public void ExertsRowLevelLockingBecauseItCan() { storage.EnsureTableIsCreated(); var now = DateTime.UtcNow; var t1 = now; var t2 = now.AddDays(1); storage.Add(new Rebus.Timeout.Timeout("bimse", "1", t1, Guid.Empty, "hej")); storage.Add(new Rebus.Timeout.Timeout("bimse", "2", t2, Guid.Empty, "hej")); TimeMachine.FixTo(t1.AddMinutes(-10)); using (var resultBefore = storage.GetDueTimeouts()) { var timeoutsBefore = resultBefore.DueTimeouts.ToList(); TimeMachine.FixTo(t1.AddMinutes(10)); using (var resultsAfterT1 = storage.GetDueTimeouts()) { var timeoutsAfterT1 = resultsAfterT1.DueTimeouts.ToList(); TimeMachine.FixTo(t2.AddMinutes(10)); using (var resultsAfterT2 = storage.GetDueTimeouts()) { var timeoutsAfterT2 = resultsAfterT2.DueTimeouts.ToList(); Assert.That(timeoutsBefore.Count, Is.EqualTo(0)); Assert.That(timeoutsAfterT1.Count, Is.EqualTo(1)); Assert.That(timeoutsAfterT2.Count, Is.EqualTo(1)); } } } }
public void ErrorTrackerDoesntRemoveMessageWhichHasntTimedOut() { //Arrange const string messageId = "testId"; const string messageId2 = "testId2"; var fakeTime = DateTime.UtcNow; //Act TimeMachine.FixTo(fakeTime); errorTracker.TrackDeliveryFail(messageId, new Exception(string.Format("This exception occurred at {0}", Time.Now()))); TimeMachine.FixTo(fakeTime + TimeSpan.FromMinutes(10)); errorTracker.TrackDeliveryFail(messageId2, new Exception(string.Format("This exception occurred at {0}", Time.Now()))); TimeMachine.FixTo(fakeTime + TimeSpan.FromDays(1) + TimeSpan.FromMinutes(5)); errorTracker.CheckForMessageTimeout(); var errorText1 = errorTracker.GetErrorText(messageId); var errorText2 = errorTracker.GetErrorText(messageId2); //Assert Assert.That(errorText1, Is.Empty); Assert.That(errorText2, Is.Not.Empty); }