public ClusterContext(ICluster cluster, CancellationTokenSource tokenSource, ClusterOptions options) { Cluster = cluster; ClusterOptions = options; _tokenSource = tokenSource; // Register this instance of ClusterContext options.AddSingletonService(this); ServiceProvider = options.BuildServiceProvider(); _configHandler = ServiceProvider.GetRequiredService <ConfigHandler>(); }
public void When_Tracing_Not_Enabled_Default_To_NoopRequestTracer() { var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = false }); var services = options.BuildServiceProvider(); var noopRequestTracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <NoopRequestTracer>(noopRequestTracer); }
public void When_CustomRequestTracer_Registered_Use_It() { var options = new ClusterOptions() { TracingOptions = new TracingOptions { RequestTracer = new CustomRequestTracer() } }; var services = options.BuildServiceProvider(); var tracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <CustomRequestTracer>(tracer); }
public void When_Tracing_Enabled_Custom_To_CustomRequestTracer() { var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, RequestTracer = new CustomRequestTracer() }); var services = options.BuildServiceProvider(); var noopRequestTracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <CustomRequestTracer>(noopRequestTracer); }
public void When_Tracing_Enabled_Default_To_ThresholdRequestTracer() { var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, RequestTracer = new ThresholdRequestTracer(new ThresholdOptions(), new LoggerFactory()) }); var services = options.BuildServiceProvider(); var noopRequestTracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <ThresholdRequestTracer>(noopRequestTracer); }
public ClusterContext(ICluster cluster, CancellationTokenSource tokenSource, ClusterOptions options) { Cluster = cluster; ClusterOptions = options; _tokenSource = tokenSource; // Register this instance of ClusterContext options.AddClusterService(this); ServiceProvider = options.BuildServiceProvider(); _logger = ServiceProvider.GetRequiredService <ILogger <ClusterContext> >(); _redactor = ServiceProvider.GetRequiredService <IRedactor>(); _configHandler = ServiceProvider.GetRequiredService <IConfigHandler>(); _clusterNodeFactory = ServiceProvider.GetRequiredService <IClusterNodeFactory>(); }
public void CircuitBreakerConfiguration_DefaultCircuitBreakerConfiguration_LoadsInServiceProvider() { // Arrange var config = new ClusterOptions(); // Act // noop // Assert var serviceProvider = config.BuildServiceProvider(); var actualCircuitBreakerConfiguration = serviceProvider.GetService <CircuitBreakerConfiguration>(); Assert.Equal(CircuitBreakerConfiguration.Default, actualCircuitBreakerConfiguration); }
public void Logging_NoLoggerProvided_DefaultsToNullLogger() { // Arrange var config = new ClusterOptions(); // Act config.WithLogging(); // Assert var serviceProvider = config.BuildServiceProvider(); var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); Assert.IsAssignableFrom <NullLoggerFactory>(loggerFactory); }
public void When_Tracing_Disabled_Custom_To_CustomTraceListener() { var options = new ClusterOptions { TracingOptions = { Enabled = false } }; options.WithThresholdTracing(new ThresholdOptions { Enabled = false, ThresholdListener = new CustomTraceListener() }).WithOrphanTracing(options => options.Enabled = false); var services = options.BuildServiceProvider(); var noopRequestTracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <NoopRequestTracer>(noopRequestTracer); }
public void Logger_CustomLogger_LoadsInServiceProvider() { // Arrange var config = new ClusterOptions(); var mockLoggerFactory = new Mock <ILoggerFactory>(); // Act config.WithLogging(mockLoggerFactory.Object); // Assert var serviceProvider = config.BuildServiceProvider(); var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); Assert.Equal(mockLoggerFactory.Object, loggerFactory); }
public void When_Tracing_Enabled_Custom_To_CustomTraceListener() { var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, ThresholdListener = new CustomTraceListener() }); var services = options.BuildServiceProvider(); var tracer = services.GetService(typeof(IRequestTracer)) as RequestTracer; var span = tracer.RequestSpan("works"); span.Dispose(); var listener = options.ThresholdOptions.ThresholdListener as CustomTraceListener; var activities = listener.Activities.Where(x => x.OperationName == "works"); var enumerable = activities as Activity[] ?? activities.ToArray(); Assert.True(enumerable.Count() == 1, $"The actual count was {enumerable.Count()}"); }
public void CircuitBreakerConfiguration_CustomCircuitBreakerConfiguration_LoadsInServiceProvider() { // Arrange var config = new ClusterOptions(); var expectedCircuitBreakerConfiguration = new CircuitBreakerConfiguration { Enabled = false }; // Act config.CircuitBreakerConfiguration = expectedCircuitBreakerConfiguration; // Assert var serviceProvider = config.BuildServiceProvider(); var actualCircuitBreakerConfiguration = serviceProvider.GetService <CircuitBreakerConfiguration>(); Assert.Equal(expectedCircuitBreakerConfiguration, actualCircuitBreakerConfiguration); }