public async Task CleanupTestCheckpointed(bool checkEntireQueueOnCleanup) { (IMessageStore messageStore, ICheckpointStore checkpointStore, InMemoryDbStore _)result = await this.GetMessageStore(checkEntireQueueOnCleanup, 20); ICheckpointStore checkpointStore = result.checkpointStore; using (IMessageStore messageStore = result.messageStore) { for (int i = 0; i < 200; i++) { if (i % 2 == 0) { IMessage input = this.GetMessage(i); IMessage updatedMessage = await messageStore.Add("module1", input, 0); CompareUpdatedMessageWithOffset(input, i / 2, updatedMessage); } else { IMessage input = this.GetMessage(i); IMessage updatedMessage = await messageStore.Add("module2", input, 0); CompareUpdatedMessageWithOffset(input, i / 2, updatedMessage); } } IMessageIterator module1Iterator = messageStore.GetMessageIterator("module1"); IEnumerable <IMessage> batch = await module1Iterator.GetNext(100); Assert.Equal(100, batch.Count()); IMessageIterator module2Iterator = messageStore.GetMessageIterator("module2"); batch = await module2Iterator.GetNext(100); Assert.Equal(100, batch.Count()); await checkpointStore.SetCheckpointDataAsync("module1", new CheckpointData(198), CancellationToken.None); await checkpointStore.SetCheckpointDataAsync("module2", new CheckpointData(199), CancellationToken.None); await Task.Delay(TimeSpan.FromSeconds(100)); module2Iterator = messageStore.GetMessageIterator("module2"); batch = await module2Iterator.GetNext(100); Assert.Empty(batch); module1Iterator = messageStore.GetMessageIterator("module1"); batch = await module1Iterator.GetNext(100); Assert.Empty(batch); } }
public async Task CleanupTestCheckpointed() { (IMessageStore messageStore, ICheckpointStore checkpointStore)result = await this.GetMessageStore(20); ICheckpointStore checkpointStore = result.checkpointStore; using (IMessageStore messageStore = result.messageStore) { for (int i = 0; i < 200; i++) { if (i % 2 == 0) { long offset = await messageStore.Add("module1", this.GetMessage(i)); Assert.Equal(i / 2, offset); } else { long offset = await messageStore.Add("module2", this.GetMessage(i)); Assert.Equal(i / 2, offset); } } IMessageIterator module1Iterator = messageStore.GetMessageIterator("module1"); IEnumerable <IMessage> batch = await module1Iterator.GetNext(100); Assert.Equal(100, batch.Count()); IMessageIterator module2Iterator = messageStore.GetMessageIterator("module2"); batch = await module2Iterator.GetNext(100); Assert.Equal(100, batch.Count()); await checkpointStore.SetCheckpointDataAsync("module1", new CheckpointData(198), CancellationToken.None); await checkpointStore.SetCheckpointDataAsync("module2", new CheckpointData(199), CancellationToken.None); await Task.Delay(TimeSpan.FromSeconds(100)); module2Iterator = messageStore.GetMessageIterator("module2"); batch = await module2Iterator.GetNext(100); Assert.Equal(0, batch.Count()); module1Iterator = messageStore.GetMessageIterator("module1"); batch = await module1Iterator.GetNext(100); Assert.Equal(0, batch.Count()); } }
public async Task CheckpointStoreBasicTest() { ICheckpointStore checkpointStore = CheckpointStore.Create(new StoreProvider(new InMemoryDbStoreProvider())); for (long i = 0; i < 10; i++) { var checkpointData = new CheckpointData(i); await checkpointStore.SetCheckpointDataAsync($"Endpoint{i}", checkpointData, CancellationToken.None); } IDictionary <string, CheckpointData> allCheckpointData = await checkpointStore.GetAllCheckpointDataAsync(CancellationToken.None); Assert.Equal(10, allCheckpointData.Count); long counter = 0; foreach (KeyValuePair <string, CheckpointData> checkpointValue in allCheckpointData) { Assert.Equal(counter, checkpointValue.Value.Offset); Assert.Equal($"Endpoint{counter}", checkpointValue.Key); counter++; } for (long i = 0; i < 10; i++) { CheckpointData checkpointData = await checkpointStore.GetCheckpointDataAsync($"Endpoint{i}", CancellationToken.None); Assert.NotNull(checkpointData); Assert.Equal(i, checkpointData.Offset); } }