public void CanClearOveride()
            {
                SystemTime.OverrideWith(() => DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)));
                SystemTime.ClearOverride();

                Assert.InRange(SystemTime.Now, DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1)), DateTime.UtcNow.Add(TimeSpan.FromMinutes(1)));
            }
            public void FirstWaitShouldNotSleep()
            {
                SystemTime.ClearOverride();

                var backoff = new ExponentialBackoff(TimeSpan.FromMilliseconds(100));

                Assert.Equal(TimeSpan.Zero, backoff.WaitUntilRetry());
            }
            protected UsingSagaEventHandlerBase()
            {
                var sagaMetadata     = new FakeSaga().GetMetadata();
                var commandPublisher = new Mock <IPublishCommands>();
                var executor         = new Action <Object, Event>((handler, e) => { ((FakeSaga)handler).Handle((Timeout)e); Handled = true; });
                var eventHandler     = new EventHandler(typeof(FakeSaga), typeof(Timeout), executor, () => { throw new NotSupportedException(); });

                SystemTime.ClearOverride();
                SagaEventHandler = new SagaTimeoutHandler(eventHandler, sagaMetadata, SagaStore.Object, new Lazy <IPublishCommands>(() => commandPublisher.Object));
            }
            public void SleepCannotExceedTimeRemaining()
            {
                SystemTime.ClearOverride();

                var backoff = new ExponentialBackoff(TimeSpan.FromMilliseconds(5), TimeSpan.FromSeconds(1));

                backoff.WaitUntilRetry();

                Assert.InRange(backoff.WaitUntilRetry(), TimeSpan.FromMilliseconds(3), TimeSpan.FromMilliseconds(5));
            }
Beispiel #5
0
            public void WillTimeoutEventuallyIfCannotExecuteHandler()
            {
                var e            = new FakeEvent();
                var eventHandler = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { throw new ConcurrencyException(); }, () => new Object());
                var envelope     = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message      = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                SystemTime.ClearOverride();

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler });

                Assert.Throws <TimeoutException>(() => Processor.Process(message));
            }
Beispiel #6
0
            public void WillTimeoutEventuallyIfCannotSave()
            {
                var command   = new FakeCommand();
                var aggregate = new FakeAggregate();
                var envelope  = new CommandEnvelope(GuidStrategy.NewGuid(), command);
                var message   = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);
                var processor = new CommandProcessor(HandlerRegistry.Object, TransientErrorRegistry.Object, new CommandProcessorSettings {
                    RetryTimeout = TimeSpan.FromMilliseconds(20)
                });

                SystemTime.ClearOverride();

                AggregateStore.Setup(mock => mock.Get(typeof(FakeAggregate), envelope.AggregateId)).Returns(aggregate);
                AggregateStore.Setup(mock => mock.Save(aggregate, It.IsAny <CommandContext>())).Callback(() => { throw new ConcurrencyException(); });
                HandlerRegistry.Setup(mock => mock.GetHandlerFor(command)).Returns(new CommandHandler(typeof(FakeAggregate), typeof(FakeCommand), AggregateStore.Object, (a, c) => ((FakeAggregate)a).Handle((FakeCommand)c)));

                Assert.Throws <TimeoutException>(() => processor.Process(message));
            }
 public void Dispose()
 {
     SystemTime.ClearOverride();
 }
 public WhenSavingAggregate()
 {
     SystemTime.ClearOverride();
 }
 public WhenWaitOrTimeout()
 {
     SystemTime.ClearOverride();
 }