public async Task Costs_1_Thread_When_Fuction_Has_Timed_Out_But_Isnt_Finished()
            {
                var commandIdentifier        = new HystrixCommandIdentifier("group", "key");
                var configurationServiceMock = new Mock <IHystrixConfigurationService>();
                var timeoutWrapper           = new HystrixTimeoutWrapper(commandIdentifier, configurationServiceMock.Object);
                var primaryTask = new Func <Task <string> >(() => Task.Run(async() =>
                {
                    Thread.Sleep(2000);
                    await Task.Delay(10);
                    return("a value");
                }));


                configurationServiceMock.Setup(service => service.GetCommandTimeoutInMilliseconds()).Returns(1000);

                int availableThreadsBefore = GetAvailableThreads();

                // act
                await Assert.ThrowsAsync <HystrixTimeoutException>(() => timeoutWrapper.ExecuteAsync(primaryTask));

                int availableThreadsAfter = GetAvailableThreads();

                Assert.Equal(1, availableThreadsBefore - availableThreadsAfter);

                await Task.Delay(2000);

                availableThreadsAfter = GetAvailableThreads();

                Assert.Equal(0, availableThreadsBefore - availableThreadsAfter);
            }
            public void Costs_1_Thread_When_Executing_Within_Timeout()
            {
                var commandIdentifier        = new HystrixCommandIdentifier("group", "key");
                var configurationServiceMock = new Mock <IHystrixConfigurationService>();
                var timeoutWrapper           = new HystrixTimeoutWrapper(commandIdentifier, configurationServiceMock.Object);
                var primaryFunctionMock      = new Mock <Func <string> >();

                primaryFunctionMock.Setup(func => func()).Returns(() =>
                {
                    Thread.Sleep(1000);
                    return("a value");
                });

                configurationServiceMock.Setup(service => service.GetCommandTimeoutInMilliseconds()).Returns(2000);

                int availableThreadsBefore = GetAvailableThreads();

                // act
                Task <string> task = Task.Run(() => timeoutWrapper.Execute(primaryFunctionMock.Object));
                int           availableThreadsDuring = GetAvailableThreads();

                task.Wait();

                Assert.Equal(1, availableThreadsBefore - availableThreadsDuring);
            }
            public void Throws_ArgumentNullException_When_ConfigurationService_Is_Null()
            {
                var commandIdentifier = new HystrixCommandIdentifier("group", "key");

                // act
                Assert.Throws <ArgumentNullException>(() => new HystrixTimeoutWrapper(commandIdentifier, null));
            }
            public async Task Costs_0_Threads_When_Fuction_Has_Timed_Out_And_CancellationToken_Is_Used()
            {
                var commandIdentifier        = new HystrixCommandIdentifier("group", "key");
                var configurationServiceMock = new Mock <IHystrixConfigurationService>();
                var timeoutWrapper           = new HystrixTimeoutWrapper(commandIdentifier, configurationServiceMock.Object);

                CancellationTokenSource tokenSource = new CancellationTokenSource();

                var primaryTask = new Func <Task <string> >(() => Task.Run(async() =>
                {
                    tokenSource.Token.WaitHandle.WaitOne(2000);
                    await Task.Delay(10, tokenSource.Token);
                    return("a value");
                }));

                configurationServiceMock.Setup(service => service.GetCommandTimeoutInMilliseconds()).Returns(1000);

                int availableThreadsBefore = GetAvailableThreads();

                // act
                await Assert.ThrowsAsync <HystrixTimeoutException>(() => timeoutWrapper.ExecuteAsync(primaryTask, tokenSource));

                int availableThreadsAfter = GetAvailableThreads();

                Assert.Equal(0, availableThreadsBefore - availableThreadsAfter);

                await Task.Delay(2000);

                availableThreadsAfter = GetAvailableThreads();

                Assert.Equal(0, availableThreadsBefore - availableThreadsAfter);
            }
            public void Throws_ArgumentNullException_When_MetricsCollector_Is_Null()
            {
                var commandIdentifier        = new HystrixCommandIdentifier("group", "key");
                var configurationServiceMock = new Mock <IHystrixConfigurationService>();

                // Act
                Assert.Throws <ArgumentNullException>(() => new HystrixCircuitBreaker(commandIdentifier, configurationServiceMock.Object, null));
            }
Exemplo n.º 6
0
            public void Throws_ArgumentNullException_When_ConfigurationService_Is_Null()
            {
                var dateTimeProvider   = new Mock <IDateTimeProvider>();
                var commandIdentifier  = new HystrixCommandIdentifier("group", "key");
                var commandMetricsMock = new Mock <IHystrixCommandMetrics>();

                // Act
                Assert.Throws <ArgumentNullException>(() => new HystrixCircuitBreaker(dateTimeProvider.Object, commandIdentifier, null, commandMetricsMock.Object));
            }
Exemplo n.º 7
0
            public void Returns_HashCode_Consisting_Of_GroupKey_And_CommandKey()
            {
                var commandIdentifier = new HystrixCommandIdentifier("GroupA", "CommandX");

                // act
                var hashCode = commandIdentifier.GetHashCode();

                Assert.Equal(579705872, hashCode);
            }
Exemplo n.º 8
0
            public void Returns_False_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                bool value = hystrixConfigurationService.GetCircuitBreakerForcedOpen();

                Assert.Equal(false, value);
            }
