public async Task UpdatesTimeOfLastRead() { const string knownId = "known id"; using (var source = new MemoryStream(new byte[0])) { await _storage.Save(knownId, source); } var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime); Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime); var justSomeTime = new DateTimeOffset(1.January(2016)); RebusTimeMachine.FakeIt(justSomeTime); _storage.Read(knownId).Result.Dispose(); var metadata = await _storage.ReadMetadata(knownId); Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True); var readTimeMetadata = metadata[MetadataKeys.ReadTime]; var readTime = DateTimeOffset.Parse(readTimeMetadata); Assert.That(readTime, Is.EqualTo(justSomeTime), $"Expected that the '{MetadataKeys.ReadTime}' metadata value '{readTimeMetadata}' would equal {justSomeTime} when passed to DateTimeOffset.Parse(...)"); }
public async Task TimeoutsAreNotRemovedIfTheyAreNotMarkedAsComplete() { var theFuture = RebusTime.Now.AddMinutes(1); await _timeoutManager.Defer(theFuture, HeadersWith("i know u"), EmptyBody()); RebusTimeMachine.FakeIt(theFuture + TimeSpan.FromSeconds(1)); using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(1), "Did not get the expected number of timeouts - debug info: {0}", _factory.GetDebugInfo()); } using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(1), "Did not get the expected number of timeouts - debug info: {0}", _factory.GetDebugInfo()); // mark as complete await dueTimeoutsInTheFuture[0].MarkAsCompleted(); } using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(0), "Did not get the expected number of timeouts - debug info: {0}", _factory.GetDebugInfo()); } }
public async Task CanGetStandardMetada() { var fakeTime = new DateTimeOffset(17.June(2016)); RebusTimeMachine.FakeIt(fakeTime); const string knownId = "known id"; var data = new byte[] { 1, 2, 3 }; using (var source = new MemoryStream(data)) { await _storage.Save(knownId, source); } var readMetadata = await _storage.ReadMetadata(knownId); // special case: zipped data has different size (and is actually bigger in this case :)) if (_storage is ZippingDataBusStorageDecorator) { Assert.That(readMetadata[MetadataKeys.Length], Is.EqualTo("23")); } else { Assert.That(readMetadata[MetadataKeys.Length], Is.EqualTo("3")); } Assert.That(readMetadata[MetadataKeys.SaveTime], Is.EqualTo(fakeTime.ToString("O"))); }
public async Task TimeoutsAreNotRemovedIfTheyAreNotMarkedAsComplete() { var theFuture = DateTimeOffset.Now.AddMinutes(1); await _timeoutManager.Defer(theFuture, HeadersWith("i know u"), EmptyBody()); RebusTimeMachine.FakeIt(theFuture + TimeSpan.FromSeconds(1)); using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(1)); } using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(1)); // mark as complete dueTimeoutsInTheFuture[0].MarkAsCompleted(); } using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(0)); } }
public async Task GetQueueVisibilityDelayOrNull_StillReturnsPositiveTimespans() { var sendInstant = DateTimeOffset.Now; var deferDate = sendInstant.AddMilliseconds(350); RebusTimeMachine.FakeIt(sendInstant); var result = AzureStorageQueuesTransport.GetQueueVisibilityDelayOrNull(new Dictionary <string, string> { { Headers.DeferredUntil, deferDate.ToString("O") } }); RebusTimeMachine.Reset(); Assert.AreEqual(result, TimeSpan.FromMilliseconds(350)); }
public void LogsAfterSilencePeriodIsOver() { var now = DateTime.UtcNow; var ignorant = new Ignorant { SilencePeriods = new[] { TimeSpan.FromMinutes(1) } }; RebusTimeMachine.FakeIt(now); var first = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(1.1)); var second = ignorant.IsToBeIgnored(new ApplicationException("hej")); Assert.That(first, Is.True); Assert.That(second, Is.False); }
public void GoesOnToNextSilencePeriodAfterTheFirstHasElapsed() { var now = DateTime.UtcNow; var ignorant = new Ignorant { SilencePeriods = new[] { TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10) } }; RebusTimeMachine.FakeIt(now); var first = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(1.1)); var second = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(11.1)); var third = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(11.2)); var fourth = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(21.2)); var fifth = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(21.3)); var sixth = ignorant.IsToBeIgnored(new ApplicationException("hej")); Assert.That(first, Is.True); Assert.That(second, Is.False); Assert.That(third, Is.True); Assert.That(fourth, Is.False); Assert.That(fifth, Is.True); Assert.That(sixth, Is.False); }
public async Task TimeoutsAreNotReturnedUntilTheyAreActuallyDue() { var theFuture = DateTimeOffset.Now.AddMinutes(1); var evenFurtherIntoTheFuture = DateTimeOffset.Now.AddMinutes(8); await _timeoutManager.Defer(theFuture, HeadersWith("i know u"), EmptyBody()); await _timeoutManager.Defer(evenFurtherIntoTheFuture, HeadersWith("i know u too"), EmptyBody()); using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsNow = result.ToList(); Assert.That(dueTimeoutsNow.Count, Is.EqualTo(0)); } RebusTimeMachine.FakeIt(theFuture); using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsInTheFuture = result.ToList(); Assert.That(dueTimeoutsInTheFuture.Count, Is.EqualTo(1)); Assert.That(dueTimeoutsInTheFuture[0].Headers[Headers.MessageId], Is.EqualTo("i know u")); await dueTimeoutsInTheFuture[0].MarkAsCompleted(); } RebusTimeMachine.FakeIt(evenFurtherIntoTheFuture); using (var result = await _timeoutManager.GetDueMessages()) { var dueTimeoutsFurtherIntoInTheFuture = result.ToList(); Assert.That(dueTimeoutsFurtherIntoInTheFuture.Count, Is.EqualTo(1)); Assert.That(dueTimeoutsFurtherIntoInTheFuture[0].Headers[Headers.MessageId], Is.EqualTo("i know u too")); await dueTimeoutsFurtherIntoInTheFuture[0].MarkAsCompleted(); } }
public void ResetsWhenResetIsCalled() { var now = DateTime.UtcNow; var ignorant = new Ignorant { SilencePeriods = new[] { TimeSpan.FromMinutes(1) } }; RebusTimeMachine.FakeIt(now); var first = ignorant.IsToBeIgnored(new ApplicationException("hej")); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(0.9)); var second = ignorant.IsToBeIgnored(new ApplicationException("hej")); ignorant.Reset(); RebusTimeMachine.FakeIt(now + TimeSpan.FromMinutes(1.1)); var third = ignorant.IsToBeIgnored(new ApplicationException("hej")); Assert.That(first, Is.True); Assert.That(second, Is.True); Assert.That(third, Is.True); }
public async Task UpdatesTimeOfLastRead() { const string knownId = "known id"; using (var source = new MemoryStream(new byte[0])) { await _storage.Save(knownId, source); } var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime); Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime); var justSomeTime = new DateTimeOffset(1.January(2016)); RebusTimeMachine.FakeIt(justSomeTime); _storage.Read(knownId).Result.Dispose(); var metadata = await _storage.ReadMetadata(knownId); Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True); Assert.That(metadata[MetadataKeys.ReadTime], Is.EqualTo(justSomeTime.ToString("O"))); }