Skip to content

Commit d46fb4e

Browse files
committed
fix: adding unit test
1 parent 0060ade commit d46fb4e

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/RetryHandlerTests.cs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,30 @@ public class RetryHandlerTests
2424
{
2525
private static readonly Uri TestUri = new Uri("https://dummy.documents.azure.com:443/dbs");
2626
[TestMethod]
27-
public async Task ValidatePassingOverlappingRangesInQueryPlanDoesntThrowAnException()
27+
public async Task ValidateQueryPlanDoesNotThrowExceptionForOverlappingRanges()
28+
{
29+
await this.ValidateOverlappingRangesBehaviorAsync(
30+
operationType: OperationType.QueryPlan,
31+
shouldThrowGoneException: false);
32+
}
33+
34+
[TestMethod]
35+
public async Task ValidateQueryThrowsGoneExceptionForOverlappingRanges()
36+
{
37+
await this.ValidateOverlappingRangesBehaviorAsync(
38+
operationType: OperationType.Query,
39+
shouldThrowGoneException: true);
40+
}
41+
42+
private async Task ValidateOverlappingRangesBehaviorAsync(
43+
OperationType operationType,
44+
bool shouldThrowGoneException)
2845
{
2946
// Create overlapping ranges for the test
3047
List<PartitionKeyRange> overlappingRanges = new List<PartitionKeyRange>
3148
{
32-
new PartitionKeyRange { Id = "0", MinInclusive = "0D4DC2CD8F49C65A8E0C5306B61B4343", MaxExclusive = "0DCEB8CE51C6BFE84F4BD9409F69B9BB2164DEBD78C50C850E0C1E3E3F0579ED" },
33-
new PartitionKeyRange { Id = "1", MinInclusive = "0DCEB8CE51C6BFE84F4BD9409F69B9BB2164DEBD78C50C850E0C1E3E3F0579ED", MaxExclusive = "1080F600C27CF98DC13F8639E94E7676" }
49+
new PartitionKeyRange { Id = "0", MinInclusive = "0D4DC2CD8F49C65A8E0C5306B61B4343", MaxExclusive = "0DCEB8CE51C6BFE84F4BD9409F69B9BB2164DEBD78C50C850E0C1E3E3F0579ED" },
50+
new PartitionKeyRange { Id = "1", MinInclusive = "0DCEB8CE51C6BFE84F4BD9409F69B9BB2164DEBD78C50C850E0C1E3E3F0579ED", MaxExclusive = "1080F600C27CF98DC13F8639E94E7676" }
3451
};
3552

3653
// Create a custom document client with our TestPartitionKeyRangeCache
@@ -65,8 +82,8 @@ public async Task ValidatePassingOverlappingRangesInQueryPlanDoesntThrowAnExcept
6582

6683
// FeedRangeEpk for the test - use a range that overlaps both partition key ranges
6784
FeedRangeEpk feedRange = new FeedRangeEpk(new Documents.Routing.Range<string>(
68-
"0DCEB8CE51C6BFE84F4BD9409F69B9BB", // Start just before the boundary
69-
"0DCEB8CE51C6BFE84F4BD9409F69B9BB2164DEBD78C50C850E0C1E3E3F0579EE", // End just after the boundary
85+
"0DCEB8CE51C6BFE84F4BD9409F69B9BB",
86+
"0DCEB8CE51C6BFE84F4BD9409F69B9BBFF",
7087
true, false));
7188

7289
RequestInvokerHandler invoker = new RequestInvokerHandler(client, null, null, null)
@@ -78,7 +95,7 @@ public async Task ValidatePassingOverlappingRangesInQueryPlanDoesntThrowAnExcept
7895
ResponseMessage response = await invoker.SendAsync(
7996
"dbs/testDb/colls/testColl",
8097
ResourceType.Document,
81-
OperationType.QueryPlan,
98+
operationType,
8299
null,
83100
containerMock.Object,
84101
feedRange,
@@ -87,9 +104,19 @@ public async Task ValidatePassingOverlappingRangesInQueryPlanDoesntThrowAnExcept
87104
NoOpTrace.Singleton,
88105
CancellationToken.None);
89106

90-
//Assert
107+
// Assert
91108
Assert.IsNotNull(response, "Response should not be null.");
92-
Assert.IsTrue(response.IsSuccessStatusCode, $"Expected a successful status code, but got {response.StatusCode}.");
109+
110+
if (shouldThrowGoneException)
111+
{
112+
Assert.IsFalse(response.IsSuccessStatusCode, "Expected a failure status code for Query operation.");
113+
Assert.AreEqual(HttpStatusCode.Gone, response.StatusCode, "Expected a 410 Gone status code.");
114+
Assert.AreEqual((int)SubStatusCodes.PartitionKeyRangeGone, (int)response.Headers.SubStatusCode, "Expected PartitionKeyRangeGone sub-status code.");
115+
}
116+
else
117+
{
118+
Assert.IsTrue(response.IsSuccessStatusCode, $"Expected a successful status code, but got {response.StatusCode}.");
119+
}
93120
}
94121

95122
// Custom MockDocumentClient that allows injecting our TestPartitionKeyRangeCache

0 commit comments

Comments
 (0)