Skip to content

Commit

Permalink
Merge branch 'users/akotalwar/TurnOnODEByDefault' of https://github.c…
Browse files Browse the repository at this point in the history
…om/Azure/azure-cosmos-dotnet-v3 into users/akotalwar/TurnOnODEByDefault
  • Loading branch information
akotalwar committed Jan 19, 2024
2 parents 0918378 + 5af47e4 commit 021cad9
Show file tree
Hide file tree
Showing 63 changed files with 14,724 additions and 537 deletions.
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyKeys.MoqPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.FaultInjection" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.FaultInjection" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.FaultInjection.Tests" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.FaultInjection.Tests" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Friends" + AssemblyKeys.ProductPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Friends" + AssemblyKeys.TestPublicKey)]
[assembly: InternalsVisibleTo("Microsoft.Azure.Cosmos.Extensions" + AssemblyKeys.ProductPublicKey)]
Expand Down
6 changes: 4 additions & 2 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Azure.Cosmos
using System.Security.Cryptography.X509Certificates;
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Client;
using Newtonsoft.Json;

/// <summary>
Expand Down Expand Up @@ -732,7 +732,9 @@ internal Protocol ConnectionProtocol
/// <summary>
/// Gets or sets Client Telemetry Options like feature flags and corresponding options
/// </summary>
public CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; }
public CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; }

internal IChaosInterceptorFactory ChaosInterceptorFactory { get; set; }

