public void cancel_should_not_cancel_others() { var bus = new CommandBus("local"); var handler = new CancelableTestCommandHandler(); bus.Subscribe((IHandleCommand <TestCommands.TestCommand>)handler); bus.Subscribe((IHandleCommand <TestCommands.TestCommand2>)handler); var handler2 = new TestCommandHandler(); bus.Subscribe((IHandleCommand <TestCommands.TestCommand3>)handler2); var cmd1 = new TestCommands.TestCommand(Guid.NewGuid(), null); var cmd2 = new TestCommands.TestCommand2(Guid.NewGuid(), null); var cmd3 = new TestCommands.TestCommand3(Guid.NewGuid(), null); Task.Delay(100).ContinueWith(t => bus.RequestCancel(cmd1)); Task.Run(() => bus.Fire(cmd2)); Task.Run(() => bus.Fire(cmd3)); Assert.Throws <CommandCanceledException>( () => { try { bus.Fire(cmd1); } catch (Exception ex) { throw ex.InnerException; } }); }
protected override void When() { _correlationId = Guid.NewGuid(); // command must have a commandHandler _cmdHandler = new TestCommandSubscriber(Bus); _multiFireCount = 0; _testCommandCount = 0; _listener = Repo.GetListener(Logging.FullStreamName); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); // create and fire a set of commands for (int i = 0; i < MaxCountedCommands; 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)); }
public void noncancelable_commands_will_ignore_cancel() { var bus = new CommandBus("local"); var handler = new TestCommandHandler(); bus.Subscribe((IHandleCommand <TestCommands.TestCommand3>)handler); var cmd = new TestCommands.TestCommand3(Guid.NewGuid(), null); Task.Delay(100).ContinueWith(t => bus.RequestCancel(cmd)); bus.Fire(cmd); }
protected override void When() { _listener = Repo.GetListener(Logging.FullStreamName); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); _countedEventCount = 0; _testDomainEventCount = 0; _cmdHandler = new TestCommandSubscriber(Bus); _multiFireCount = 0; _testCommandCount = 0; _listener = Repo.GetListener(Logging.FullStreamName); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); // create and fire a mixed set of commands and events for (int i = 0; i < _maxCountedMessages; i++) { Bus.Publish( new CountedEvent(i, _correlationId, Guid.NewGuid())); // 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)); } for (int i = 0; i < _maxCountedEvents; i++) { Bus.Publish(new TestDomainEvent(_correlationId, Guid.NewGuid())); } var tstCmd = new TestCommands.TestCommand3( Guid.NewGuid(), null); Bus.Fire(tstCmd, "Test Command exception message", TimeSpan.FromSeconds(1)); }
protected override void When() { // commands must have a commandHandler _cmdHandler = new TestCommandSubscriber(Bus); _commandFireCount = 0; _commandAckCount = 0; _commandSuccessCount = 0; _lastCommandCount = 0; _countedEventCount = 0; _testDomainEventCount = 0; _numberOfItemsLogged = 0; _catchupSubscriptionMsgs = 0; _listener = Repo.GetListener(Logging.FullStreamName); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); // create and fire a mixed set of commands and events for (int i = 0; i < _maxCountedMessages; i++) { Bus.Publish( new CountedEvent(i, Guid.NewGuid(), Guid.NewGuid())); // 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)); Bus.Publish(new TestDomainEvent(Guid.NewGuid(), Guid.NewGuid())); } var tstCmd = new TestCommands.TestCommand3( _correlationId, null); Bus.Fire(tstCmd, "TestCommand3 failed", TimeSpan.FromSeconds(2)); }
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}"); }
public CommandResponse Handle(TestCommands.TestCommand3 command) { Interlocked.Increment(ref TestCommand3Handled); return(command.Succeed()); }