コード例 #1
0
        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>();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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>();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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()}");
        }
コード例 #12
0
        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);
        }