//This is a quick test for "ShouldCommit" public static void AssertShouldCommit() { var smallBatch = new CommitBatchPolicy(10); var bigBatch = new CommitBatchPolicy(1000); var reloadPositionCatchedUp = new ProjectionPosition(444, 440, 444); var rebuildFirstPositionCatchedUp = new ProjectionPosition(444, null, 444); var reloadCatchingUp900Uncomitted = new ProjectionPosition(999, 99, 8747235); if (smallBatch.ShouldCommit(reloadPositionCatchedUp) == false) { throw new InvalidOperationException("failed expectation: small batch to commit on " + nameof(reloadPositionCatchedUp)); } if (bigBatch.ShouldCommit(reloadPositionCatchedUp) == false) { throw new InvalidOperationException("failed expectation: big batch to commit on " + nameof(reloadPositionCatchedUp)); } if (smallBatch.ShouldCommit(rebuildFirstPositionCatchedUp) == false) { throw new InvalidOperationException("failed expectation: small batch to commit on " + nameof(rebuildFirstPositionCatchedUp)); } if (smallBatch.ShouldCommit(rebuildFirstPositionCatchedUp) == false) { throw new InvalidOperationException("failed expectation: big batch to commit on " + nameof(rebuildFirstPositionCatchedUp)); } if (smallBatch.ShouldCommit(reloadCatchingUp900Uncomitted) == false) { throw new InvalidOperationException("failed expectation: small batch to commit on " + nameof(reloadCatchingUp900Uncomitted)); } if (bigBatch.ShouldCommit(reloadCatchingUp900Uncomitted)) { throw new InvalidOperationException("failed expectation: big batch not to commit on " + nameof(reloadCatchingUp900Uncomitted)); } }
private async Task CommitIfRelevant(ProjectionPosition p) { if (!BatchingPolicy.ShouldCommit(p)) { return; } await CommitState(); if (p.LooksLikeLatestAvailableInput()) { //performance testing: var now = DateTimeOffset.UtcNow; var timeSpentCatchingUp = now - _startedCatchingUpAt; Console.WriteLine($"Time taken to restore state of projection: {timeSpentCatchingUp.TotalSeconds} seconds"); } }