Beispiel #1
0
        public void commands_are_logged()
        {
            TestQueue.WaitFor <TestDomainEvent>(TimeSpan.FromSeconds(5));
            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5));

            // Wait  for last event to be queued
            Assert.IsOrBecomesTrue(() => _countedEventCount == _maxCountedMessages, 2000);
            Assert.True(_countedEventCount == _maxCountedMessages, $"Message {_countedEventCount} doesn't match expected index {_maxCountedMessages}");
            Assert.IsOrBecomesTrue(() => _testDomainEventCount == _maxCountedEvents,
                                   1000,
                                   $"Last event count {_testDomainEventCount} doesn't match expected value {_maxCountedEvents}");

            Assert.True(_testDomainEventCount == _maxCountedEvents, $"Last event count {_testDomainEventCount} doesn't match expected value {1}");


            // Wait  for last TestCommand2 to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(() => _multiFireCount == _maxCountedMessages,
                                   3000,
                                   $"Command count {_multiFireCount} doesn't match expected index {_maxCountedMessages}");

            Assert.True(_multiFireCount == _maxCountedMessages, $"Command count {_multiFireCount} doesn't match expected index {_maxCountedMessages}");

            // Wait  for last command to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(() => _testCommandCount == 1, 1000);
            Assert.True(_testCommandCount == 1, $"Last command count {_testCommandCount} doesn't match expected value {1}");
        }
Beispiel #2
0
 public void can_timeout_waiting_for_message_of_type()
 {
     using (var tq = new TestQueue(_dispatcher, new[] { typeof(Event), typeof(Command) }))
     {
         // Don't publish anything
         Assert.Throws <TimeoutException>(() => tq.WaitFor <TestEvent>(TimeSpan.FromMilliseconds(100)));
         tq.AssertEmpty();
     }
 }
 public void canceled_commands_will_not_fire()
 {
     TestQueue.WaitFor <Canceled>(TimeSpan.FromSeconds(2));
     TestQueue.Commands
     .AssertEmpty();
     TestQueue.Responses
     .AssertNext <Canceled>(_ => true)
     .AssertEmpty();
 }
