示例#1
0
        public when_using_listener_start_with_aggregate_and_guid(StreamStoreConnectionFixture fixture)
        {
            var conn = fixture.Connection;

            conn.Connect();

            // Build an origin stream to which the the events are appended. We are testing this stream directly
            var originalStreamGuid = Guid.NewGuid();
            var originStreamName   = _streamNameBuilder.GenerateForAggregate(typeof(AggregateIdTestAggregate), originalStreamGuid);


            // Drop an event into the stream testAggregate-guid
            var result = conn.AppendToStream(
                originStreamName,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent()));

            Assert.True(result.NextExpectedVersion == 0);

            // Wait for the stream to be written
            CommonHelpers.WaitForStream(conn, originStreamName);

            StreamListener listener = new QueuedStreamListener(
                "guidStream",
                conn,
                _streamNameBuilder,
                _eventSerializer);

            listener.EventStream.Subscribe(new AdHocHandler <Event>(Handle));

            // This will start listening on the TestAggregate-guid stream.
            listener.Start <AggregateIdTestAggregate>(originalStreamGuid);
        }
示例#2
0
        public when_events_are_published(StreamStoreConnectionFixture fixture) : base(fixture.Connection)
        {
            _listener = new SynchronizableStreamListener(
                Logging.FullStreamName,
                Connection,
                StreamNameBuilder,
                EventSerializer);
            _listener.EventStream.Subscribe <Event>(this);

            _listener.Start(Logging.FullStreamName);

            _countedEventCount    = 0;
            _testDomainEventCount = 0;
            CorrelatedMessage source = CorrelatedMessage.NewRoot();

            // create and publish a set of events
            for (int i = 0; i < _maxCountedEvents; i++)
            {
                var evt = new CountedEvent(i, source);
                Bus.Publish(evt);
                source = evt;
            }

            Bus.Subscribe(new AdHocHandler <TestEvent>(_ => Interlocked.Increment(ref _gotEvt)));
            Bus.Publish(new TestEvent(source));
        }
        public when_using_listener_start_with_custom_stream_synched(StreamStoreConnectionFixture fixture)
        {
            var conn = fixture.Connection;

            conn.Connect();

            // Build an origin stream from strings to which the the events are appended
            var originStreamName = $"testStream-{Guid.NewGuid():N}";


            var result = fixture.Connection.AppendToStream(
                originStreamName,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent()));

            Assert.True(result.NextExpectedVersion == 0);

            // Wait for the stream to be written
            CommonHelpers.WaitForStream(conn, originStreamName);

            StreamListener listener = new QueuedStreamListener(
                originStreamName,
                fixture.Connection,
                new PrefixedCamelCaseStreamNameBuilder(),
                _eventSerializer);

            listener.EventStream.Subscribe(new AdHocHandler <Event>(Handle));
            listener.Start(originStreamName);
        }
示例#4
0
        public when_using_listener_start_with_event_type(StreamStoreConnectionFixture fixture)
        {
            var streamNameBuilder = new PrefixedCamelCaseStreamNameBuilder();
            var conn = fixture.Connection;

            conn.Connect();

            var originalAggregateStream =
                streamNameBuilder.GenerateForAggregate(
                    typeof(TestAggregate),
                    Guid.NewGuid());
            var evt = new EventProjectionTestEvent();
            //drop the event into the stream
            var result = conn.AppendToStream(
                originalAggregateStream,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(evt));

            Assert.True(result.NextExpectedVersion == 0);

            //wait for the projection to be written
            CommonHelpers.WaitForStream(conn, streamNameBuilder.GenerateForEventType(nameof(EventProjectionTestEvent)));

            //build the listener
            StreamListener listener = new SynchronizableStreamListener(
                "event listener",
                conn,
                streamNameBuilder,
                _eventSerializer);

            listener.EventStream.Subscribe(new AdHocHandler <EventProjectionTestEvent>(Handle));
            listener.Start(typeof(EventProjectionTestEvent));
        }
        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_using_listener_start_with_category_aggregate(StreamStoreConnectionFixture fixture)
        {
            var streamNameBuilder = new PrefixedCamelCaseStreamNameBuilder();
            var conn = fixture.Connection;

            conn.Connect();

            var aggStream      = streamNameBuilder.GenerateForAggregate(typeof(AggregateCategoryTestAggregate), Guid.NewGuid());
            var categoryStream = streamNameBuilder.GenerateForCategory(typeof(AggregateCategoryTestAggregate));

            // Drop an event into the stream testAggregate-guid
            var result = conn.AppendToStream(
                aggStream,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent(CorrelatedMessage.NewRoot())));

            Assert.True(result.NextExpectedVersion == 0);

            //wait for the projection to be written.
            CommonHelpers.WaitForStream(conn, categoryStream);

            // Now set up the projection listener, and start it.
            var listener = new SynchronizableStreamListener(
                "category listener",
                conn,
                streamNameBuilder,
                new JsonMessageSerializer());

            listener.EventStream.Subscribe <TestEvent>(new AdHocHandler <TestEvent>(Handle));
            listener.Start <AggregateCategoryTestAggregate>();
        }
示例#7
0
        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");
        }
示例#8
0
        public with_correlated_repository(StreamStoreConnectionFixture fixture)
        {
            _fixture = fixture;
            fixture.Connection.Connect();
            _stdRepo = new StreamStoreRepository(new PrefixedCamelCaseStreamNameBuilder(),
                                                 fixture.Connection,
                                                 new JsonMessageSerializer());

            _repo = new CorrelatedStreamStoreRepository(
                _stdRepo);
        }
        public when_toggling_logging(StreamStoreConnectionFixture fixture) : base(fixture.Connection)
        {
            // command must have a commandHandler
            _cmdHandler = new TestCommandSubscriber(Bus);

            _multiFireCount = 0;

            _listener = new SynchronizableStreamListener(
                Logging.FullStreamName,
                Connection,
                StreamNameBuilder,
                EventSerializer);

            _listener.Start(Logging.FullStreamName);
        }
示例#10
0
        public when_using_read_model_base(StreamStoreConnectionFixture fixture)
            : base(nameof(when_using_read_model_base), GetListener)
        {
            //_conn = new MockStreamStoreConnection("mockStore");
            _conn = fixture.Connection;
            _conn.Connect();

            // ReSharper disable once RedundantTypeArgumentsOfMethod
            EventStream.Subscribe <ReadModelTestEvent>(this);

            _stream1 = Namer.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid());
            _stream2 = Namer.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid());

            AppendEvents(10, _conn, _stream1, 2);
            AppendEvents(10, _conn, _stream2, 3);
        }
示例#11
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));
        }
示例#12
0
        public when_using_read_model_base_with_reader(StreamStoreConnectionFixture fixture)
            : base(nameof(when_using_read_model_base),
                   new ConfiguredConnection(fixture.Connection, Namer, Serializer))
        {
            _conn = fixture.Connection;
            _conn.Connect();

            // ReSharper disable once RedundantTypeArgumentsOfMethod
            EventStream.Subscribe <ReadModelTestEvent>(this);

            _stream1 = Namer.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid());
            _stream2 = Namer.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid());

            AppendEvents(10, _conn, _stream1, 2);
            AppendEvents(10, _conn, _stream2, 3);
            _conn.TryConfirmStream(_stream1, 10);
            _conn.TryConfirmStream(_stream2, 10);
            _conn.TryConfirmStream(Namer.GenerateForCategory(typeof(TestAggregate)), 20);
        }
        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));
        }