public async Task When_exception_throw_by_all_stream_subscriber_then_should_drop_subscription_with_reason_SubscriberError()
        {
            using (var fixture = GetFixture())
            {
                using (var store = await fixture.GetStreamStore())
                {
                    var eventReceivedException = new TaskCompletionSource <SubscriptionDroppedReason>();
                    AllStreamMessageReceived messageReceived = (_, __) =>
                    {
                        throw new Exception();
                    };
                    AllSubscriptionDropped subscriptionDropped = (_, reason, __) =>
                    {
                        eventReceivedException.SetResult(reason);
                    };
                    string streamId = "stream-1";
                    using (store.SubscribeToAll(
                               null,
                               messageReceived,
                               subscriptionDropped))
                    {
                        await store.AppendToStream(streamId,
                                                   ExpectedVersion.NoStream,
                                                   new NewStreamMessage(Guid.NewGuid(), "type", "{}"));

                        var droppedReason = await eventReceivedException.Task.WithTimeout();

                        droppedReason.ShouldBe(SubscriptionDroppedReason.SubscriberError);
                    }
                }
            }
        }
Exemple #2
0
 protected abstract IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     bool prefetchJsonData,
     string name);
Exemple #3
0
        public AllStreamSubscription(
            long?continueAfterPosition,
            IReadonlyStreamStore readonlyStreamStore,
            IObservable <Unit> streamStoreAppendedNotification,
            AllStreamMessageReceived streamMessageReceived,
            AllSubscriptionDropped subscriptionDropped,
            HasCaughtUp hasCaughtUp,
            bool prefetchJsonData,
            string name)
        {
            FromPosition           = continueAfterPosition;
            LastPosition           = continueAfterPosition;
            _nextPosition          = continueAfterPosition + 1 ?? Position.Start;
            _readonlyStreamStore   = readonlyStreamStore;
            _streamMessageReceived = streamMessageReceived;
            _prefetchJsonData      = prefetchJsonData;
            _subscriptionDropped   = subscriptionDropped ?? ((_, __, ___) => { });
            _hasCaughtUp           = hasCaughtUp ?? (_ => { });
            Name = string.IsNullOrWhiteSpace(name) ? Guid.NewGuid().ToString() : name;

            readonlyStreamStore.OnDispose += ReadonlyStreamStoreOnOnDispose;

            _notification = streamStoreAppendedNotification.Subscribe(_ =>
            {
                _streamStoreNotification.Set();
            });

            Task.Run(PullAndPush);

            s_logger.Info(
                "AllStream subscription created {name} continuing after position {position}",
                Name,
                continueAfterPosition?.ToString() ?? "<null>");
        }
Exemple #4
0
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name)
 {
     throw new NotImplementedException();
 }
            private IAllStreamSubscription SubscribeToAll(
                AllStreamMessageReceived streamMessageReceived,
                AllSubscriptionDropped subscriptionDropped)
            {
                _streamMessageReceived = streamMessageReceived;
                _subscriptionDropped   = subscriptionDropped;

                var mock = new Mock <IAllStreamSubscription>();

                mock.Setup(subscription => subscription.Name).Returns($"AllStreamSubscription<{Guid.NewGuid()}>");
                _allStreamSubscription = mock.Object;

                return(_allStreamSubscription);
            }
Exemple #6
0
 public IAllStreamSubscription SubscribeToAll(long?continueAfterPosition, AllStreamMessageReceived streamMessageReceived,
                                              AllSubscriptionDropped subscriptionDropped = null, HasCaughtUp hasCaughtUp = null, bool prefetchJsonData = true,
                                              string name = null)
 {
     return(new AllStreamSubscription(
                continueAfterPosition,
                this,
                new PollingStreamStoreNotifier(this),
                streamMessageReceived,
                subscriptionDropped,
                hasCaughtUp,
                prefetchJsonData,
                name));
 }
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     bool prefetchJsonData,
     string name)
 => new AllStreamSubscription(
     fromPosition,
     this,
     GetStoreObservable,
     streamMessageReceived,
     subscriptionDropped,
     hasCaughtUp,
     prefetchJsonData,
     name);
Exemple #8
0
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     string name)
 {
     return(new AllStreamSubscription(
                fromPosition,
                this,
                GetStoreObservable,
                streamMessageReceived,
                subscriptionDropped,
                hasCaughtUp,
                name));
 }
Exemple #9
0
 public IAllStreamSubscription SubscribeToAll(
     long?continueAfterPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped = null,
     HasCaughtUp hasCaughtUp = null,
     bool prefetchJsonData   = true,
     string name             = null)
 => Trace(
     nameof(SubscribeToAll),
     "all",
     () => _streamStore.SubscribeToAll(
         continueAfterPosition,
         streamMessageReceived,
         subscriptionDropped,
         hasCaughtUp,
         prefetchJsonData,
         name));
        public IAllStreamSubscription SubscribeToAll(
            long?continueAfterPosition,
            AllStreamMessageReceived streamMessageReceived,
            AllSubscriptionDropped subscriptionDropped = null,
            HasCaughtUp hasCaughtUp = null,
            string name             = null)
        {
            Ensure.That(streamMessageReceived, nameof(streamMessageReceived)).IsNotNull();

            GuardAgainstDisposed();

            return(SubscribeToAllInternal(continueAfterPosition,
                                          streamMessageReceived,
                                          subscriptionDropped,
                                          hasCaughtUp,
                                          name));
        }
 protected override IAllStreamSubscription SubscribeToAllInternal(
     long?fromPosition,
     AllStreamMessageReceived streamMessageReceived,
     AllSubscriptionDropped subscriptionDropped,
     HasCaughtUp hasCaughtUp,
     bool prefetchJsonData,
     string name)
 {
     return(new AllStreamSubscription(
                fromPosition,
                this,
                _subscriptions,
                streamMessageReceived,
                subscriptionDropped,
                hasCaughtUp,
                prefetchJsonData,
                name));
 }
        public IAllStreamSubscription SubscribeToAll(
            long?continueAfterPosition,
            AllStreamMessageReceived streamMessageReceived,
            AllSubscriptionDropped subscriptionDropped = null,
            HasCaughtUp hasCaughtUp = null,
            bool prefetchJsonData   = true,
            string name             = null)
        {
            GuardAgainstDisposed();

            return(new AllStreamSubscription(
                       continueAfterPosition,
                       this,
                       _streamStoreNotifier.Value,
                       streamMessageReceived,
                       subscriptionDropped,
                       hasCaughtUp,
                       prefetchJsonData,
                       name));
        }