Beispiel #4
0
        public void can_get_all_messages_from_queue()
        {
            using (var tq = new TestQueue(_dispatcher))
            {
                var evt = new TestEvent();
                var cmd = new TestCommands.Command1();
                _dispatcher.Publish(evt);
                _dispatcher.Send(cmd);

                tq.WaitFor <CommandResponse>(TimeSpan.FromMilliseconds(100));
                tq.WaitFor <Success>(TimeSpan.FromMilliseconds(100));
                Assert.Throws <TimeoutException>(() => tq.WaitFor <Fail>(TimeSpan.FromMilliseconds(10)));
                tq.AssertNext <TestEvent>(evt.CorrelationId)
                .AssertNext <AckCommand>(cmd.CorrelationId)
                .AssertNext <Success>(cmd.CorrelationId)
                .AssertNext <TestCommands.Command1>(cmd.CorrelationId)
                .AssertEmpty();
            }
        }
        public void all_events_are_logged()
        {
            TestQueue.WaitFor <TestDomainEvent>(TimeSpan.FromSeconds(5));

            // Wait  for last event to be queued
            Assert.IsOrBecomesTrue(() => _countedEventCount == _maxCountedEvents, 9000);
            Assert.True(_countedEventCount == _maxCountedEvents, $"Message {_countedEventCount} doesn't match expected index {_maxCountedEvents}");
            Assert.IsOrBecomesTrue(() => _testDomainEventCount == 1, 1000);

            Assert.True(_testDomainEventCount == 1, $"Last event count {_testDomainEventCount} doesn't match expected value {1}");
        }
        public void all_commands_are_logged()
        {
            // Wait  for last command to be queued
            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5));

            Assert.IsOrBecomesTrue(() => _multiFireCount == MaxCountedCommands, 9000);
            Assert.True(_multiFireCount == MaxCountedCommands, $"Command count {_multiFireCount} doesn't match expected index {MaxCountedCommands}");
            Assert.IsOrBecomesTrue(() => _testCommandCount == 1, 1000);

            Assert.True(_testCommandCount == 1, $"Last event count {_testCommandCount} doesn't match expected value {1}");
        }
 public void can_cancel_immediately()
 {
     TestQueue.WaitFor <TestTokenCancellableCmd>(TimeSpan.FromSeconds(2));
     TokenSource.Cancel();
     TestQueue.WaitFor <Canceled>(TimeSpan.FromSeconds(2));
     TestQueue.Commands
     .AssertNext <TestTokenCancellableCmd>(_ => true)
     .AssertEmpty();
     TestQueue.Responses
     .AssertNext <Canceled>(_ => true)
     .AssertEmpty();
 }
 public void will_succeed_if_not_canceled()
 {
     TestQueue.WaitFor <TestTokenCancellableCmd>(TimeSpan.FromSeconds(2));
     _handler?.ParkedMessages[_cmd.MsgId].Set();
     TestQueue.WaitFor <Success>(TimeSpan.FromSeconds(2));
     TestQueue.Commands
     .AssertNext <TestTokenCancellableCmd>(_ => true)
     .AssertEmpty();
     TestQueue.Responses
     .AssertNext <Success>(_ => true)
     .AssertEmpty();
 }
 public void can_cancel_after_delay()
 {
     TestQueue.WaitFor <TestTokenCancellableCmd>(TimeSpan.FromSeconds(2));
     Thread.Sleep(500);
     TokenSource.Cancel();
     TestQueue.WaitFor <Canceled>(TimeSpan.FromSeconds(2));
     TestQueue.Commands
     .AssertNext <TestTokenCancellableCmd>(_ => true)
     .AssertEmpty();
     TestQueue.Responses
     .AssertNext <Canceled>(_ => true)
     .AssertEmpty();
 }
        public void all_messages_are_logged()
        {
            // Wait for last command to be queued
            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(10));

            // Wait  for last command to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(() =>
                                   _lastCommandCount == 1,
                                   40000,
                                   $"Last command count = {_lastCommandCount}. Command never handled");

            // Wait  for last CountedEvent to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(
                () => _countedEventCount == _maxCountedMessages,
                2000,
                $"Message {_countedEventCount} doesn't attain expected index {_maxCountedMessages}");

            Assert.True(_countedEventCount == _maxCountedMessages, $"Message {_countedEventCount} doesn't match expected index {_maxCountedMessages}");

            // Wait  for last TestCommand2 to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(() => _commandFireCount == _maxCountedMessages,
                                   3000,
                                   $"Command count {_commandFireCount} doesn't attain expected index {_maxCountedMessages}");

            Assert.True(_commandFireCount == _maxCountedMessages, $"Command count {_commandFireCount} doesn't match expected index {_maxCountedMessages}");

            // Wait  for last TestDomainEvent to be "heard" from logger/repo
            Assert.IsOrBecomesTrue(() => _testDomainEventCount == _maxCountedMessages,
                                   1000,
                                   $"Last event count {_testDomainEventCount} doesn't attain expected value {_maxCountedMessages}");

            Assert.True(_testDomainEventCount == _maxCountedMessages, $"Last event count {_testDomainEventCount} doesn't match expected value {1}");


            Assert.True(_lastCommandCount == 1, $"Last command count {_lastCommandCount} doesn't match expected value, 1");

            // were all expected items logged?
            //Note that for a command, there is the command itself, the AckCommand and Success
            var sumOfItemsLogged = _commandFireCount +
                                   _countedEventCount +
                                   _testDomainEventCount +
                                   _lastCommandCount +
                                   _commandAckCount +
                                   _commandSuccessCount +
                                   _catchupSubscriptionMsgs;

            Assert.IsOrBecomesTrue(() =>
                                   _numberOfItemsLogged == sumOfItemsLogged,
                                   500,
                                   $"Number of items logged  {_numberOfItemsLogged} doesn't match expected value, {sumOfItemsLogged}");
        }
 public void will_not_cross_cancel()
 {
     TestQueue.WaitFor <TestTokenCancellableCmd>(TimeSpan.FromSeconds(2));
     TokenSource1.Cancel();
     Handler.ParkedMessages[Cmd1.MsgId].Set();
     TestQueue.WaitFor <Canceled>(TimeSpan.FromSeconds(2));
     Handler.ParkedMessages[Cmd2.MsgId].Set();
     TestQueue.WaitFor <Success>(TimeSpan.FromSeconds(3));
     TestQueue.Commands
     .AssertNext <TestTokenCancellableCmd>(_ => true)
     .AssertNext <TestTokenCancellableCmd>(_ => true)
     .AssertEmpty();
     TestQueue.Responses
     .AssertNext <Canceled>(msg => msg.SourceCommand.MsgId == Cmd1.MsgId)
     .AssertNext <Success>(msg => msg.SourceCommand.MsgId == Cmd2.MsgId)
     .AssertEmpty();
 }
Beispiel #12
0
        public void slow_commands_should_throw_timeout()
        {
            Assert.Throws <CommandTimedOutException>(
                () => Bus.Fire(new TestCommands.TimeoutTestCommand(Guid.NewGuid(), null))
                );

            Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotCmd1) == 1, msg: "Expected Cmd1 handled");

            TestQueue.WaitFor <TestCommands.TimeoutTestCommand>(TimeSpan.FromMilliseconds(2000));
            TestQueue.WaitFor <Canceled>(TimeSpan.FromMilliseconds(2000));
            TestQueue.Commands
            .AssertNext <TestCommands.TimeoutTestCommand>(_ => true)
            .AssertEmpty();
            TestQueue.Responses
            .AssertNext <Canceled>(msg =>
                                   msg.Exception is CommandCanceledException)
            .AssertEmpty();
        }
