public void calls_checkpoint_delegate_during_catchup()
        {
            var filter            = Filter.StreamId.Prefix("stream-a");
            var checkpointReached = new CountdownEvent(10);
            var eventsSeen        = 0;

            var settings = new CatchUpSubscriptionFilteredSettings(
                10000,
                2,
                verboseLogging: false,
                resolveLinkTos: true,
                maxSearchWindow: 2,
                subscriptionName: String.Empty
                );

            _conn.FilteredSubscribeToAllFrom(
                Position.Start,
                filter,
                settings,
                (s, e) => {
                eventsSeen++;
                return(Task.CompletedTask);
            },
                (s, p) => {
                checkpointReached.Signal();
                return(Task.CompletedTask);
            }, 1);

            if (!checkpointReached.Wait(Timeout))
            {
                Assert.Fail("Checkpoint reached not called enough times within time limit.");
            }

            Assert.AreEqual(10, eventsSeen);
        }
 public EventStoreAllFilteredCatchUpSubscription FilteredSubscribeToAllFrom(Position?lastCheckpoint, Filter filter,
                                                                            CatchUpSubscriptionFilteredSettings settings, Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared, Func <EventStoreCatchUpSubscription, Position, Task> checkpointReached,
                                                                            int checkpointIntervalMultiplier, Action <EventStoreCatchUpSubscription> liveProcessingStarted = null, Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
                                                                            UserCredentials userCredentials = null)
 {
     throw new NotImplementedException();
 }
        public void calls_checkpoint_during_live_processing_stage()
        {
            var filter     = Filter.StreamId.Prefix("stream-a");
            var appeared   = new CountdownEvent(_testEventsAfter.EvenEvents().Count + 1);           // Calls once for switch to live.
            var eventsSeen = 0;
            var isLive     = false;

            var settings = new CatchUpSubscriptionFilteredSettings(
                10000,
                1,
                verboseLogging: false,
                resolveLinkTos: true,
                maxSearchWindow: 1,
                subscriptionName: String.Empty
                );

            _conn.FilteredSubscribeToAllFrom(
                Position.Start,
                filter,
                settings,
                (s, e) => {
                eventsSeen++;
                return(Task.CompletedTask);
            },
                (s, p) => {
                if (isLive)
                {
                    appeared.Signal();
                }

                return(Task.CompletedTask);
            }, 1, s => {
                isLive = true;
                _conn.AppendToStreamAsync("stream-a", ExpectedVersion.Any, _testEventsAfter.EvenEvents()).Wait();
            });

            if (!appeared.Wait(Timeout))
            {
                Assert.Fail("Checkpoint appeared not called enough times within time limit.");
            }

            Assert.AreEqual(20, eventsSeen);
        }
        public void calls_checkpoint_delegate_during_catchup()
        {
            var filter = Filter.StreamId.Prefix("stream-a");
            // in v2 there are 20 events, 10 in stream-a and 10 in stream-b.
            // in v3 there are additionally two stream records and two event type records
            var isV2 = LogFormatHelper <TLogFormat, TStreamId> .IsV2;
            var checkpointReached = new CountdownEvent(isV2 ? 10 : 14);
            var eventsSeen        = 0;

            var settings = new CatchUpSubscriptionFilteredSettings(
                maxLiveQueueSize: 10000,
                readBatchSize: 2,
                verboseLogging: false,
                resolveLinkTos: true,
                maxSearchWindow: 2,
                subscriptionName: String.Empty
                );

            _conn.FilteredSubscribeToAllFrom(
                Position.Start,
                filter,
                settings,
                (s, e) => {
                eventsSeen++;
                return(Task.CompletedTask);
            },
                (s, p) => {
                checkpointReached.Signal();
                return(Task.CompletedTask);
            }, 1);

            if (!checkpointReached.Wait(Timeout))
            {
                Assert.Fail("Checkpoint reached not called enough times within time limit.");
            }

            Assert.AreEqual(10, eventsSeen);
        }
        public EventStoreAllFilteredCatchUpSubscription FilteredSubscribeToAllFrom(Position?lastCheckpoint,
                                                                                   Filter filter, CatchUpSubscriptionFilteredSettings settings,
                                                                                   Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared,
                                                                                   Func <EventStoreCatchUpSubscription, Position, Task> checkpointReached, int checkpointIntervalMultiplier,
                                                                                   Action <EventStoreCatchUpSubscription> liveProcessingStarted = null,
                                                                                   Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
                                                                                   UserCredentials userCredentials = null)
        {
            Ensure.NotNull(eventAppeared, nameof(eventAppeared));
            Ensure.NotNull(settings, nameof(settings));
            Ensure.NotNull(filter, nameof(filter));
            Ensure.NotNull(checkpointReached, nameof(checkpointReached));
            Ensure.Positive(settings.MaxSearchWindow, nameof(settings.MaxSearchWindow));
            Ensure.GreaterThanOrEqualTo(settings.MaxSearchWindow, settings.ReadBatchSize, nameof(settings.ReadBatchSize));

            if (checkpointIntervalMultiplier <= 0 && checkpointIntervalMultiplier != DontReportCheckpointReached)
            {
                throw new ArgumentOutOfRangeException(nameof(checkpointIntervalMultiplier));
            }

            var catchUpSubscription =
                new EventStoreAllFilteredCatchUpSubscription(this, Settings.Log, lastCheckpoint, filter,
                                                             userCredentials, eventAppeared, checkpointReached, checkpointIntervalMultiplier, liveProcessingStarted,
                                                             subscriptionDropped, settings);

            catchUpSubscription.StartAsync();
            return(catchUpSubscription);
        }
 public EventStoreAllFilteredCatchUpSubscription FilteredSubscribeToAllFrom(Position?lastCheckpoint,
                                                                            Filter filter, CatchUpSubscriptionFilteredSettings settings,
                                                                            Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared,
                                                                            Action <EventStoreCatchUpSubscription> liveProcessingStarted = null,
                                                                            Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null,
                                                                            UserCredentials userCredentials = null)
 {
     return(FilteredSubscribeToAllFrom(lastCheckpoint, filter, settings, eventAppeared,
                                       (s, p) => TaskEx.CompletedTask, DontReportCheckpointReached, liveProcessingStarted, subscriptionDropped,
                                       userCredentials));
 }