From bdc4082c4f2a948689072661648658a97bab537d Mon Sep 17 00:00:00 2001 From: Philip Thomas <86612891+philipthomas-MSFT@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:30:21 -0400 Subject: [PATCH] CFP AVAD: Fixes issue where customers are allowed to use WithStartTime and WithStartFromBeginning with CFP AVAD. (#4619) * checkin with tests * Update Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs Co-authored-by: Kiran Kumar Kolli * Update Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs Co-authored-by: Kiran Kumar Kolli --------- Co-authored-by: Kiran Kumar Kolli --- .../ChangeFeedProcessorBuilder.cs | 10 ++++ ...orBuilderWithAllVersionsAndDeletesTests.cs | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs index 49bfa9d816..3287f1b857 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/ChangeFeedProcessorBuilder.cs @@ -132,6 +132,11 @@ public ChangeFeedProcessorBuilder WithPollInterval(TimeSpan pollInterval) /// The instance of to use. 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; } @@ -149,6 +154,11 @@ internal virtual ChangeFeedProcessorBuilder WithStartFromBeginning() /// The instance of to use. 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)); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/GetChangeFeedProcessorBuilderWithAllVersionsAndDeletesTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/GetChangeFeedProcessorBuilderWithAllVersionsAndDeletesTests.cs index 0479bbb353..ee316a4932 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/GetChangeFeedProcessorBuilderWithAllVersionsAndDeletesTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ChangeFeed/GetChangeFeedProcessorBuilderWithAllVersionsAndDeletesTests.cs @@ -588,5 +588,53 @@ private async Task 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(() => + { + ChangeFeedProcessor processor = monitoredContainer + .GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + processorName: "processor", + onChangesDelegate: (ChangeFeedProcessorContext context, IReadOnlyCollection> 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(() => + { + ChangeFeedProcessor processor = monitoredContainer + .GetChangeFeedProcessorBuilderWithAllVersionsAndDeletes( + processorName: "processor", + onChangesDelegate: (ChangeFeedProcessorContext context, IReadOnlyCollection> 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); + } } }