Skip to content

Commit

Permalink
Test ChangeFeed: Adding a Unit Test For ChangeFeed Response Headers
Browse files Browse the repository at this point in the history
- This test validates the changes made in the following PR: #2218
- Adding this test in place so that the contract does not regress.
  • Loading branch information
vivekr20 committed Feb 22, 2021
1 parent 6a82cd5 commit d699981
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Microsoft.Azure.Cosmos.Tests.Pagination
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.ChangeFeed.Pagination;
using Microsoft.Azure.Cosmos.CosmosElements;
Expand All @@ -21,6 +24,8 @@ namespace Microsoft.Azure.Cosmos.Tests.Pagination
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.Pagination;
using Microsoft.Azure.Cosmos.Query.Core.QueryClient;
using Moq;

[TestClass]
public abstract class DocumentContainerTests
Expand Down Expand Up @@ -723,6 +728,60 @@ public async Task TestQueryAsync()
}
}

[TestMethod]
public async Task ValidateExceptionForMonadicChangeFeedAsync()
{
Mock<CosmosDiagnosticsContext> mockDiagnosticsContext = new Mock<CosmosDiagnosticsContext>();
CosmosException dummyException = new CosmosException(
message: "dummy",
statusCode: HttpStatusCode.TooManyRequests,
subStatusCode: 3200,
activityId: "fakeId",
requestCharge: 1.0);
ResponseMessage message = new ResponseMessage(
statusCode: HttpStatusCode.TooManyRequests,
requestMessage: null,
headers: null,
cosmosException: dummyException,
diagnostics: mockDiagnosticsContext.Object);

Mock<CosmosClientContext> mockCosmosClientContext = new Mock<CosmosClientContext>();
mockCosmosClientContext.Setup(
context => context.ProcessResourceOperationStreamAsync(
It.IsAny<string>(),
It.IsAny<ResourceType>(),
It.IsAny<OperationType>(),
It.IsAny<RequestOptions>(),
It.IsAny<ContainerInternal>(),
It.IsAny<Microsoft.Azure.Cosmos.FeedRange>(),
It.IsAny<Stream>(),
It.IsAny<Action<RequestMessage>>(),
It.IsAny<CosmosDiagnosticsContext>(),
It.IsAny<ITrace>(),
It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(message));
Mock<ContainerInternal> mockContainerInternal = new Mock<ContainerInternal>();
mockContainerInternal.SetupGet(container => container.ClientContext).Returns(mockCosmosClientContext.Object);
Mock<CosmosQueryClient> mockCosmosQueryClient = new Mock<CosmosQueryClient>();
NetworkAttachedDocumentContainer container = new NetworkAttachedDocumentContainer(
mockContainerInternal.Object,
mockCosmosQueryClient.Object,
mockDiagnosticsContext.Object);

FeedRangeState<ChangeFeedState> state = new FeedRangeState<ChangeFeedState>();
ChangeFeedPaginationOptions options = new ChangeFeedPaginationOptions(ChangeFeedMode.Incremental);
TryCatch<ChangeFeedPage> result = await container.MonadicChangeFeedAsync(
state,
options,
NoOpTrace.Singleton,
CancellationToken.None);

Assert.IsNotNull(result.Exception);
CosmosException ex = result.Exception.InnerException as CosmosException;
Assert.IsNotNull(ex);
Assert.AreSame(dummyException, ex);
}

private readonly struct DrainFunctions<TState>
where TState : State
{
Expand Down

0 comments on commit d699981

Please sign in to comment.