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

CFP AVAD: Fixes issue where customers are allowed to use WithStartTime and WithStartFromBeginning with CFP AVAD. #4619

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public ChangeFeedProcessorBuilder WithPollInterval(TimeSpan pollInterval)
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
internal virtual ChangeFeedProcessorBuilder WithStartFromBeginning()
{
if (this.changeFeedProcessorOptions.Mode == ChangeFeedMode.AllVersionsAndDeletes)
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
{
throw new InvalidOperationException($"Using the '{nameof(WithStartFromBeginning)}' option with ChangeFeedProcessor is not supported with {ChangeFeedMode.AllVersionsAndDeletes} mode.");
}

this.changeFeedProcessorOptions.StartFromBeginning = true;
return this;
}
Expand All @@ -149,6 +154,11 @@ internal virtual ChangeFeedProcessorBuilder WithStartFromBeginning()
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
public ChangeFeedProcessorBuilder WithStartTime(DateTime startTime)
{
if (this.changeFeedProcessorOptions.Mode == ChangeFeedMode.AllVersionsAndDeletes)
{
throw new InvalidOperationException($"Using the '{nameof(WithStartTime)}' option with ChangeFeedProcessor is not supported with {ChangeFeedMode.AllVersionsAndDeletes} mode.");
}

if (startTime == null)
{
throw new ArgumentNullException(nameof(startTime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,5 +588,53 @@ private async Task<ContainerInternal> CreateMonitoredContainer(ChangeFeedMode ch

return (ContainerInternal)response;
}

[TestMethod]
[Owner("philipthomas-MSFT")]
[Description("Scenario: WithStartTime should throw an exception when used in AVAD mode.")]
public async Task WhenACFPInAVADModeUsesWithStartTimeExpectExceptionTestsAsync()
{
ContainerInternal monitoredContainer = await this.CreateMonitoredContainer(ChangeFeedMode.AllVersionsAndDeletes);

InvalidOperationException exception = Assert.ThrowsException<InvalidOperationException>(() =>
{
ChangeFeedProcessor processor = monitoredContainer
.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes(
processorName: "processor",
onChangesDelegate: (ChangeFeedProcessorContext context, IReadOnlyCollection<ChangeFeedItem<dynamic>> docs, CancellationToken cancellationToken) => Task.CompletedTask)
.WithStartTime(DateTime.Now)
.WithInstanceName(Guid.NewGuid().ToString())
.WithLeaseContainer(this.LeaseContainer)
.Build();
});

Assert.AreEqual(
expected: "Using the 'WithStartTime' option with ChangeFeedProcessor is not supported with Microsoft.Azure.Cosmos.ChangeFeed.ChangeFeedModeFullFidelity mode.",
actual: exception.Message);
}

[TestMethod]
[Owner("philipthomas-MSFT")]
[Description("Scenario: WithStartFromBeginning should throw an exception when used in AVAD mode.")]
public async Task WhenACFPInAVADModeUsesWithStartFromBeginningExpectExceptionTestsAsync()
{
ContainerInternal monitoredContainer = await this.CreateMonitoredContainer(ChangeFeedMode.AllVersionsAndDeletes);

InvalidOperationException exception = Assert.ThrowsException<InvalidOperationException>(() =>
{
ChangeFeedProcessor processor = monitoredContainer
.GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes(
processorName: "processor",
onChangesDelegate: (ChangeFeedProcessorContext context, IReadOnlyCollection<ChangeFeedItem<dynamic>> docs, CancellationToken cancellationToken) => Task.CompletedTask)
.WithStartFromBeginning()
.WithInstanceName(Guid.NewGuid().ToString())
.WithLeaseContainer(this.LeaseContainer)
.Build();
});

Assert.AreEqual(
expected: "Using the 'WithStartFromBeginning' option with ChangeFeedProcessor is not supported with Microsoft.Azure.Cosmos.ChangeFeed.ChangeFeedModeFullFidelity mode.",
actual: exception.Message);
}
}
}
Loading