public void max_dispatched_is_handled_per_distinct_slot() { CreateAggregate(1); CreateAggregate(2); CreateAggregate(3); //prepare the tracker ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection1.GetSlotName(), new[] { _projection1.GetCommonName() }, 2); thisTracker.UpdateSlotAndSetCheckpoint(_projection3.GetSlotName(), new[] { _projection3.GetCommonName() }, 1); var status = sut.Rebuild(); WaitForFinish(status); Assert.That(_writer1.All.Count(), Is.EqualTo(2)); Assert.That(_writer3.All.Count(), Is.EqualTo(1)); var allCheckpoints = _checkpointCollection.FindAll().ToList(); var projection1 = allCheckpoints.Single(c => c.Id == _projection1.GetCommonName()); Assert.That(projection1.Current, Is.EqualTo(2)); Assert.That(projection1.Value, Is.EqualTo(2)); var projection2 = allCheckpoints.Single(c => c.Id == _projection3.GetCommonName()); Assert.That(projection2.Current, Is.EqualTo(1)); Assert.That(projection2.Value, Is.EqualTo(1)); }
protected void ConfigureProjectionEngine() { if (Engine != null) { Engine.Stop(); } _tracker = new ConcurrentCheckpointTracker(Database); _statusChecker = new ConcurrentCheckpointStatusChecker(Database); var tenantId = new TenantId("engine"); var config = new ProjectionEngineConfig() { Slots = new[] { "*" }, EventStoreConnectionString = _eventStoreConnectionString, TenantId = tenantId }; _rebuildContext = new RebuildContext(false); StorageFactory = new MongoStorageFactory(Database, _rebuildContext); Engine = new ConcurrentProjectionsEngine( _tracker, BuildProjections().ToArray(), new PollingClientWrapper(new CommitEnhancer(_identityConverter), true, _tracker), new NullHouseKeeper(), _rebuildContext, new NullNotifyCommitHandled(), config ); Engine.LoggerFactory = Substitute.For <ILoggerFactory>(); Engine.LoggerFactory.Create(Arg.Any <Type>()).Returns(NullLogger.Instance); Engine.StartWithManualPoll(); }
public async Task Verify_non_dispatched_event_can_be_flushed() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projections = new IProjection[] { projection1 }; _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60); _concurrentCheckpointTrackerSut.SetUp(projections, 1, false); await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 891, true).ConfigureAwait(false); //now update slot telling that the event was not dispatched, then flush immediately. await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 892, false).ConfigureAwait(false); await _concurrentCheckpointTrackerSut.FlushCheckpointAsync().ConfigureAwait(false); var allDbCheckpoints = _checkPoints.AsQueryable().Where(c => c.Slot == "default").ToList(); Assert.That(allDbCheckpoints.Single().Slot, Is.EqualTo("default")); Assert.That(allDbCheckpoints.Single().Current, Is.EqualTo(892)); Assert.That(allDbCheckpoints.Single().Value, Is.EqualTo(892)); //in memory checkpoint should be updated. Assert.That(_concurrentCheckpointTrackerSut.GetCheckpoint(projections[0]), Is.EqualTo(892)); }
public void Verify_projection_change_info_for_projection_that_changed_slot_and_signature() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projections = new IProjection[] { projection1 }; var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature + "modified") { Slot = projection1.Info.SlotName + "modified" }; _checkPoints.InsertMany(new[] { checkpoint1, }); _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); var status = _slotStatusCheckerSut.GetProjectionChangeInfo(); var singleProjectionStatus = status.Single(); Assert.That((Int32)(singleProjectionStatus.ChangeType | ProjectionChangeInfo.ProjectionChangeType.SlotChange), Is.GreaterThan(0)); Assert.That((Int32)(singleProjectionStatus.ChangeType | ProjectionChangeInfo.ProjectionChangeType.SignatureChange), Is.GreaterThan(0)); Assert.That(singleProjectionStatus.OldSlot, Is.EqualTo(projection1.Info.SlotName + "modified")); Assert.That(singleProjectionStatus.ActualSlot, Is.EqualTo(projection1.Info.SlotName)); Assert.That(singleProjectionStatus.OldSignature, Is.EqualTo(projection1.Info.Signature + "modified")); Assert.That(singleProjectionStatus.ActualSignature, Is.EqualTo(projection1.Info.Signature)); }
public void Verify_projection_change_info_new_projection() { var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature) { Slot = projection1.Info.SlotName }; var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature) { Slot = projection2.Info.SlotName }; _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, }); _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); var status = _slotStatusCheckerSut.GetProjectionChangeInfo(); Assert.That(status.Count(), Is.EqualTo(3)); var none = status.Where(s => s.ChangeType == ProjectionChangeInfo.ProjectionChangeType.None); Assert.That(none.Count(), Is.EqualTo(2)); var singleChange = status.Single(s => s.ChangeType == ProjectionChangeInfo.ProjectionChangeType.NewProjection); Assert.That(singleChange.CommonName, Is.EqualTo(projection3.Info.CommonName)); }
public async Task max_dispatched_is_handled_per_distinct_slot() { await CreateAggregate(1).ConfigureAwait(false); await CreateAggregate(2).ConfigureAwait(false); await CreateAggregate(3).ConfigureAwait(false); //prepare the tracker ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db, 60); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection1.Info.SlotName, new[] { _projection1.Info.CommonName }, 2, true); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection3.Info.SlotName, new[] { _projection3.Info.CommonName }, 1, true); var status = await sut.RebuildAsync().ConfigureAwait(false); WaitForFinish(status); Assert.That(_writer1.All.Count(), Is.EqualTo(2)); Assert.That(_writer3.All.Count(), Is.EqualTo(1)); var allCheckpoints = _checkpointCollection.FindAll().ToList(); var projection1 = allCheckpoints.Single(c => c.Id == _projection1.Info.CommonName); Assert.That(projection1.Current, Is.EqualTo(2)); Assert.That(projection1.Value, Is.EqualTo(2)); var projection2 = allCheckpoints.Single(c => c.Id == _projection3.Info.CommonName); Assert.That(projection2.Current, Is.EqualTo(1)); Assert.That(projection2.Value, Is.EqualTo(1)); }
public void Verify_slot_status_new_projection() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature); var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature); checkpoint1.Current = checkpoint1.Value; checkpoint2.Current = checkpoint2.Value; _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, }); _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); var status = _slotStatusCheckerSut.GetSlotsStatus(); Assert.That(status.NewSlots, Is.EquivalentTo(new[] { projection3.Info.SlotName })); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(0)); }
private IProjection[] SetupTwoProjectionsError() { _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db); var rebuildContext = new RebuildContext(false); var storageFactory = new MongoStorageFactory(_db, rebuildContext); var writer1 = new CollectionWrapper <SampleReadModel, string>(storageFactory, new NotifyToNobody()); var writer2 = new CollectionWrapper <SampleReadModel2, string>(storageFactory, new NotifyToNobody()); var projection1 = new Projection(writer1); var projection2 = new Projection2(writer2); var projections = new IProjection[] { projection1, projection2 }; var p1 = new Checkpoint(projection1.Info.CommonName, 42, projection1.Info.Signature); p1.Slot = projection1.Info.SlotName; _checkPoints.Save(p1, p1.Id); var p2 = new Checkpoint(projection2.Info.CommonName, 40, projection2.Info.Signature); p2.Slot = projection1.Info.SlotName; _checkPoints.Save(p2, p2.Id); _concurrentCheckpointTrackerSut.SetUp(projections, 1, false); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); return(projections); }
public void verify_slot_status_error() { var projections = SetupTwoProjectionsError(); _sut = new ConcurrentCheckpointTracker(_db); var status = _sut.GetSlotsStatus(projections); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(1)); }
protected void ConfigureProjectionEngine(Boolean dropCheckpoints = true) { if (Engine != null) { Engine.Stop(); } if (dropCheckpoints) { _checkpoints.Drop(); } _tracker = new ConcurrentCheckpointTracker(Database); _statusChecker = new ConcurrentCheckpointStatusChecker(Database); var tenantId = new TenantId("engine"); var config = new ProjectionEngineConfig() { Slots = new[] { "*" }, EventStoreConnectionString = _eventStoreConnectionString, TenantId = tenantId, BucketInfo = new List <BucketInfo>() { new BucketInfo() { Slots = new[] { "*" }, BufferSize = 10 } }, DelayedStartInMilliseconds = 1000, ForcedGcSecondsInterval = 0, EngineVersion = "v2", }; RebuildSettings.Init(OnShouldRebuild(), OnShouldUseNitro()); _rebuildContext = new RebuildContext(RebuildSettings.NitroMode); StorageFactory = new MongoStorageFactory(Database, _rebuildContext); Func <IPersistStreams, CommitPollingClient> pollingClientFactory = ps => new CommitPollingClient( ps, new CommitEnhancer(_identityConverter), OnGetPollingClientId(), NullLogger.Instance); Engine = new ProjectionEngine( pollingClientFactory, _tracker, BuildProjections().ToArray(), new NullHouseKeeper(), _rebuildContext, new NullNotifyCommitHandled(), config ); Engine.LoggerFactory = Substitute.For <ILoggerFactory>(); Engine.LoggerFactory.Create(Arg.Any <Type>()).Returns(NullLogger.Instance); OnStartPolling(); }
public void Verify_slot_status_error() { var projections = SetupTwoProjectionsError(); _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); var status = _slotStatusCheckerSut.GetSlotsStatus(); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(1)); }
public virtual void TestFixtureSetUp() { _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString; var url = new MongoUrl(_eventStoreConnectionString); var client = new MongoClient(url); _db = client.GetDatabase(url.DatabaseName); _db.Drop(); ProjectionEngineConfig config = new ProjectionEngineConfig(); config.EventStoreConnectionString = _eventStoreConnectionString; config.Slots = new string[] { "*" }; config.TenantId = new TenantId("A"); config.BucketInfo = new List <BucketInfo>(); config.BucketInfo.Add(new BucketInfo() { Slots = new[] { "*" }, BufferSize = 10000 }); _identityConverter = new IdentityManager(new CounterService(_db)); _identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly); ConfigureEventStore(); CommitEnhancer commitEnhancer = new CommitEnhancer(_identityConverter); _eventUnwinder = new EventUnwinder(config, new TestLogger(LoggerLevel.Info)); _unwindedEventCollection = _db.GetCollection <UnwindedDomainEvent>("UnwindedEvents"); MongoFlatMapper.EnableFlatMapping(true); MongoFlatIdSerializerHelper.Initialize(_identityConverter); var rebuildContext = new RebuildContext(NitroEnabled); _storageFactory = new MongoStorageFactory(_db, rebuildContext); _reader1 = new MongoReader <SampleReadModel, string>(_db); _reader2 = new MongoReader <SampleReadModel2, string>(_db); _reader3 = new MongoReader <SampleReadModel3, string>(_db); //now configure RebuildProjectionEngine _tracker = new ConcurrentCheckpointTracker(_db); var projections = BuildProjections().ToArray(); _tracker.SetUp(projections, 1, false); ProjectionEventInspector inspector = new ProjectionEventInspector(); inspector.AddAssembly(Assembly.GetExecutingAssembly()); sut = new RebuildProjectionEngine(_eventUnwinder, _tracker, projections, rebuildContext, config, inspector); sut.Logger = new TestLogger(LoggerLevel.Debug); _checkpointCollection = _db.GetCollection <Checkpoint>("checkpoints"); }
public void SetUp() { var connectionString = ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString; var url = new MongoUrl(connectionString); var client = new MongoClient(url); _db = client.GetServer().GetDatabase(url.DatabaseName); var sut = new ConcurrentCheckpointTracker(_db); _checkPoints = _db.GetCollection <Checkpoint>("checkpoints"); _checkPoints.Drop(); }
public void updateSlotAndSetCheckpoint_should_create_record_in_database() { Assert.Inconclusive("Probably this is not correct, it is better to setup the tracker and then set values"); var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); var projections = new IProjection[] { projection1, projection2 }; _sut = new ConcurrentCheckpointTracker(_db); _sut.UpdateSlotAndSetCheckpoint(projection1.GetSlotName(), projections.Select(p => p.GetCommonName()), 2); var checkpoints = _checkPoints.FindAll().ToEnumerable().Where(c => c.Id != "VERSION").ToList(); Assert.That(checkpoints, Has.Count.EqualTo(2)); Assert.That(checkpoints.All(c => c.Value == 2)); }
protected async Task ConfigureProjectionEngineAsync(Boolean dropCheckpoints = true) { Engine?.Stop(); if (dropCheckpoints) { _checkpoints.Drop(); } _tracker = new ConcurrentCheckpointTracker(Database); _statusChecker = new MongoDirectConcurrentCheckpointStatusChecker(Database); var tenantId = new TenantId("engine"); var config = new ProjectionEngineConfig() { Slots = new[] { "*" }, EventStoreConnectionString = _eventStoreConnectionString, TenantId = tenantId, BucketInfo = new List <BucketInfo>() { new BucketInfo() { Slots = new[] { "*" }, BufferSize = 10 } }, DelayedStartInMilliseconds = 0, ForcedGcSecondsInterval = 0, EngineVersion = "v2", }; RebuildSettings.Init(OnShouldRebuild(), OnShouldUseNitro()); var rebuildContext = new RebuildContext(RebuildSettings.NitroMode); StorageFactory = new MongoStorageFactory(Database, rebuildContext); Engine = new ProjectionEngine( _pollingClientFactory, Persistence, _tracker, BuildProjections().ToArray(), new NullHouseKeeper(), new NullNotifyCommitHandled(), config, NullLogger.Instance, NullLoggerThreadContextManager.Instance); Engine.LoggerFactory = Substitute.For <ILoggerFactory>(); Engine.LoggerFactory.Create(Arg.Any <Type>()).Returns(NullLogger.Instance); await OnStartPolling().ConfigureAwait(false); }
public void verify_status_for_slot_that_needs_to_be_rebuilded() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projections = new IProjection[] { projection1 }; var checkpoint1 = new Checkpoint(projection1.GetCommonName(), 1, projection1.GetSignature() + "modified"); _checkPoints.InsertMany(new[] { checkpoint1, }); _sut = new ConcurrentCheckpointTracker(_db); var status = _sut.GetSlotsStatus(projections); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(1)); }
public void event_is_dispatched() { CreateAggregate(); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection1.GetSlotName(), new[] { _projection1.GetCommonName() }, 1); thisTracker.UpdateSlotAndSetCheckpoint(_projection3.GetSlotName(), new[] { _projection3.GetCommonName() }, 1); var status = sut.Rebuild(); WaitForFinish(status); Assert.That(_writer1.All.Count(), Is.EqualTo(1)); Assert.That(_writer3.All.Count(), Is.EqualTo(1)); }
public async Task dispatch_only_until_maximum_checkpoint_already_dispatched() { await CreateAggregate(1).ConfigureAwait(false); await CreateAggregate(2).ConfigureAwait(false); await CreateAggregate(3).ConfigureAwait(false); //prepare the tracker ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db, 60); thisTracker.SetUp(new[] { _projection }, 1, false); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection.Info.SlotName, new[] { _projection.Info.CommonName }, 2, true); //Set the projection as dispatched var status = await sut.RebuildAsync().ConfigureAwait(false); WaitForFinish(status); Assert.That(_writer.All.Count(), Is.EqualTo(2)); }
public void verify_slot_status_new_projection_when_db_empty() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; _sut = new ConcurrentCheckpointTracker(_db); var status = _sut.GetSlotsStatus(projections); Assert.That(status.NewSlots, Has.Count.EqualTo(0)); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(0)); }
public void dispatch_only_until_maximum_checkpoint_already_dispatched() { CreateAggregate(1); CreateAggregate(2); CreateAggregate(3); //prepare the tracker ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection.GetSlotName(), new[] { _projection.GetCommonName() }, 2); //Set the projection as dispatched var status = sut.Rebuild(); WaitForFinish(status); Assert.That(_writer.All.Count(), Is.EqualTo(2)); }
public async Task event_is_dispatched() { await CreateAggregate().ConfigureAwait(false); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db, 60); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection1.Info.SlotName, new[] { _projection1.Info.CommonName }, 1, true); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection3.Info.SlotName, new[] { _projection3.Info.CommonName }, 1, true); var status = await sut.RebuildAsync().ConfigureAwait(false); WaitForFinish(status); Assert.That(_writer1.All.Count(), Is.EqualTo(1)); Assert.That(_writer3.All.Count(), Is.EqualTo(1)); }
public async Task Verify_dispatched_event_are_flushed() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projections = new IProjection[] { projection1 }; _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60); _concurrentCheckpointTrackerSut.SetUp(projections, 1, false); await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 891, true).ConfigureAwait(false); var allDbCheckpoints = _checkPoints.AsQueryable().Where(c => c.Slot == "default").ToList(); Assert.That(allDbCheckpoints.Single().Slot, Is.EqualTo("default")); Assert.That(allDbCheckpoints.Single().Current, Is.EqualTo(891)); Assert.That(allDbCheckpoints.Single().Value, Is.EqualTo(891)); }
public void event_is_dispatched() { CreateAggregate(); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); thisTracker.UpdateSlotAndSetCheckpoint(_projection1.GetSlotName(), new[] { _projection1.GetCommonName() }, 1); thisTracker.UpdateSlotAndSetCheckpoint(_projection3.GetSlotName(), new[] { _projection3.GetCommonName() }, 1); var status = sut.Rebuild(); WaitForFinish(status); var coll = _db.GetCollection <BsonDocument>("Sample"); var allRecord = coll.FindAll().ToList(); Assert.That(allRecord, Has.Count.EqualTo(1)); }
private void SetupOneProjectionNew() { _sut = new ConcurrentCheckpointTracker(_db); var rebuildContext = new RebuildContext(false); var storageFactory = new MongoStorageFactory(_db, rebuildContext); var writer1 = new CollectionWrapper <SampleReadModel, string>(storageFactory, new NotifyToNobody()); var writer2 = new CollectionWrapper <SampleReadModel2, string>(storageFactory, new NotifyToNobody()); var projection1 = new Projection(writer1); var projection2 = new Projection2(writer2); var projections = new IProjection[] { projection1, projection2 }; var p1 = new Checkpoint(projection1.GetCommonName(), "42"); p1.Slot = projection1.GetSlotName(); _checkPoints.Save(p1); _sut.SetUp(projections, 1); }
private void UpdateVaueQueryingConcurrentCheckpointTracker(long lastCommit) { //read data directly from the concurrent checkpoint tracker. //first be sure to have preloaded a dictionary with slot in key and //one of the projection as value. InitProjectionDictionary(); var allSlot = _sampleProjectionPerSlot .Select(kvp => new { SlotName = kvp.Key, SlotCheckpoint = ConcurrentCheckpointTracker.GetCheckpoint(kvp.Value) }); foreach (var slotStatus in allSlot) { UpdateSlot(lastCommit, slotStatus.SlotName, slotStatus.SlotCheckpoint); } }
public async Task event_is_dispatched() { await CreateAggregate().ConfigureAwait(false); ConcurrentCheckpointTracker thisTracker = new ConcurrentCheckpointTracker(_db, 60); thisTracker.SetUp(new[] { _projection1, _projection3 }, 1, false); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection1.Info.SlotName, new[] { _projection1.Info.CommonName }, 1, true); await thisTracker.UpdateSlotAndSetCheckpointAsync(_projection3.Info.SlotName, new[] { _projection3.Info.CommonName }, 1, true); RebuildStatus status = await sut.RebuildAsync().ConfigureAwait(false); WaitForFinish(status); var coll = _db.GetCollection <BsonDocument>("Sample"); var allRecord = coll.FindAll().ToList(); Assert.That(allRecord, Has.Count.EqualTo(1)); }
/// <summary> /// If a rebuild starts then stops, we have a particular situation where signature is ok, current is null /// and if the slot is not marked as to rebuild, the engine will simply restart the slot redispatching everything. /// </summary> private void SetupOneProjectionWithCurrentNull() { _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60); var rebuildContext = new RebuildContext(false); var storageFactory = new MongoStorageFactory(_db, rebuildContext); var writer1 = new CollectionWrapper <SampleReadModel, string>(storageFactory, new NotifyToNobody()); var projection1 = new Projection(writer1); var projections = new IProjection[] { projection1 }; var p1 = new Checkpoint(projection1.Info.CommonName, 42, projection1.Info.Signature); p1.Slot = projection1.Info.SlotName; p1.Value = 42; p1.Current = null; _checkPoints.Save(p1, p1.Id); _concurrentCheckpointTrackerSut.SetUp(projections, 1, false); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); }
public void verify_new_projection_when_zero_events_dispatched() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; var checkpoint1 = new Checkpoint(projection1.GetCommonName(), 1, projection1.GetSignature()); var checkpoint2 = new Checkpoint(projection2.GetCommonName(), 1, projection2.GetSignature()); var checkpoint3 = new Checkpoint(projection3.GetCommonName(), 0, projection3.GetSignature()); _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, checkpoint3 }); _sut = new ConcurrentCheckpointTracker(_db); var status = _sut.GetSlotsStatus(projections); Assert.That(status.NewSlots, Is.EquivalentTo(new[] { projection3.GetSlotName() })); }
public void Verify_new_projection_when_zero_events_dispatched() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; var checkpoint1 = new Checkpoint(projection1.Info.CommonName, 1, projection1.Info.Signature); var checkpoint2 = new Checkpoint(projection2.Info.CommonName, 1, projection2.Info.Signature); var checkpoint3 = new Checkpoint(projection3.Info.CommonName, 0, projection3.Info.Signature); _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, checkpoint3 }); _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, 60); _slotStatusCheckerSut = new SlotStatusManager(_db, projections.Select(p => p.Info).ToArray()); var status = _slotStatusCheckerSut.GetSlotsStatus(); Assert.That(status.NewSlots, Is.EquivalentTo(new[] { projection3.Info.SlotName })); }
public void verify_slot_status_all_ok() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projection2 = new Projection2(Substitute.For <ICollectionWrapper <SampleReadModel2, String> >()); //A projection in other slot var projection3 = new Projection3(Substitute.For <ICollectionWrapper <SampleReadModel3, String> >()); var projections = new IProjection[] { projection1, projection2, projection3 }; var checkpoint1 = new Checkpoint(projection1.GetCommonName(), 1, projection1.GetSignature()); var checkpoint2 = new Checkpoint(projection2.GetCommonName(), 1, projection2.GetSignature()); var checkpoint3 = new Checkpoint(projection3.GetCommonName(), 1, projection3.GetSignature()); _checkPoints.InsertMany(new[] { checkpoint1, checkpoint2, checkpoint3 }); _sut = new ConcurrentCheckpointTracker(_db); var status = _sut.GetSlotsStatus(projections); Assert.That(status.NewSlots, Has.Count.EqualTo(0)); Assert.That(status.SlotsThatNeedsRebuild, Has.Count.EqualTo(0)); }