Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Preview] ChangeFeedProcessor: Adds support for manual checkpoint, context, and stream #2331

Merged
merged 16 commits into from
Apr 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
exception test
  • Loading branch information
ealsur committed Mar 23, 2021
commit 4748d385d45971c3f3786f0d7ad652fa5c54195d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests.ChangeFeed
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -63,6 +64,57 @@ public async Task WritesTriggerDelegate_WithLeaseContainer()
CollectionAssert.AreEqual(expectedIds.ToList(), receivedIds);
}

[TestMethod]
public async Task ExceptionsRetryBatch()
{
ManualResetEvent allDocsProcessed = new ManualResetEvent(false);

bool thrown = false;
IEnumerable<int> expectedIds = Enumerable.Range(0, 3);
List<int> receivedIds = new List<int>();
ChangeFeedProcessor processor = this.Container
.GetChangeFeedProcessorBuilder("test", (IReadOnlyCollection<TestClass> docs, CancellationToken token) =>
{
if (receivedIds.Count == 1
&& !thrown)
{
thrown = true;
throw new Exception("Retry batch");
}

foreach (TestClass doc in docs)
{
receivedIds.Add(int.Parse(doc.id));
}

if (receivedIds.Count == 3)
{
allDocsProcessed.Set();
}

return Task.CompletedTask;
})
.WithInstanceName("random")
.WithMaxItems(1)
.WithLeaseContainer(this.LeaseContainer).Build();

await processor.StartAsync();
// Letting processor initialize
await Task.Delay(BaseChangeFeedClientHelper.ChangeFeedSetupTime);
// Inserting documents
foreach (int id in expectedIds)
{
await this.Container.CreateItemAsync<dynamic>(new { id = id.ToString() });
}

// Waiting on all notifications to finish
bool isStartOk = allDocsProcessed.WaitOne(30 * BaseChangeFeedClientHelper.ChangeFeedSetupTime);
await processor.StopAsync();
Assert.IsTrue(isStartOk, "Timed out waiting for docs to process");
// Verify that we maintain order
CollectionAssert.AreEqual(expectedIds.ToList(), receivedIds);
}

[TestMethod]
public async Task Schema_DefaultsToNoPartitionId()
{
Expand Down