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); }
protected override EventStoreCatchUpSubscription GetEventStoreCatchUpSubscription( CatchupCacheSubscriptionHolder <TAggregate> catchupCacheSubscriptionHolder, IEventStoreConnection connection, Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> onEvent, Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> onSubscriptionDropped) { void onCaughtUp(EventStoreCatchUpSubscription _) { catchupCacheSubscriptionHolder.OnCaughtUpSubject.OnNext(true); } var eventTypeFilter = GetEventsFilters(); var filter = Filter.EventType.Prefix(eventTypeFilter); Logger?.LogInformation($"{Id} => {nameof(AllStreamsCatchupCache<TAggregate>)} - {nameof(GetEventStoreCatchUpSubscription)} - FilteredSubscribeToAllFrom - Filters [{string.Join("|", eventTypeFilter)}]"); var subscription = connection.FilteredSubscribeToAllFrom( _catchupCacheConfiguration.Checkpoint, filter, _catchupCacheConfiguration.CatchUpSubscriptionFilteredSettings, eventAppeared: onEvent, liveProcessingStarted: onCaughtUp, subscriptionDropped: onSubscriptionDropped, userCredentials: _catchupCacheConfiguration.UserCredentials); return(subscription); }
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); }
protected override IDisposable ConnectToEventStream(IEventStoreConnection connection) { void stopSubscription() { if (null != _eventStoreAllFilteredCatchUpSubscription) { _eventStoreAllFilteredCatchUpSubscription.Stop(); } } Task onEvent(EventStoreCatchUpSubscription _, ResolvedEvent resolvedEvent) { Logger?.LogDebug($"{Id} => onEvent - {resolvedEvent.Event.EventId} {resolvedEvent.Event.EventStreamId} {resolvedEvent.Event.EventNumber}"); OnResolvedEvent(resolvedEvent); return(Task.CompletedTask); } void onSubscriptionDropped(EventStoreCatchUpSubscription _, SubscriptionDropReason subscriptionDropReason, Exception exception) { switch (subscriptionDropReason) { case SubscriptionDropReason.UserInitiated: break; case SubscriptionDropReason.ConnectionClosed: case SubscriptionDropReason.NotAuthenticated: case SubscriptionDropReason.AccessDenied: case SubscriptionDropReason.SubscribingError: case SubscriptionDropReason.ServerError: case SubscriptionDropReason.CatchUpError: case SubscriptionDropReason.ProcessingQueueOverflow: case SubscriptionDropReason.EventHandlerException: case SubscriptionDropReason.MaxSubscribersReached: case SubscriptionDropReason.PersistentSubscriptionDeleted: case SubscriptionDropReason.Unknown: case SubscriptionDropReason.NotFound: default: Logger?.LogError(exception, $"{nameof(SubscriptionDropReason)}: [{subscriptionDropReason}] throwed the consumer in an invalid state"); if (_eventStoreStreamConfiguration.DoAppCrashOnFailure) { _killSwitch.KillProcess(exception); } else { createNewFilteredCatchupSubscription(); } break; } } void onCaughtUp(EventStoreCatchUpSubscription _) { } void createNewFilteredCatchupSubscription() { stopSubscription(); var eventTypeFilter = _eventTypeProvider.GetAll().Select(type => type.FullName).ToArray(); var filter = Filter.EventType.Prefix(eventTypeFilter); var position = Position.End; Logger?.LogInformation($"{Id} => {nameof(SubscribeFromEndToAllEventStoreStream)} - FilteredSubscribeToAllFrom - Position: {position} Filters: [{string.Join("|", eventTypeFilter)}]"); _eventStoreAllFilteredCatchUpSubscription = connection.FilteredSubscribeToAllFrom( position, filter, _volatileEventStoreStreamConfiguration.CatchUpSubscriptionFilteredSettings, eventAppeared: onEvent, liveProcessingStarted: onCaughtUp, subscriptionDropped: onSubscriptionDropped, userCredentials: _volatileEventStoreStreamConfiguration.UserCredentials); } createNewFilteredCatchupSubscription(); return(Disposable.Create(() => { stopSubscription(); })); }