public when_logging_disabled_and_commands_are_fired(StreamStoreConnectionFixture fixture) : base(fixture.Connection) { // command must have a commandHandler _cmdHandler = new TestCommandSubscriber(Bus); _multiFireCount = 0; _testCommandCount = 0; _listener = new SynchronizableStreamListener( Logging.FullStreamName, Connection, StreamNameBuilder, EventSerializer); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); CorrelatedMessage source = CorrelatedMessage.NewRoot(); // 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } var tstCmd = new TestCommands.Command3(source); Bus.Send(tstCmd, "Test Command exception message", TimeSpan.FromSeconds(1)); }
public when_commands_are_fired(StreamStoreConnectionFixture fixture) : base(fixture.Connection) { Bus.Subscribe(new AdHocCommandHandler <TestCommands.Command2>(_ => true)); Bus.Subscribe(new AdHocCommandHandler <TestCommands.Command3>(_ => true)); Bus.Subscribe <Message>(this); _multiFireCount = 0; _testCommandCount = 0; CorrelatedMessage source = CorrelatedMessage.NewRoot(); // 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } Bus.Send(new TestCommands.Command3(source), "Test Command exception message", TimeSpan.FromSeconds(1)); Assert.IsOrBecomesTrue(() => _testCommandCount == 1, 1000, "Set Setup failed: Timed out waiting for last cmd"); Assert.IsOrBecomesTrue(() => _multiFireCount == MaxCountedCommands, 9000, "Didn't get all commands"); }
public void commands_logged_only_while_logging_is_enabled() { Assert.False(Logging.Enabled); _multiFireCount = 0; CorrelatedMessage source = CorrelatedMessage.NewRoot(); for (int i = 0; i < _maxCountedMessages; i++) { var cmd = new TestCommands.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 1000, $"Found {_multiFireCount} of first set of commands on disabled log. Should be 0")); _multiFireCount = 0; Logging.Enabled = true; // create and fire a mixed set of commands and events for (int i = 0; i < _maxCountedMessages; i++) { var cmd = new TestCommands.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } Assert.IsOrBecomesTrue( () => _multiFireCount == _maxCountedMessages, 1000, $"Second set of Commands count {_multiFireCount} not properly logged. Expected {_maxCountedMessages}"); Logging.Enabled = false; _multiFireCount = 0; for (int i = 0; i < _maxCountedMessages; i++) { var cmd = new TestCommands.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 1000, $"Found {_multiFireCount} of third set of commands on disabled log. Should be 0")); }
public when_mixed_messages_are_published(StreamStoreConnectionFixture fixture) : base(fixture.Connection) { // commands must have a commandHandler _cmdHandler = new TestCommandSubscriber(Bus); _multiFireCount = 0; _testCommandCount = 0; IListener listener = new SynchronizableStreamListener( Logging.FullStreamName, Connection, StreamNameBuilder, EventSerializer); listener.EventStream.Subscribe <Message>(this); listener.Start(Logging.FullStreamName); CorrelatedMessage source = CorrelatedMessage.NewRoot(); // 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); var evt = new CountedEvent(i, cmd); Bus.Publish(evt); source = evt; } Bus.Subscribe(new AdHocHandler <TestEvent>(_ => Interlocked.Increment(ref _gotEvt))); for (int i = 0; i < _maxCountedEvents; i++) { var evt = new TestEvent(source); Bus.Publish(evt); source = evt; } var tstCmd = new TestCommands.Command3(source); Bus.Send(tstCmd, "Test Command exception message", TimeSpan.FromSeconds(1)); }
public when_logging_high_volume_message_traffic(StreamStoreConnectionFixture fixture) : base(fixture.Connection) { // 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 = new SynchronizableStreamListener( Logging.FullStreamName, Connection, StreamNameBuilder, EventSerializer); _listener.EventStream.Subscribe <Message>(this); _listener.Start(Logging.FullStreamName); CorrelatedMessage source = CorrelatedMessage.NewRoot(); // create and fire a mixed set of commands and events for (int i = 0; i < _maxCountedMessages; i++) { var evt = new CountedEvent(i, source); Bus.Publish(evt); // this is just an example command - choice to fire this one was random var cmd = new TestCommands.Command2(evt); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); var evt2 = new TestEvent(cmd); Bus.Publish(evt2); source = evt2; } var tstCmd = new TestCommands.Command3(source); Bus.Send(tstCmd, "TestCommand3 failed", TimeSpan.FromSeconds(2)); }
public CommandResponse Handle(TestCommands.Command2 command) { Interlocked.Increment(ref _cmd2Count); return(command.Succeed()); }
public void mixed_messages_logged_only_while_logging_is_enabled() { _countedEventCount = 0; CorrelatedMessage source = CorrelatedMessage.NewRoot(); // create and publish a set of events and commands for (int i = 0; i < _maxCountedMessages; i++) { var evt = new CountedEvent(i, source); Bus.Publish(evt); var cmd = new TestCommands.Command2(evt); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(1)); source = cmd; } Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _countedEventCount > 0, 1000, $"Found {_countedEventCount} of first set of events on log. Should be 0")); Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 1000, $"First set of commands count {_multiFireCount} - not properly logged")); Logging.Enabled = true; _countedEventCount = 0; _multiFireCount = 0; // repeat, with logging disabled for (int i = 0; i < _maxCountedMessages; i++) { var evt = new CountedEvent(i, source); Bus.Publish(evt); var cmd = new TestCommands.Command2(evt); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(1)); source = cmd; } Assert.IsOrBecomesTrue( () => _countedEventCount == _maxCountedMessages, 1000, $"Second set of Events count {_countedEventCount} - not properly logged"); Assert.IsOrBecomesTrue( () => _multiFireCount == _maxCountedMessages, 1000, $"Second set of commands count {_multiFireCount} - not properly logged"); Logging.Enabled = false; _countedEventCount = 0; _multiFireCount = 0; // repeat, with logging enabled again for (int i = 0; i < _maxCountedMessages; i++) { var evt = new CountedEvent(i, source); Bus.Publish(evt); var cmd = new TestCommands.Command2(evt); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(1)); source = cmd; } Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _countedEventCount > 0, 1000, $"Found {_countedEventCount} of Third set of events on disabled log. Should be 0")); Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue( () => _multiFireCount > 0, 1000, $"Third set of commands count {_multiFireCount} - not properly logged")); }
private void commands_logged_only_while_logging_is_enabled() { CorrelatedMessage source = CorrelatedMessage.NewRoot(); // 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } 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.Command2(source); Bus.Send(cmd, $"exception message{i}", TimeSpan.FromSeconds(2)); source = cmd; } var tstCmd = new TestCommands.Command3(source); _cmdHandler.TestCommand3Handled = 0; Bus.Send(tstCmd, "Test Command exception message", TimeSpan.FromSeconds(1)); source = tstCmd; Assert.IsOrBecomesTrue(() => _cmdHandler.TestCommand3Handled > 0); 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}"); }