Skip to content

Commit

Permalink
Changed to Async Method (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
NaluTripician authored Jan 26, 2024
1 parent 7209b38 commit 0633389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ internal partial class DocumentClient : IDisposable, IAuthorizationTokenProvider
private readonly bool IsLocalQuorumConsistency = false;
private readonly bool isReplicaAddressValidationEnabled;

private readonly IChaosInterceptor chaosInterceptor;
//Fault Injection
private readonly IChaosInterceptorFactory chaosInterceptorFactory;
private IChaosInterceptor chaosInterceptor;

//Auth
internal readonly AuthorizationTokenProvider cosmosAuthorization;
Expand Down Expand Up @@ -487,7 +489,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.chaosInterceptorFactory = chaosInterceptorFactory;

this.Initialize(
serviceEndpoint: serviceEndpoint,
Expand Down Expand Up @@ -1015,6 +1017,14 @@ internal virtual void Initialize(Uri serviceEndpoint,
// Always called from under the lock except when called from Intilialize method during construction.
private async Task<bool> GetInitializationTaskAsync(IStoreClientFactory storeClientFactory)
{
//Create the chaos interceptor if using fault injection
//Creating the chaos interceptor requires async calls, so we do it here instead of in the constructor
//This must also be done before creating the storeClientFactory for direct mode
if (this.chaosInterceptorFactory != null)
{
this.chaosInterceptor = await this.chaosInterceptorFactory.CreateInterceptorAsync(this);
}

await this.InitializeGatewayConfigurationReaderAsync();

if (this.desiredConsistencyLevel.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos
{
using System.Threading.Tasks;
using Microsoft.Azure.Documents.FaultInjection;

/// <summary>
Expand All @@ -15,6 +16,6 @@ internal interface IChaosInterceptorFactory
/// Creates the IChaosInterceptor interceptor that will be used to inject fault injection rules.
/// </summary>
/// <param name="documentClient"></param>
public IChaosInterceptor CreateInterceptor(DocumentClient documentClient);
public Task<IChaosInterceptor> CreateInterceptorAsync(DocumentClient documentClient);
}
}

0 comments on commit 0633389

Please sign in to comment.