Esempio n. 1
0
        void can_handle_threaded_commands()
        {
            var bus = new Dispatcher("test", 2);

            using (var sub = new TestSubscriber(bus)) {
                sub.Subscribe(
                    new AdHocCommandHandler <TestCommands.OrderedCommand>(cmd => {
                    Interlocked.Increment(ref _cmdCount);
                    return(Interlocked.Read(ref _cmdCount) == cmd.SequenceNumber + 1);
                }));
                var messages = new TestCommands.OrderedCommand[_count];
                for (int i = 0; i < _count; i++)
                {
                    messages[i] = new TestCommands.OrderedCommand(i);
                }

                for (int i = 0; i < _count; i++)
                {
                    bus.Send(messages[i]);
                }

                AssertEx.IsOrBecomesTrue(
                    () => _cmdCount == _count,
                    1000,
                    $"Expected Command count to be {_count} Commands, found {_cmdCount }");
            }
        }
Esempio n. 2
0
 public can_unsubscribe_queued_messages()
 {
     for (var i = 0; i < _msgCount; i++)
     {
         _messages.Add(new CountedTestMessage(i));
         var evt = new CountedEvent(i);
         _messages.Add(evt);
         var cmd = new TestCommands.OrderedCommand(i);
         _messages.Add(cmd);
     }
 }
        void can_handle_commands_in_order()
        {
            _fixture.Reset();

            for (int i = 0; i < _count; i++)
            {
                var cmd = new TestCommands.OrderedCommand(i);
                _fixture.Dispatcher.Send(cmd);
            }
            AssertEx.IsOrBecomesTrue(
                () => Interlocked.Read(ref _fixture.CmdCount) == _count,
                msg: $"Expected message count to be {_count} Messages, found {_fixture.CmdCount}");
        }