コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventFailed" /> class.
 /// </summary>
 /// <param name="message">Message that failed.</param>
 /// <param name="exception">The exception.</param>
 /// <exception cref="System.ArgumentNullException">failedEvent</exception>
 public EventFailed(DispatchEvent message, Exception exception)
 {
     if (message == null) throw new ArgumentNullException("message");
     if (exception == null) throw new ArgumentNullException("exception");
     _message = message;
     _exception = exception;
 }
コード例 #2
0
        public void WorkersBusy()
        {
            var msg1 = new DispatchEvent(new FakeEvent());
            var msg2 = new DispatchEvent(new FakeEvent());
            var msg3 = new DispatchEvent(new FakeEvent());
            var evt = new ManualResetEvent(false);
            var context = new FakeContext(X => evt.WaitOne());
            var dispatcher = new AsyncHandler(2);

            // make first worker busy and validate
            dispatcher.HandleDownstream(context, msg1);
            Assert.True(context.Wait(TimeSpan.FromMilliseconds(100)));
            context.Reset();

            // make second worker busy and validate
            dispatcher.HandleDownstream(context, msg2);
            Assert.True(context.Wait(TimeSpan.FromMilliseconds(100)));
            context.Reset();

            // Make sure that the third message is not dispatched.
            dispatcher.HandleDownstream(context, msg3);
            Assert.False(context.Wait(TimeSpan.FromMilliseconds(100)));
            context.Reset();

            // release workers.
            evt.Set();

            // and expect the third to get running.
            Assert.True(context.Wait(TimeSpan.FromMilliseconds(100)));
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCompleted" /> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <exception cref="System.ArgumentNullException">message</exception>
 public EventCompleted(DispatchEvent message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     Message = message;
 }
コード例 #4
0
        public void Shutdown_ReleaseAfter1Second()
        {
            var msg1 = new DispatchEvent(new FakeEvent());
            var evt = new ManualResetEvent(false);
            var context = new FakeContext(X => Thread.Sleep(1000));
            var dispatcher = new AsyncHandler(2);

            dispatcher.HandleDownstream(context, msg1);
            dispatcher.Close();
        }
コード例 #5
0
        public void RegularDispatch()
        {
            var dispatcher = new AsyncHandler(5);
            var msg = new DispatchEvent(new FakeEvent());
            var context = new FakeContext();

            dispatcher.HandleDownstream(context, msg);

            Assert.True(context.Wait(TimeSpan.FromMilliseconds(50000)));
            Assert.Same(msg, context.Message);
        }
コード例 #6
0
        public void UowDispatcherNoUow()
        {
            var uowAdapter = new FakeUowAdapter();
            var storage = new MemoryStorage();
            var context = Substitute.For<IDownstreamContext>();
            var msg = new DispatchEvent(new FakeEvent());

            var handler = new TransactionalHandler(uowAdapter, storage);
            handler.HandleDownstream(context, msg);

            context.Received().SendDownstream(msg);
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventFailed" /> class.
 /// </summary>
 /// <param name="message">Message that failed.</param>
 /// <param name="exception">The exception.</param>
 /// <exception cref="System.ArgumentNullException">failedEvent</exception>
 public EventFailed(DispatchEvent message, Exception exception)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (exception == null)
     {
         throw new ArgumentNullException("exception");
     }
     _message   = message;
     _exception = exception;
 }
コード例 #8
0
        public void Throws()
        {
            var container = Substitute.For<IRootContainer>();
            var context = Substitute.For<IDownstreamContext>();
            var child = Substitute.For<IScopedContainer>();
            container.CreateScope().Returns(child);
            var msg = new DispatchEvent(new FakeEvent());
            child.ResolveAll<ISubscribeOn<FakeEvent>>().Returns(call => { throw new Exception(); });

            var handler = new IocHandler(container);
            handler.HandleDownstream(context, msg);

            context.Received().SendUpstream(Arg.Any<EventFailed>());
        }
コード例 #9
0
        public void Shutdown_NotReleased()
        {
            var msg1 = new DispatchEvent(new FakeEvent());
            var evt = new ManualResetEvent(false);
            var context = new FakeContext(X => evt.WaitOne());
            var dispatcher = new AsyncHandler(2);

            dispatcher.HandleDownstream(context, msg1);
            Assert.Throws<InvalidOperationException>(() => dispatcher.Close());

            evt.Set();

            // and expect the third to get running.
            Assert.True(context.Wait(TimeSpan.FromMilliseconds(100)));
        }
コード例 #10
0
        public void UowDispatcher_UowNotReleased()
        {
            var uowAdapter = new FakeUowAdapter();
            var storage = Substitute.For<IDomainEventStorage>();
            var context = Substitute.For<IDownstreamContext>();
            var msg = new DispatchEvent(new FakeEvent());
            var uowMapper = new ThreadBatchIdMapper();

            var handler = new TransactionalHandler(uowAdapter, storage, uowMapper);
            uowAdapter.Observer.Create(uowAdapter);
            handler.HandleDownstream(context, msg);


            storage.Received().Hold(uowMapper.GetBatchId(), msg.DomainEvent);
        }
コード例 #11
0
        public void UowDispatcher_UowReleasedFailed()
        {
            var uowAdapter = new FakeUowAdapter();
            var storage = Substitute.For<IDomainEventStorage>();
            var context = Substitute.For<IDownstreamContext>();
            var msg = new DispatchEvent(new FakeEvent());
            var uowMapper = new ThreadBatchIdMapper();
            var handler = new TransactionalHandler(uowAdapter, storage, uowMapper);
            uowAdapter.Observer.Create(uowAdapter);
            var batchId = uowMapper.GetBatchId();
            storage.Release(batchId).Returns(new[] {new FakeEvent()});

            handler.HandleDownstream(context, msg);
            context.DidNotReceive().SendDownstream(msg);
            uowAdapter.Observer.Released(uowAdapter, false);


            storage.Received().Hold(batchId, msg.DomainEvent);
            storage.Received().Delete(batchId);
            context.DidNotReceive().SendDownstream(Arg.Any<DispatchEvent>());
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCompleted" /> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <exception cref="System.ArgumentNullException">message</exception>
 public EventCompleted(DispatchEvent message)
 {
     if (message == null) throw new ArgumentNullException("message");
     Message = message;
 }