public void can_subscribe_to_all()
        {
            var streams = new List <string>
            {
                _streamNameBuilder.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid()),
                _streamNameBuilder.GenerateForAggregate(typeof(TestWoftamAggregate), Guid.NewGuid())
            };

            foreach (var conn in _stores)
            {
                long evtCount = 0;
                var  dropped  = false;


                //first event in a stream is copied to the $streams projection in the in-Memory ES
                //the Mock ES does not support this projection
                foreach (var stream in streams)
                {
                    var evt = new StreamCreatedTestEvent();
                    conn.AppendToStream(stream, ExpectedVersion.Any, null, _serializer.Serialize(evt));
                }

                var sub = conn.SubscribeToAll(
                    evt => {
                    if (string.CompareOrdinal(evt.EventType, nameof(SubscriptionTestEvent)) == 0)
                    {
                        Interlocked.Increment(ref evtCount);
                    }
                },
                    (reason, ex) => dropped = true,
                    _admin);
                foreach (var stream in streams)
                {
                    AppendEvents(5, conn, stream);
                }
                AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref evtCount) == 30, 2000);

                sub.Dispose();
                AssertEx.IsOrBecomesTrue(() => dropped, msg: "Failed to handle drop");
            }
        }
Пример #2
0
        public void can_subscribe_to_all()
        {
            var streams = new List <string>
            {
                _streamNameBuilder.GenerateForAggregate(typeof(TestAggregate), Guid.NewGuid()),
                _streamNameBuilder.GenerateForAggregate(typeof(TestWoftamAggregate), Guid.NewGuid())
            };

            foreach (var conn in _stores)
            {
                //TODO: The Mock event store all stream implementation is fundamentally broken see issue #42
                if (conn is MockStreamStoreConnection)
                {
                    continue;
                }

                long evtCount = 0;
                var  dropped  = false;


                //first event in a stream is copied to the $streams projection in the in-Memory ES
                //the Mock ES does not support this projection
                foreach (var stream in streams)
                {
                    var evt = new StreamCreatedTestEvent();
                    conn.AppendToStream(stream, ExpectedVersion.Any, null, _serializer.Serialize(evt));
                }

                var events = new ConcurrentDictionary <string, int>();
                var sub    = conn.SubscribeToAll(
                    evt =>
                {
                    if (events.ContainsKey(evt.EventType))
                    {
                        events[evt.EventType] += 1;
                    }
                    else
                    {
                        events.TryAdd(evt.EventType, 1);
                    }

                    if (string.Compare(evt.EventType, nameof(AllSubscriptionTestEvent), StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        Interlocked.Increment(ref evtCount);
                    }
                },
                    (reason, ex) => dropped = true,
                    _admin);

                foreach (var stream in streams)
                {
                    AppendEventsForAll(5, conn, stream);
                }
                foreach (var stream in streams)
                {
                    conn.TryConfirmStream(stream, 5);
                }
                Assert.False(dropped);
                AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref evtCount) == 30,
                                         2000,
                                         $"evtCount: Expected {30}, Actual {Interlocked.Read(ref evtCount)} ");

                sub.Dispose();
                AssertEx.IsOrBecomesTrue(() => dropped, msg: "Failed to handle drop");
            }
        }