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

[Do not merge] QuroumReader: Fixes issue + adds test #4596

Closed
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 @@ -26,7 +26,6 @@
</ItemGroup>

<ItemGroup Condition=" '$(ProjectRef)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos.Direct" Version="[$(DirectVersion)]" PrivateAssets="All" />
<PackageReference Include="Microsoft.HybridRow" Version="[$(HybridRowVersion)]" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
</PropertyGroup>

<ItemGroup Condition=" '$(ProjectRef)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos.Direct" Version="[$(DirectVersion)]" PrivateAssets="All" />
<PackageReference Include="Microsoft.HybridRow" Version="[$(HybridRowVersion)]" PrivateAssets="All" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/RMResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Microsoft.Azure.Cosmos/src/direct/QuorumReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,14 @@ private bool IsQuorumMet(
selectedResponse = validReadResponses.Where(s => (s.Target.LSN == maxLsn) && (s.Target.StatusCode < StatusCodes.StartingErrorCode)).FirstOrDefault();
if (selectedResponse == null)
{
selectedResponse = validReadResponses.First(s => s.Target.LSN == maxLsn);
try
{
selectedResponse = validReadResponses.First(s => s.Target.LSN == maxLsn);
}
catch
{
selectedResponse = validReadResponses.First();
}
}

readLsn = selectedResponse.Target.ItemLSN == -1 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.FaultInjection;

[TestClass]
public class CosmosItemTests : BaseCosmosClientHelper
Expand Down Expand Up @@ -3320,6 +3321,79 @@ await CosmosItemTests.GivenItemAsyncWhenMissingMemberHandlingIsErrorThenExpectsC
cancellationToken: cancellationToken));
}

[TestMethod]
public async Task TooManyReadTest()
{
string connectionString = ConfigurationManager.GetEnvironmentVariable<string>("COSMOSDB_MULTI_REGION", null);

if (string.IsNullOrEmpty(connectionString))
{
Assert.Fail("Set environment variable COSMOSDB_MULTI_REGION to run the tests");
}

FaultInjectionCondition readConditon = new FaultInjectionConditionBuilder()
.WithOperationType(FaultInjectionOperationType.ReadItem)
.Build();
IFaultInjectionResult tooManyRequestsResult = FaultInjectionResultBuilder
.GetResultBuilder(FaultInjectionServerErrorType.TooManyRequests)
.Build();
FaultInjectionRule rule = new FaultInjectionRuleBuilder(
id: "tooMany",
condition: readConditon,
result: tooManyRequestsResult)
.WithDuration(TimeSpan.FromMinutes(90))
.Build();

List<FaultInjectionRule> rules = new List<FaultInjectionRule>() { rule };
FaultInjector faultInjector = new FaultInjector(rules);

rule.Disable();


CosmosClientOptions clientOptions = new CosmosClientOptions()
{
ConnectionMode = ConnectionMode.Direct,
ConsistencyLevel = Cosmos.ConsistencyLevel.Strong,
};

CosmosClient faultInjectionClient = new CosmosClient(
connectionString: connectionString,
clientOptions: faultInjector.GetFaultInjectionClientOptions(clientOptions));

Cosmos.Database db = await faultInjectionClient.CreateDatabaseIfNotExistsAsync("LoadTest");
Container container = await db.CreateContainerIfNotExistsAsync("LoadContainer", "/pk");

dynamic item = new
{
id = "testId",
pk = "pk",
};

await container.CreateItemAsync<dynamic>(item);

rule.Enable();

try
{
ItemResponse<dynamic> ir = await container.ReadItemAsync<dynamic>(
"testId",
new Cosmos.PartitionKey("pk"),
new ItemRequestOptions()
{
ExcludeRegions = new List<string>() { "West US" }
});


Assert.AreEqual(HttpStatusCode.OK, ir.StatusCode);
}
finally
{
await db.DeleteAsync();
faultInjectionClient.Dispose();
}

}

private static async Task GivenItemStreamAsyncWhenMissingMemberHandlingIsErrorThenExpectsCosmosExceptionTestAsync(
Func<Container, string, string, CancellationToken, Task<ResponseMessage>> itemStreamAsync)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</ItemGroup>

<ItemGroup Condition=" '$(ProjectRef)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos.Direct" Version="[$(DirectVersion)]" PrivateAssets="All" />
<PackageReference Include="Microsoft.HybridRow" Version="[$(HybridRowVersion)]" PrivateAssets="All" />
</ItemGroup>

Expand Down Expand Up @@ -361,6 +360,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Microsoft.Azure.Cosmos.Samples\Tools\FaultInjection\src\FaultInjection.csproj" />
</ItemGroup>

<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down
Loading