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

FaultInjection: Adds method to add FaultInjection using CosmosClientBuilder #4867

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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 @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Cosmos.FaultInjection
using System.Collections.Generic;
using Microsoft.Azure.Documents.FaultInjection;

public class FaultInjector
public class FaultInjector : IFaultInjector
{
private readonly ChaosInterceptorFactory chaosInterceptorFactory;

Expand Down Expand Up @@ -48,5 +48,10 @@ internal IChaosInterceptorFactory GetChaosInterceptorFactory()
{
return this.chaosInterceptorFactory;
}

IChaosInterceptorFactory IFaultInjector.GetChaosInterceptorFactory()
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
{
return this.chaosInterceptorFactory;
}
}
}
22 changes: 20 additions & 2 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.Azure.Cosmos
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Azure.Cosmos.FaultInjection;
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
Expand Down Expand Up @@ -72,7 +73,8 @@ public class CosmosClientOptions
private PortReuseMode? portReuseMode;
private IWebProxy webProxy;
private Func<HttpClient> httpClientFactory;
private string applicationName;
private string applicationName;
private IFaultInjector faultInjector;

/// <summary>
/// Creates a new CosmosClientOptions
Expand Down Expand Up @@ -898,6 +900,22 @@ internal Func<X509Certificate2, X509Chain, SslPolicyErrors, bool> GetServerCerti
/// </summary>
public CosmosClientTelemetryOptions CosmosClientTelemetryOptions { get; set; }

/// <summary>
/// Create a client with Fault Injection capabilities.
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public IFaultInjector FaultInjector
{
get => this.faultInjector;
set
{
this.faultInjector = value;
if (this.faultInjector != null)
{
this.ChaosInterceptorFactory = this.faultInjector.GetChaosInterceptorFactory();
}
}
}

internal IChaosInterceptorFactory ChaosInterceptorFactory { get; set; }

internal void SetSerializerIfNotConfigured(CosmosSerializer serializer)
Expand Down
16 changes: 16 additions & 0 deletions Microsoft.Azure.Cosmos/src/FaultInjection/IFaultInjector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.FaultInjection
{
/// <summary>
/// Interface for injecting faults into the Cosmos DB client operations.
/// </summary>
public interface IFaultInjector
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets the chaosInterceptorFactory for client building
/// </summary>
internal IChaosInterceptorFactory GetChaosInterceptorFactory();
}
}
12 changes: 12 additions & 0 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.Azure.Cosmos.Fluent
using global::Azure;
using global::Azure.Core;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.FaultInjection;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;

Expand Down Expand Up @@ -755,6 +756,17 @@ internal CosmosClientBuilder WithFaultInjection(IChaosInterceptorFactory chaosIn
{
this.clientOptions.ChaosInterceptorFactory = chaosInterceptorFactory;
return this;
}

/// <summary>
/// Enables SDK to inject fault. Used for testing applications.
/// </summary>
/// <param name="faultInjector"></param>
/// <returns>>The <see cref="CosmosClientBuilder"/> object</returns>
public CosmosClientBuilder WithFaultInjection(IFaultInjector faultInjector)
{
this.clientOptions.ChaosInterceptorFactory = faultInjector.GetChaosInterceptorFactory();
return this;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void ClientDllNamespaceTest()
{

#if INTERNAL
int expected = 7;
int expected = 8;
#else
int expected = 5;
int expected = 6;
#endif
ContractTests.NamespaceCountTest(typeof(CosmosClient), expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,16 @@
],
"MethodInfo": "Microsoft.Azure.Cosmos.CosmosSerializer Serializer;CanRead:True;CanWrite:True;Microsoft.Azure.Cosmos.CosmosSerializer get_Serializer();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_Serializer(Microsoft.Azure.Cosmos.CosmosSerializer);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector FaultInjector": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector FaultInjector;CanRead:True;CanWrite:True;Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector get_FaultInjector();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_FaultInjector(Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector get_FaultInjector()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector get_FaultInjector();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Collections.Generic.IEnumerable`1[System.Uri] AccountInitializationCustomEndpoints": {
"Type": "Property",
"Attributes": [],
Expand Down Expand Up @@ -3113,6 +3123,11 @@
],
"MethodInfo": "Void set_EnableTcpConnectionEndpointRediscovery(Boolean);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_FaultInjector(Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Void set_FaultInjector(Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_GatewayModeMaxConnectionLimit(Int32)": {
"Type": "Method",
"Attributes": [],
Expand Down Expand Up @@ -4537,6 +4552,11 @@
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector;;IsAbstract:True;IsSealed:False;IsInterface:True;IsEnum:False;IsClass:False;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.FeedIterator;System.Object;IsAbstract:True;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
Expand Down Expand Up @@ -4922,6 +4942,11 @@
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithCustomSerializer(Microsoft.Azure.Cosmos.CosmosSerializer);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithFaultInjection(Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector)": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithFaultInjection(Microsoft.Azure.Cosmos.FaultInjection.IFaultInjector);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder WithHttpClientFactory(System.Func`1[System.Net.Http.HttpClient])": {
"Type": "Method",
"Attributes": [],
Expand Down
Loading