internal void SetSerializerIfNotConfigured(CosmosSerializer serializer)
{
Expand Down
12 changes: 9 additions & 3 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Microsoft.Azure.Cosmos
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Common;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Handler;
using Microsoft.Azure.Cosmos.Query;
using Microsoft.Azure.Cosmos.Query.Core.QueryPlan;
using Microsoft.Azure.Cosmos.Routing;
Expand All @@ -30,6 +29,7 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Collections;
using Microsoft.Azure.Documents.FaultInjection;
using Microsoft.Azure.Documents.Routing;
using Newtonsoft.Json;

Expand Down Expand Up @@ -115,6 +115,8 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
private readonly bool IsLocalQuorumConsistency = false;
private readonly bool isReplicaAddressValidationEnabled;

private readonly IChaosInterceptor chaosInterceptor;

//Auth
internal readonly AuthorizationTokenProvider cosmosAuthorization;

Expand Down Expand Up @@ -433,6 +435,7 @@ internal DocumentClient(Uri serviceEndpoint,
/// <param name="cosmosClientId"></param>
/// <param name="remoteCertificateValidationCallback">This delegate responsible for validating the third party certificate. </param>
/// <param name="cosmosClientTelemetryOptions">This is distributed tracing flag</param>
/// <param name="chaosInterceptorFactory">This is the chaos interceptor used for fault injection</param>
/// <remarks>
/// The service endpoint can be obtained from the Azure Management Portal.
/// If you are connecting using one of the Master Keys, these can be obtained along with the endpoint from the Azure Management Portal
Expand Down Expand Up @@ -460,7 +463,8 @@ internal DocumentClient(Uri serviceEndpoint,
bool isLocalQuorumConsistency = false,
string cosmosClientId = null,
RemoteCertificateValidationCallback remoteCertificateValidationCallback = null,
CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null)
CosmosClientTelemetryOptions cosmosClientTelemetryOptions = null,
IChaosInterceptorFactory chaosInterceptorFactory = null)
{
if (sendingRequestEventArgs != null)
{
Expand All @@ -483,6 +487,7 @@ internal DocumentClient(Uri serviceEndpoint,
this.transportClientHandlerFactory = transportClientHandlerFactory;
this.IsLocalQuorumConsistency = isLocalQuorumConsistency;
this.initTaskCache = new AsyncCacheNonBlocking<string, bool>(cancellationToken: this.cancellationTokenSource.Token);
this.chaosInterceptor = chaosInterceptorFactory?.CreateInterceptor(this);

this.Initialize(
serviceEndpoint: serviceEndpoint,
Expand Down Expand Up @@ -6666,7 +6671,8 @@ private void InitializeDirectConnectivity(IStoreClientFactory storeClientFactory
addressResolver: this.AddressResolver,
rntbdMaxConcurrentOpeningConnectionCount: this.rntbdMaxConcurrentOpeningConnectionCount,
remoteCertificateValidationCallback: this.remoteCertificateValidationCallback,
distributedTracingOptions: distributedTracingOptions);
distributedTracingOptions: distributedTracingOptions,
chaosInterceptor: this.chaosInterceptor);

if (this.transportClientHandlerFactory != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using Microsoft.Azure.Documents.FaultInjection;

/// <summary>
/// This interface is used by the fault injection library to create an instance of IChaosInterceptor
/// This allows the fault injection library to intercept requests and inject faults in the request process
/// </summary>
internal interface IChaosInterceptorFactory
{
/// <summary>
/// Creates the IChaosInterceptor interceptor that will be used to inject fault injection rules.
/// </summary>
/// <param name="documentClient"></param>
public IChaosInterceptor CreateInterceptor(DocumentClient documentClient);
}
}
10 changes: 10 additions & 0 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ internal CosmosClientBuilder WithPartitionLevelFailoverEnabled()
return this;
}

/// <summary>
/// Enables SDK to inject fault. Used for testing applications.
/// </summary>
/// <param name="chaosInterceptorFactory"></param>
internal CosmosClientBuilder WithFaultInjection(IChaosInterceptorFactory chaosInterceptorFactory)
{
this.clientOptions.ChaosInterceptorFactory = chaosInterceptorFactory;
return this;
}

/// <summary>
/// To enable LocalQuorum Consistency, i.e. Allows Quorum read with Eventual Consistency Account or with Consistent Prefix Account.
/// Use By Compute Only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ private static class Constants
public const string Aggregate = "Aggregate";
public const string Aggregates = "Aggregates";
public const string Builtin = "Builtin";
public const string Cql = "Cql";
public const string ClientQL = "clientQL";
public const string ConditionExpression = "ConditionExpression";
public const string ClientDistributionPlan = "clientDistributionPlan";
public const string DeclaredVariable = "DeclaredVariable";
public const string DeclaredVariableExpression = "DeclaredVariableExpression";
public const string Distinct = "Distinct";
public const string EnumerationKind = "EnumerationKind";
public const string Expression = "Expression";
public const string Expressions = "Expressions";
public const string FunctionKind = "FunctionKind";
public const string GroupBy = "GroupBy";
public const string Identifier = "Identifier";
Expand Down Expand Up @@ -69,7 +70,7 @@ public static ClientDistributionPlan DeserializeClientDistributionPlan(string js
{
CosmosObject cosmosObject = CosmosObject.Parse(jsonString);
CosmosObject clientDistributionPlanElement = GetValue<CosmosObject>(cosmosObject, Constants.ClientDistributionPlan);
CosmosObject cqlElement = GetValue<CosmosObject>(clientDistributionPlanElement, Constants.Cql);
CosmosObject cqlElement = GetValue<CosmosObject>(clientDistributionPlanElement, Constants.ClientQL);
CqlEnumerableExpression expression = DeserializeCqlEnumerableExpression(cqlElement);

return new ClientDistributionPlan(expression);
Expand Down Expand Up @@ -118,7 +119,7 @@ private static CqlDistinctEnumerableExpression DeserializeDistinctEnumerableExpr
{
CqlEnumerableExpression sourceExpression = DeserializeCqlEnumerableExpression(GetValue<CosmosObject>(cosmosObject, Constants.SourceExpression));
CqlVariable declaredVariable = DeserializeCqlVariable(GetValue<CosmosObject>(cosmosObject, Constants.DeclaredVariable));
IReadOnlyList<CqlScalarExpression> expressions = DeserializeScalarExpressionArray(GetValue<CosmosArray>(cosmosObject, Constants.Expression));
IReadOnlyList<CqlScalarExpression> expressions = DeserializeScalarExpressionArray(GetValue<CosmosArray>(cosmosObject, Constants.Expressions));
return new CqlDistinctEnumerableExpression(sourceExpression, declaredVariable, expressions);
}

Expand Down Expand Up @@ -318,8 +319,9 @@ private static CqlUnaryScalarExpression DeserializeUnaryScalarExpression(CosmosO

private static CqlUserDefinedFunctionCallScalarExpression DeserializeUserDefinedFunctionCallScalarExpression(CosmosObject cosmosObject)
{
string identifierString = GetValue<CosmosString>(cosmosObject, Constants.Identifier).Value;
CqlFunctionIdentifier functionIdentifier = new CqlFunctionIdentifier(identifierString);
CosmosObject identifier = GetValue<CosmosObject>(cosmosObject, Constants.Identifier);
string nameString = GetValue<CosmosString>(identifier, Constants.Name).Value;
CqlFunctionIdentifier functionIdentifier = new CqlFunctionIdentifier(nameString);
IReadOnlyList<CqlScalarExpression> arguments = DeserializeScalarExpressionArray(GetValue<CosmosArray>(cosmosObject, Constants.Arguments));
bool builtin = GetValue<CosmosBoolean>(cosmosObject, Constants.Builtin).Value;
return new CqlUserDefinedFunctionCallScalarExpression(functionIdentifier, arguments, builtin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ protected CqlAggregate(CqlAggregateKind kind)
}

public CqlAggregateKind Kind { get; }

public abstract void Accept(ICqlVisitor cqlVisitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ internal class CqlAggregateEnumerableExpression : CqlEnumerableExpression
{
public CqlAggregateEnumerableExpression(CqlEnumerableExpression sourceExpression, CqlAggregate aggregate)
: base(CqlEnumerableExpressionKind.Aggregate)
{
{
this.SourceExpression = sourceExpression ?? throw new ArgumentNullException(nameof(sourceExpression));
this.Aggregate = aggregate ?? throw new ArgumentNullException(nameof(aggregate));
}

public CqlEnumerableExpression SourceExpression { get; }

public CqlAggregate Aggregate { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public CqlArrayCreateScalarExpression(IReadOnlyList<CqlScalarExpression> items)
public string ArrayKind { get; }

public IReadOnlyList<CqlScalarExpression> Items { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public CqlArrayIndexerScalarExpression(CqlScalarExpression expression, ulong ind
public CqlScalarExpression Expression { get; }

public ulong Index { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public CqlArrayLiteral(IReadOnlyList<CqlLiteral> items)
}

public IReadOnlyList<CqlLiteral> Items { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public CqlBinaryScalarExpression(CqlBinaryScalarOperatorKind operatorKind, CqlSc
public CqlScalarExpression LeftExpression { get; }

public CqlScalarExpression RightExpression { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public CqlBooleanLiteral(bool value)
}

public bool Value { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public CqlBuiltinAggregate(CqlAggregateOperatorKind operatorKind)
}

public CqlAggregateOperatorKind OperatorKind { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public CqlDistinctEnumerableExpression(CqlEnumerableExpression sourceExpression,
public CqlVariable DeclaredVariable { get; }

public IReadOnlyList<CqlScalarExpression> Expression { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ protected CqlEnumerableExpression(CqlEnumerableExpressionKind kind)
}

public CqlEnumerableExpressionKind Kind { get; }

public abstract void Accept(ICqlVisitor cqlVisitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public CqlGroupByEnumerableExpression(CqlEnumerableExpression sourceExpression,
public ulong KeyCount { get; }

public IReadOnlyList<CqlAggregate> Aggregates { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public CqlInputEnumerableExpression(string name)
}

public string Name { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public CqlIsOperatorScalarExpression(CqlIsOperatorKind operatorKind, CqlScalarEx
public CqlIsOperatorKind OperatorKind { get; }

public CqlScalarExpression Expression { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public CqlLetScalarExpression(CqlVariable declaredVariable, CqlScalarExpression
public CqlScalarExpression DeclaredVariableExpression { get; }

public CqlScalarExpression Expression { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ protected CqlLiteral(CqlLiteralKind kind)
}

public CqlLiteralKind Kind { get; }

public abstract void Accept(ICqlVisitor cqlVisitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public CqlLiteralScalarExpression(CqlLiteral literal)
}

public CqlLiteral Literal { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public CqlMuxScalarExpression(CqlScalarExpression conditionExpression, CqlScalar
public CqlScalarExpression LeftExpression { get; }

public CqlScalarExpression RightExpression { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ private CqlNullLiteral()
: base(CqlLiteralKind.Null)
{
}

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public CqlNumberLiteral(Number64 value)
}

public Number64 Value { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public CqlObjectCreateScalarExpression(IReadOnlyList<CqlObjectProperty> properti
public IReadOnlyList<CqlObjectProperty> Properties { get; }

public string ObjectKind { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public CqlObjectLiteral(IReadOnlyList<CqlObjectLiteralProperty> properties)
}

public IReadOnlyList<CqlObjectLiteralProperty> Properties { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public CqlOrderByEnumerableExpression(CqlEnumerableExpression sourceExpression,
public CqlVariable DeclaredVariable { get; }

public IReadOnlyList<CqlOrderByItem> Items { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public CqlPropertyRefScalarExpression(CqlScalarExpression expression, string pro
public CqlScalarExpression Expression { get; }

public string PropertyName { get; }

public override void Accept(ICqlVisitor cqlVisitor) => cqlVisitor.Visit(this);
}
}
Loading

0 comments on commit 021cad9

Please sign in to comment.