Beispiel #13
0
        public void commands_are_not_logged()
        {
            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5));
            // Wait  for last command to be queued

            //    // Wait  for last event to be queued
            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _multiFireCount > 0,
                                              1000,
                                              $"Commands logged to ES when logging should be disabled - {_multiFireCount}"));

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _testCommandCount == 1,
                                              1000,
                                              $"Last command logged to ES when logging should be disabled"));

            Assert.False(_multiFireCount == _maxCountedCommands, $"Command count {_multiFireCount} doesn't match expected index {_maxCountedCommands}");
            Assert.False(_testCommandCount == 1, $"Last event count {_testCommandCount} doesn't match expected value {1}");
        }
        public void events_are_not_logged()
        {
            // wait for all events to be queued
            TestQueue.WaitFor <TestDomainEvent>(TimeSpan.FromSeconds(5));

            //// Need the "is or becomes" here because if the handler (see below) is executed, it takes time.
            // see the enabled test

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _countedEventCount > 0,
                                              1000,
                                              $"Found {_countedEventCount} CountedEvents on log"));
            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _testDomainEventCount > 0,
                                              1000,
                                              $"Found {_testDomainEventCount} TestDomainEvents on log"));

            // counters are never incremented because they are not logged, therefore not "heard" by the repo listener
            Assert.False(_countedEventCount == _maxCountedEvents, $"{_countedEventCount} CountedEvents found on Log");
            Assert.True(_testDomainEventCount == 0, $"Last event count {_testDomainEventCount} is not 0");
        }
Beispiel #15
0
        public void mixed_messages_are_not_logged()
        {
            // all events published, commands fired
            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5));

            // Wait  for last CountedEvent to be "heard" from logger/repo - times out because events not logged
            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _countedEventCount > 0,
                                              1000,
                                              $"Found {_countedEventCount} CountedEvents on log"));

            Assert.True(_countedEventCount == 0,
                        $"{_countedEventCount} CountedEvents found on Log");

            // Wait  for last command to be queued - times out because events not logged
            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _multiFireCount > 0,
                                              9000,
                                              $"Found {_multiFireCount} TestCommand2s on log - expected 0"));

            Assert.True(_multiFireCount == 0, $"Command count {_multiFireCount}  expected 0");


            // Wait  for last TestDomainEvent to be "heard" from logger/repo - times out because events not logged
            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _testDomainEventCount > 0,
                                              1000,
                                              $"Found {_testDomainEventCount} TestDomainEvents on log, expected 0"));

            Assert.True(_testDomainEventCount == 0, $"Last event count {_testDomainEventCount} doesn't match expected value {1}");

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _testCommandCount == 1,
                                              1000,
                                              $"Found {_testCommandCount} TestCommand3s on log - expected 0"));

            Assert.True(_testCommandCount == 0, $"Last event count {_testCommandCount} is not 0");
        }
Beispiel #16
0
        public void commands_logged_only_while_logging_is_enabled()
        {
            // create and fire a mixed set of commands and events
            for (int i = 0; i < _maxCountedMessages; i++)
            {
                // this is just an example command - choice to fire this one was random
                var cmd = new TestCommands.TestCommand2(
                    Guid.NewGuid(),
                    null);
                Bus.Fire(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
            }

            Assert.IsOrBecomesTrue(
                () => _multiFireCount == _maxCountedMessages,
                1000,
                $"First set of Commands count {_multiFireCount} not properly logged. Expected {_maxCountedMessages}");

            Logging.Enabled = false;
            _multiFireCount = 0;

            // create and fire a mixed set of commands and events
            for (int i = 0; i < _maxCountedMessages; i++)
            {
                // this is just an example command - choice to fire this one was random
                var cmd = new TestCommands.TestCommand2(
                    Guid.NewGuid(),
                    null);
                Bus.Fire(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
            }

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _multiFireCount > 0,
                                              5000,
                                              $"Found {_multiFireCount} of second set of commands on log. Should be 0"));

            Logging.Enabled = true;
            _multiFireCount = 0;

            for (int i = 0; i < _maxCountedMessages; i++)
            {
                // this is just an example command - choice to fire this one was random
                var cmd = new TestCommands.TestCommand2(
                    Guid.NewGuid(),
                    null);
                Bus.Fire(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
            }

            var tstCmd = new TestCommands.TestCommand3(
                Guid.NewGuid(),
                null);

            Bus.Fire(tstCmd,
                     "Test Command exception message",
                     TimeSpan.FromSeconds(1));

            TestQueue.WaitFor <TestCommands.TestCommand3>(TimeSpan.FromSeconds(5));

            Assert.IsOrBecomesTrue(
                () => _multiFireCount == _maxCountedMessages,
                5000,
                $"First set of Commands count {_multiFireCount} doesn't match expected index {_maxCountedMessages}");

            Assert.True(
                _multiFireCount == _maxCountedMessages,
                $"Third set of Commands count {_multiFireCount} doesn't match expected index {_maxCountedMessages}");
        }