public void DispatchingEventsInTheWrongOrderWithANonZeroStartingSequenceNumber( IRepository <string, SomeData> repository, View view, ISequenceResolver sequenceResolver, IViewManager viewManager, SomeEvent firstEvent, SomeEvent secondEvent) { "Given a view repository"._(() => repository = new MemoryRepository <string, SomeData>()); "and a view"._(() => view = new SomeView(repository)); "and a sequence resolver"._(() => sequenceResolver = new CustomSequenceResolver()); "and a view manager"._(ctx => viewManager = ViewManager.ForViews(view).OrderEventsUsing(sequenceResolver).StartAtSequenceNumber(2).Create().Using(ctx)); "and a first event"._(() => firstEvent = new SomeEvent { Sequence = 2, Id = "test2" }); "and a second event"._(() => secondEvent = new SomeEvent { Sequence = 3, Id = "test3" }); "when those events are dispatched out of order"._( () => { viewManager.QueueForDispatch(secondEvent); viewManager.QueueForDispatch(firstEvent); }); "and the operation is given time to process"._(() => Thread.Sleep(1000)); "then the view received the second event last"._(() => repository.Get("root").LastEventId.Should().Be(secondEvent.Id)); "and the view received two events"._(() => repository.Get("root").EventCount.Should().Be(1)); }
public ManagedEventDispatcher( IEnumerable <View> views, ISequenceResolver sequenceResolver, IRepository <string, SequenceInfo> sequenceRepository, Func <long, IOrderedBuffer> bufferFactory, int quietTimeTimeout) { Guard.Against.NullOrEmptyOrNullElements(() => views); this.views = views.ToDictionary( view => view, view => { var sequenceInfo = sequenceRepository.Get(view.GetType().FullName); return(sequenceInfo == null ? 0L : sequenceInfo.SequenceNumber); }); this.sequenceResolver = sequenceResolver; this.sequenceRepository = sequenceRepository; this.quietTimeTimeout = quietTimeTimeout; this.sequenceNumber = this.views.Values.Min(); this.buffer = bufferFactory.Invoke(this.sequenceNumber); var task = new Task(() => this.Run(this.cancellationTokenSource.Token)); task.ContinueWith(t => this.cancellationTokenSource.Dispose(), TaskContinuationOptions.ExecuteSynchronously); task.Start(); this.timer = new Timer(this.TimerCallback, null, this.quietTimeTimeout, Timeout.Infinite); }
public void EventReplayingOnStartUp( List <SomeEvent> eventStore, IRepository <string, SomeData> repository, View view, ISequenceResolver sequenceResolver, IEventResolver eventResolver, IViewManager viewManager) { "Given an event store with three events"._(() => eventStore = new List <SomeEvent> { new SomeEvent { Sequence = 1, Id = "test" }, new SomeEvent { Sequence = 2, Id = "test2" }, new SomeEvent { Sequence = 3, Id = "test3" }, }); "and a view repository"._(() => repository = new MemoryRepository <string, SomeData>()); "and a view"._(() => view = new SomeView(repository)); "and a sequence resolver"._(() => sequenceResolver = new CustomSequenceResolver()); "and an event resolver"._(() => eventResolver = new CustomEventResolver(eventStore)); "when a view manager is created"._(ctx => viewManager = ViewManager.ForViews(view) .OrderEventsUsing(sequenceResolver).StartAtSequenceNumber(0) .ResolveMissingEventsUsing(eventResolver).WithATimeoutOf(Timeout.Infinite) .Create().Using(ctx)); "and the operation is given time to process"._(() => Thread.Sleep(1000)); "then the view received the third event last"._(() => repository.Get("root").LastEventId.Should().Be(eventStore[2].Id)); "and the view received three events"._(() => repository.Get("root").EventCount.Should().Be(3)); }
private ViewManager OrderEventsUsing(ISequenceResolver sequenceResolver) { Guard.Against.Null(() => sequenceResolver); this.sequenceResolver = sequenceResolver; return(this); }
public Configure.EventSequencingOptions SequenceEventsUsing(ISequenceResolver sequenceResolver) { Guard.Against.Null(() => sequenceResolver); this.bufferType = typeof(OrderedBuffer); this.eventDispatcherType = typeof(OrderedEventDispatcher); this.sequenceResolver = sequenceResolver; return(this); }
public void SubsequentViewPersistence( IRepository <string, SomeData> repository, View view, ISequenceResolver sequenceResolver, IRepository <string, Snapshot> snapshotRepository, IViewManager viewManager, SomeEvent firstEvent, SomeEvent secondEvent, SomeData initialData, SomeData actualInitialData, SomeData subsequentData) { "Given a view repository"._(() => repository = new MemoryRepository <string, SomeData>()); "and some intial data"._( () => initialData = new SomeData { LastEventId = "test2", EventCount = 2, }); "and the repository contains the initial data"._(() => repository.AddOrUpdate("root", initialData)); "and a view"._(() => view = new SomeView(repository)); "and a sequence resolver"._(() => sequenceResolver = new CustomSequenceResolver()); "and a snapshot repository"._(() => snapshotRepository = new MemoryRepository <string, Snapshot>()); "and the snapshot repository contains the initial snapshot data"._( () => snapshotRepository.AddOrUpdate( view.GetType().FullName, new Snapshot { ViewName = view.GetType().FullName, PersistedSequenceNumber = 2, })); "and a view manager"._(ctx => viewManager = ViewManager.ForViews(view) .OrderEventsUsing(sequenceResolver) .SnapshotViewsUsing(snapshotRepository).WithAQuietTimeTimeoutOf(2) .Create().Using(ctx)); "and a third event"._(() => firstEvent = new SomeEvent { Sequence = 3, Id = "test3" }); "and a fourth event"._(() => secondEvent = new SomeEvent { Sequence = 4, Id = "test4" }); "when those events are dispatched"._( () => { viewManager.QueueForDispatch(firstEvent); viewManager.QueueForDispatch(secondEvent); }); "and the operation is given time to process"._(() => Thread.Sleep(1000)); "and the repository is queried initially"._(() => actualInitialData = repository.Get("root")); "and the snapshot is given time to process"._(() => Thread.Sleep(2000)); "and the repository is queried subsequently"._(() => subsequentData = repository.Get("root")); "then the initial query should be empty"._(() => actualInitialData.Should().Be(initialData)); "and the view received the second event last"._(() => subsequentData.LastEventId.Should().Be(secondEvent.Id)); "and the view received two events"._(() => subsequentData.EventCount.Should().Be(4)); }
public OrderedEventDispatcher(IEventDispatcher innerEventDispatcher, ISequenceResolver sequenceResolver, IOrderedBuffer buffer) { Guard.Against.Null(() => innerEventDispatcher); Guard.Against.Null(() => sequenceResolver); Guard.Against.Null(() => buffer); this.innerEventDispatcher = innerEventDispatcher; this.sequenceResolver = sequenceResolver; this.buffer = buffer; var task = new Task(() => this.Run(this.cancellationTokenSource.Token)); task.ContinueWith(t => this.cancellationTokenSource.Dispose(), TaskContinuationOptions.ExecuteSynchronously); task.Start(); }
private IEnumerable <Instance> Instantiate(string variableName, ISequenceResolver resolver, IEnumerable <string> categories, IDictionary <string, string> traits) { foreach (var obj in resolver.Execute()) { var instanceVariable = new InstanceVariable(obj); yield return(new Instance( new Dictionary <string, ITestVariable>() { { variableName, instanceVariable } }, categories, traits )); } }
private IEnumerable <Instance> Instantiate(string variableName, ISequenceResolver resolver, IDictionary <string, DerivationArgs> derivations, IEnumerable <string> categories, IDictionary <string, string> traits) { foreach (var obj in resolver.Execute()) { var dico = new Dictionary <string, ITestVariable>() { { variableName, new InstanceVariable(obj) } }; foreach (var derivation in derivations) { dico.Add(derivation.Key, new InstanceVariable(derivation.Value.Transformer.Execute(dico[derivation.Value.Source].GetValue()))); } yield return(new Instance( dico, categories, traits )); } }
public void InitialViewPersistence( IRepository <string, SomeData> repository, View view, ISequenceResolver sequenceResolver, IRepository <string, Snapshot> snapshotRepository, IViewManager viewManager, SomeEvent firstEvent, SomeEvent secondEvent, SomeData initialData, SomeData subsequentData) { "Given a view repository"._(() => repository = new MemoryRepository <string, SomeData>()); "and a view"._(() => view = new SomeView(repository)); "and a sequence resolver"._(() => sequenceResolver = new CustomSequenceResolver()); "and a snapshot repository"._(() => snapshotRepository = new MemoryRepository <string, Snapshot>()); "and a view manager"._(ctx => viewManager = ViewManager.ForViews(view) .OrderEventsUsing(sequenceResolver) .SnapshotViewsUsing(snapshotRepository).WithAQuietTimeTimeoutOf(2) .Create().Using(ctx)); "and a first event"._(() => firstEvent = new SomeEvent { Sequence = 1, Id = "test" }); "and a second event"._(() => secondEvent = new SomeEvent { Sequence = 2, Id = "test2" }); "when those events are dispatched"._( () => { viewManager.QueueForDispatch(firstEvent); viewManager.QueueForDispatch(secondEvent); }); "and the operation is given time to process"._(() => Thread.Sleep(1000)); "and the repository is queried initially"._(() => initialData = repository.Get("root")); "and the snapshot is given time to process"._(() => Thread.Sleep(2000)); "and the repository is queried subsequently"._(() => subsequentData = repository.Get("root")); "then the initial query should be empty"._(() => initialData.Should().BeNull()); "and the view received the second event last"._(() => subsequentData.LastEventId.Should().Be(secondEvent.Id)); "and the view received two events"._(() => subsequentData.EventCount.Should().Be(2)); }
internal EventManager(ISequenceResolver sequenceResolver, IEventResolver eventResolver, int timeout, IEventBuffer eventBuffer, bool disposeBuffer) { Trace.WriteLine("EventManager.ctor(ISequenceResolver sequenceResolver, IEventResolver eventResolver, IEventBuffer eventBuffer, int timeout, bool disposeBuffer)"); Guard.Against.Null(() => sequenceResolver); Guard.Against.Null(() => eventResolver); Guard.Against.Null(() => eventBuffer); Guard.Against.NegativeTimeout(() => timeout); this.sequenceResolver = sequenceResolver; this.eventResolver = eventResolver; this.eventBuffer = eventBuffer; this.timeout = timeout; this.disposeBuffer = disposeBuffer; Trace.WriteLine("EventManager.ctor: Timer.ctor(Timeout.Infinite, Timeout.Infinite)"); this.timer = new Timer(state => this.ResolveMissingEvents(this.cancellationTokenSource.Token), null, Timeout.Infinite, Timeout.Infinite); // NOTE (Cameron): This will immediately resolve all missing events from the specified sequence number (eg. event re-playing). this.IsEventReplaying = true; new Task(() => this.ResolveMissingEvents(this.cancellationTokenSource.Token)).Start(); }
public EventManager(ISequenceResolver sequenceResolver) : this(sequenceResolver, new NullEventResolver(), Timeout.Infinite, new EventBuffer(0L), true) { }
Configuration.EventOrderingOptions Configuration.EventOrdering.OrderEventsUsing(ISequenceResolver sequenceResolver) { return(this.OrderEventsUsing(sequenceResolver)); }
public SequenceResultSetResolverArgs(ISequenceResolver resolver) : base(new List <ISequenceResolver>() { resolver }) { }
public FilterSequenceResolverArgs(ISequenceResolver resolver, IPredicate predicate, ITransformer transformation) => (Resolver, Predicate, OperandTransformation) = (resolver, predicate, transformation);
public EventManager(ISequenceResolver sequenceResolver, IEventResolver eventResolver, int timeout, IEventBuffer eventBuffer) : this(sequenceResolver, eventResolver, timeout, eventBuffer, false) { }
public EventManager(ISequenceResolver sequenceResolver, IEventResolver eventResolver, int timeout) : this(sequenceResolver, eventResolver, timeout, new EventBuffer(0L), true) { }
public EventManager(ISequenceResolver sequenceResolver, IEventBuffer eventBuffer) : this(sequenceResolver, new NullEventResolver(), Timeout.Infinite, eventBuffer, false) { }
public CartesianProductSequenceCombination(ISequenceResolver resolver) => Resolver = resolver;