public SimpleEventStore(string baseDirectory) { var directoryName = Path.Combine(baseDirectory, "EventStore"); Directory.CreateDirectory(directoryName); _allStream = new ChangeStream(directoryName); _notifier = new PollingNotifier(ReadHead); }
public PollingNotifierTests() { _currentPosition = AllStreamPosition.None; _notifier = new PollingNotifier( _ => _currentPosition.ToInt64() != 9999 ? Task.FromResult(_currentPosition) : throw new InvalidOperationException("Error happened"), (ex, p) => { _error.SetResult(ex); // this actually fails 2nd+ time (intentional) return(Task.CompletedTask); }, interval: Interval); }
public SubscriptionFixture(Action <string> writeLine, long maxPosition = 20, long handlerExceptionPosition = -2) { _writeLine = writeLine; _cts = new CancellationTokenSource(); MaxPosition = maxPosition; AllStreamPosition hasCaughtUpTrigger = AllStreamPosition.None; AllStreamPosition notifierTrigger = AllStreamPosition.None; ReadAllPageFunc readAllPage = (from, ct) => Task.FromResult(Read(from)); MessageReceived handler = (s, m, ct) => { LastProcessed = m.Checkpoint; if (m.Checkpoint == handlerExceptionPosition) { throw new InvalidOperationException("Custom exception thrown"); } return(Task.CompletedTask); }; Func <Exception, Task> onError = ex => Async(() => _exceptionSource.SetResult(ex)); HasCaughtUp hasCaughtUp = () => Async(() => hasCaughtUpTrigger = hasCaughtUpTrigger.Shift()); var hasCaughtUpNotifier = new PollingNotifier(_ => Task.FromResult(hasCaughtUpTrigger)); var notifier = new PollingNotifier(_ => Task.FromResult(notifierTrigger)); Subscription = new GenericSubscription( readAllPage, AllStreamPosition.None, notifier.WaitForNotification, handler, onError, hasCaughtUp); var cancellationToken = _cts.Token; cancellationToken.Register(() => { Subscription.Dispose(); notifier.Dispose(); hasCaughtUpNotifier.Dispose(); }); WaitForCaughtUp = () => hasCaughtUpNotifier.WaitForNotification(cancellationToken); AppendEvents = c => { MaxPosition += c; notifierTrigger = notifierTrigger.Shift(); }; }
public Fixture(Action <string> writeLine) { _writeLine = writeLine ?? (_ => {}); _baseDirectory = Path.Combine(Path.GetTempPath(), "local_projections", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(_baseDirectory); EventStore = new SimpleEventStore(_baseDirectory); CheckpointsGroup = new LocalCheckpointGroup(Path.Combine(_baseDirectory, "checkpoint")); var searchDir = Path.Combine(_baseDirectory, "search"); Directory.CreateDirectory(searchDir); Index = new Index(searchDir, new[] { new Field("name"), new Field("value", true), new Field("parent"), new Field("child"), }); IEnumerable <P> ExtractDocument(string key, SearchDocument doc) { _writeLine($"Extracting {doc.Name}"); yield return(new P("name", doc.Name)); yield return(new P("value", doc.Value)); foreach (var c in doc.Children ?? new string[0]) { yield return(new P("child", c)); } foreach (var p in doc.Parents ?? new string[0]) { yield return(new P("parent", p)); } } var searchProjector = new SearchProjector <string, SearchDocument>( Index, "name", ExtractDocument, d => d.Value != null); var mainProjectionDir = Path.Combine(_baseDirectory, "main"); Directory.CreateDirectory(mainProjectionDir); Repository = new ObjectRepository <string, SearchDocument>( new DefaultObjectRepositorySettings <SearchDocument>(mainProjectionDir)); var parentLookupDir = Path.Combine(_baseDirectory, "parent_lookup"); Directory.CreateDirectory(parentLookupDir); ParentLookup = new ObjectRepository <string, List <string> >( new DefaultObjectRepositorySettings <List <string> >(parentLookupDir)); Notifier = new PollingNotifier(EventStore.ReadHead, (ex, p) => { _writeLine($"Error reading head ({p}): {ex}"); return(Task.CompletedTask); }); Subscription = new RecoverableSubscriptionAdapter( CreateSubscription, () => ParallelGroupHelper.CreateObservableParallelGroup( () => Task.FromResult(CreateParallelGroup(searchProjector)), Observer, () => Subscription.Restart()), () => Observer.Min); }