Exemplo n.º 9
0
            public void Returns_GetCircuitBreakerForcedOpen_AppSetting_As_Boolean_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                bool value = hystrixConfigurationService.GetCircuitBreakerForcedOpen();

                Assert.Equal(true, value);
            }
Exemplo n.º 10
0
            public void Returns_True_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                bool value = hystrixConfigurationService.GetHystrixCommandEnabled();

                Assert.True(value);
            }
Exemplo n.º 11
0
            public void Returns_HystrixCommandEnabled_AppSetting_As_Boolean_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                bool value = hystrixConfigurationService.GetHystrixCommandEnabled();

                Assert.False(value);
            }
Exemplo n.º 12
0
            public void Returns_100_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileBucketSize();

                Assert.Equal(100, value);
            }
            public void Returns_True_If_AppSetting_Is_Not_A_Valid_Integer()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupC", "DependencyZ");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetHystrixCommandEnabled();

                Assert.True(value);
            }
Exemplo n.º 14
0
            public void Returns_True_If_GroupKey_Are_Equal_And_CommandKey_Are_Not_Equal()
            {
                var firstCommandIdentifier  = new HystrixCommandIdentifier("GroupA", "CommandX");
                var secondCommandIdentifier = new HystrixCommandIdentifier("GroupA", "CommandY");

                // act
                var result = firstCommandIdentifier.Equals(secondCommandIdentifier);

                Assert.False(result);
            }
            public void Returns_MetricsRollingPercentileBucketSize_AppSetting_As_Integer_For_GroupB_And_DependencyY()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupB", "DependencyY");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileBucketSize();

                Assert.Equal(1500, value);
            }
Exemplo n.º 16
0
            public void Returns_MetricsRollingStatisticalWindowInMilliseconds_AppSetting_As_Integer_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetMetricsRollingStatisticalWindowInMilliseconds();

                Assert.Equal(3000, value);
            }
Exemplo n.º 17
0
            public void Returns_20_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetCircuitBreakerRequestVolumeThreshold();

                Assert.Equal(20, value);
            }
Exemplo n.º 18
0
            public void Returns_CircuitBreakerRequestVolumeThreshold_AppSetting_As_Integer_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetCircuitBreakerRequestVolumeThreshold();

                Assert.Equal(50000, value);
            }
            public void Returns_100_If_AppSetting_Is_Not_A_Valid_Integer()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupC", "DependencyZ");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileBucketSize();

                Assert.Equal(100, value);
            }
            public void Returns_False_If_AppSetting_Is_Not_A_Valid_Boolean()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupC", "DependencyZ");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetCircuitBreakerForcedOpen();

                Assert.Equal(false, value);
            }
            public void Returns_GetCircuitBreakerForcedOpen_AppSetting_As_Boolean_For_GroupB_And_DependencyY()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupB", "DependencyY");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetCircuitBreakerForcedOpen();

                Assert.Equal(false, value);
            }
            public void Returns_6_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileWindowBuckets();

                Assert.Equal(6, value);
            }
Exemplo n.º 23
0
            public void Returns_True_If_GroupKey_Are_Equal_And_CommandKey_Are_Equal_And_Have_Different_Casing()
            {
                var firstCommandIdentifier  = new HystrixCommandIdentifier("GroupA", "CommandX");
                var secondCommandIdentifier = new HystrixCommandIdentifier("grOUpA", "comMAndX");

                // act
                var result = firstCommandIdentifier.Equals(secondCommandIdentifier);

                Assert.True(result);
            }
Exemplo n.º 24
0
            public void Returns_1000_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetCommandTimeoutInMilliseconds();

                Assert.Equal(1000, value);
            }
            public void Returns_True_If_AppSetting_Does_Not_Exist()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("NonExistingGroup", "NonExistingCommand");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetMetricsRollingPercentileEnabled();

                Assert.True(value);
            }
            public void Returns_HystrixCommandEnabled_AppSetting_As_Boolean_For_GroupB_And_DependencyY()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupB", "DependencyY");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetHystrixCommandEnabled();

                Assert.False(value);
            }
Exemplo n.º 27
0
            public void Returns_CommandTimeoutInMilliseconds_AppSetting_As_Integer_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var sut = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int result = sut.GetCommandTimeoutInMilliseconds();

                Assert.Equal(1500, result);
            }
            public void Returns_MetricsRollingPercentileWindowBuckets_AppSetting_As_Integer_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileWindowBuckets();

                Assert.Equal(3000, value);
            }
Exemplo n.º 29
0
            public void Returns_MetricsRollingPercentileBucketSize_AppSetting_As_Integer_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixLocalConfigurationService(hystrixCommandIdentifier, options);

                // Act
                int value = hystrixConfigurationService.GetMetricsRollingPercentileBucketSize();

                Assert.Equal(3000, value);
            }
            public void Returns_MetricsRollingPercentileEnabled_AppSetting_As_Boolean_For_GroupA_And_DependencyX()
            {
                var hystrixCommandIdentifier    = new HystrixCommandIdentifier("GroupA", "DependencyX");
                var hystrixConfigurationService = new HystrixWebConfigConfigurationService(hystrixCommandIdentifier);

                // act
                bool value = hystrixConfigurationService.GetMetricsRollingPercentileEnabled();

                Assert.True(value);
            }