Skip to content

Commit

Permalink
CFP AVAD: Fixes issue where customers are allowed to use WithStartTim…
Browse files Browse the repository at this point in the history
…e and WithStartFromBeginning with CFP AVAD. (#4619)

* checkin with tests

* Update Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>

* Update Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>

---------

Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
  • Loading branch information
philipthomas-MSFT and kirankumarkolli authored Aug 2, 2024
1 parent aba2b2c commit bdc4082
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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)
{
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);
}
}
}

0 comments on commit bdc4082

Please sign in to comment.