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 async Task Verify_non_dispatched_event_are_written_to_disk_after_timeout() { //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); _concurrentCheckpointTrackerSut.FlushNotDispatchedTimeoutInSeconds = 1; //flush after one second await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 891, true).ConfigureAwait(false); //now update slot, but tell the manager that you do not dispatched the event. await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 892, false).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)); //in memory checkpoint should be updated. Assert.That(_concurrentCheckpointTrackerSut.GetCheckpoint(projections[0]), Is.EqualTo(892)); //now wait, then retry to write await Task.Delay(1500).ConfigureAwait(false); //not spectactular but works :D await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 893, false).ConfigureAwait(false); //Now everything should be flushed. allDbCheckpoints = _checkPoints.AsQueryable().Where(c => c.Slot == "default").ToList(); Assert.That(allDbCheckpoints.Single().Slot, Is.EqualTo("default")); Assert.That(allDbCheckpoints.Single().Current, Is.EqualTo(893)); Assert.That(allDbCheckpoints.Single().Value, Is.EqualTo(893)); //in memory checkpoint should be updated. Assert.That(_concurrentCheckpointTrackerSut.GetCheckpoint(projections[0]), Is.EqualTo(893)); }
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 Verify_disable_dispatching() { //Two projection in the same slot var projection1 = new Projection(Substitute.For <ICollectionWrapper <SampleReadModel, String> >()); var projections = new IProjection[] { projection1 }; _concurrentCheckpointTrackerSut = new ConcurrentCheckpointTracker(_db, -1); _concurrentCheckpointTrackerSut.SetUp(projections, 1, false); await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 891, true).ConfigureAwait(false); //now update slot, but tell the manager that you do not dispatched the event. await _concurrentCheckpointTrackerSut.UpdateSlotAndSetCheckpointAsync("default", new[] { "Projection" }, 892, false).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), "deferred flush is dispatched we expect checpoint to be updated"); Assert.That(allDbCheckpoints.Single().Value, Is.EqualTo(892), "deferred flush is dispatched we expect checpoint to be updated"); //in memory checkpoint should be updated. Assert.That(_concurrentCheckpointTrackerSut.GetCheckpoint(projections[0]), Is.EqualTo(892)); }