protected C GetCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, int executionLatency, FallbackResultTest fallbackResult, int fallbackLatency, TestCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool, int timeout, CacheEnabledTest cacheEnabled, object value, int executionSemaphoreCount, int fallbackSemaphoreCount, bool circuitBreakerDisabled)
        {
            SemaphoreSlim executionSemaphore = new SemaphoreSlim(executionSemaphoreCount);
            SemaphoreSlim fallbackSemaphore  = new SemaphoreSlim(fallbackSemaphoreCount);

            return(GetCommand(isolationStrategy, executionResult, executionLatency, fallbackResult, fallbackLatency, circuitBreaker, threadPool, timeout, cacheEnabled, value, executionSemaphore, fallbackSemaphore, circuitBreakerDisabled));
        }
            public static Command From(IHystrixCommandGroupKey groupKey, IHystrixCommandKey key, HystrixEventType desiredEventType, int latency,
                                       ExecutionIsolationStrategy isolationStrategy,
                                       HystrixEventType desiredFallbackEventType, int fallbackLatency)
            {
                HystrixThreadPoolOptions topts = new HystrixThreadPoolOptions()
                {
                    CoreSize      = 10,
                    MaxQueueSize  = -1,
                    ThreadPoolKey = HystrixThreadPoolKeyDefault.AsKey(groupKey.Name)
                };

                HystrixCommandOptions setter = new HystrixCommandOptions()
                {
                    GroupKey   = groupKey,
                    CommandKey = key,

                    ExecutionTimeoutInMilliseconds                = 600,
                    ExecutionIsolationStrategy                    = isolationStrategy,
                    CircuitBreakerEnabled                         = true,
                    CircuitBreakerRequestVolumeThreshold          = 3,
                    MetricsHealthSnapshotIntervalInMilliseconds   = 100,
                    MetricsRollingStatisticalWindowInMilliseconds = 1000,
                    MetricsRollingStatisticalWindowBuckets        = 10,
                    RequestCacheEnabled = true,
                    RequestLogEnabled   = true,
                    FallbackIsolationSemaphoreMaxConcurrentRequests = 5,
                    ThreadPoolKey     = HystrixThreadPoolKeyDefault.AsKey(groupKey.Name),
                    ThreadPoolOptions = topts
                };



                String uniqueArg;

                switch (desiredEventType)
                {
                case HystrixEventType.SUCCESS:
                    uniqueArg = uniqueId.IncrementAndGet() + "";
                    return(new Command(setter, HystrixEventType.SUCCESS, latency, uniqueArg, desiredFallbackEventType, 0));

                case HystrixEventType.FAILURE:
                    uniqueArg = uniqueId.IncrementAndGet() + "";
                    return(new Command(setter, HystrixEventType.FAILURE, latency, uniqueArg, desiredFallbackEventType, fallbackLatency));

                case HystrixEventType.TIMEOUT:
                    uniqueArg = uniqueId.IncrementAndGet() + "";
                    return(new Command(setter, HystrixEventType.SUCCESS, 1000, uniqueArg, desiredFallbackEventType, fallbackLatency));

                case HystrixEventType.BAD_REQUEST:
                    uniqueArg = uniqueId.IncrementAndGet() + "";
                    return(new Command(setter, HystrixEventType.BAD_REQUEST, latency, uniqueArg, desiredFallbackEventType, 0));

                case HystrixEventType.RESPONSE_FROM_CACHE:
                    String arg = uniqueId.Value + "";
                    return(new Command(setter, HystrixEventType.SUCCESS, 0, arg, desiredFallbackEventType, 0));

                default:
                    throw new Exception("not supported yet");
                }
            }
        protected C GetCircuitOpenCommand(ExecutionIsolationStrategy isolationStrategy, FallbackResultTest fallbackResult)
        {
            TestCircuitBreaker openCircuit = new TestCircuitBreaker();

            openCircuit.SetForceShortCircuit(true);
            return(GetCommand(isolationStrategy, ExecutionResultTest.SUCCESS, 0, fallbackResult, 0, openCircuit, null, 500, CacheEnabledTest.NO, "foo", 10, 10, false));
        }
Example #4
0
 public BadRequestCommand(TestCircuitBreaker circuitBreaker, ExecutionIsolationStrategy isolationType)
     : base(new TestCommandBuilder()
 {
     CircuitBreaker            = circuitBreaker,
     CommandPropertiesDefaults = UnitTestSetterFactory.GetCommandPropertiesSetter().WithExecutionIsolationStrategy(isolationType),
 })
 {
 }
Example #5
0
 public static Command From(
     IHystrixCommandGroupKey groupKey,
     IHystrixCommandKey key,
     HystrixEventType desiredEventType,
     int latency,
     ExecutionIsolationStrategy isolationStrategy)
 {
     return(From(groupKey, key, desiredEventType, latency, isolationStrategy, HystrixEventType.FALLBACK_SUCCESS, 0));
 }
Example #6
0
 public static Command From(
     IHystrixCommandGroupKey groupKey,
     IHystrixCommandKey key,
     HystrixEventType desiredEventType,
     int latency,
     ExecutionIsolationStrategy isolationStrategy,
     HystrixEventType desiredFallbackEventType)
 {
     return(From(groupKey, key, desiredEventType, latency, isolationStrategy, desiredFallbackEventType, 0));
 }
 public HystrixCommandExecutionConfig(int semaphoreMaxConcurrentRequests, ExecutionIsolationStrategy isolationStrategy,
                                      bool threadInterruptOnTimeout, String threadPoolKeyOverride, bool timeoutEnabled,
                                      int timeoutInMilliseconds, bool fallbackEnabled, int fallbackMaxConcurrentRequests,
                                      bool requestCacheEnabled, bool requestLogEnabled)
 {
     this.semaphoreMaxConcurrentRequests = semaphoreMaxConcurrentRequests;
     this.isolationStrategy            = isolationStrategy;
     this.threadInterruptOnTimeout     = threadInterruptOnTimeout;
     this.threadPoolKeyOverride        = threadPoolKeyOverride;
     this.timeoutEnabled               = timeoutEnabled;
     this.timeoutInMilliseconds        = timeoutInMilliseconds;
     this.fallbackEnabled              = fallbackEnabled;
     this.fallbackMaxConcurrentRequest = fallbackMaxConcurrentRequests;
     this.requestCacheEnabled          = requestCacheEnabled;
     this.requestLogEnabled            = requestLogEnabled;
 }
 public virtual void MarkCommandExecution(HystrixCommandKey key, ExecutionIsolationStrategy isolationStrategy, TimeSpan duration, IEnumerable<HystrixEventType> eventsDuringExecution)
 {
     // do nothing
 }
 protected C GetLatentCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, int executionLatency, FallbackResultTest fallbackResult, TestCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool, int timeout)
 {
     return(GetCommand(isolationStrategy, executionResult, executionLatency, fallbackResult, 0, circuitBreaker, threadPool, timeout, CacheEnabledTest.NO, "foo", 10, 10));
 }
 protected C GetLatentCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, int executionLatency, FallbackResultTest fallbackResult, int timeout)
 {
     return(GetCommand(isolationStrategy, executionResult, executionLatency, fallbackResult, 0, new TestCircuitBreaker(), null, timeout, CacheEnabledTest.NO, "foo", 10, 10));
 }
 protected abstract C GetCommand(IHystrixCommandKey commandKey, ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, int executionLatency, FallbackResultTest fallbackResult, int fallbackLatency, TestCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool, int timeout, CacheEnabledTest cacheEnabled, object value, SemaphoreSlim executionSemaphore, SemaphoreSlim fallbackSemaphore, bool circuitBreakerDisabled);
Example #12
0
 public CommandPropertiesBuilder WithExecutionIsolationStrategy(ExecutionIsolationStrategy value)
 {
     this.executionIsolationStrategy = value;
     return(this);
 }
Example #13
0
 public HystrixCommandPropertiesSetter WithExecutionIsolationStrategy(ExecutionIsolationStrategy value)
 {
     ExecutionIsolationStrategy = value;
     return(this);
 }
 public HystrixCommandExecutionStarted(IHystrixCommandKey commandKey, IHystrixThreadPoolKey threadPoolKey, ExecutionIsolationStrategy isolationStrategy, int currentConcurrency)
     : base(commandKey, threadPoolKey)
 {
     this.isolationStrategy  = isolationStrategy;
     this.currentConcurrency = currentConcurrency;
 }
 protected C GetUnrecoverableErrorCommand(ExecutionIsolationStrategy isolationStrategy, FallbackResultTest fallbackResult)
 {
     return(GetCommand(isolationStrategy, ExecutionResultTest.UNRECOVERABLE_ERROR, 0, fallbackResult));
 }
 protected C GetSharedCircuitBreakerCommand(IHystrixCommandKey commandKey, ExecutionIsolationStrategy isolationStrategy, FallbackResultTest fallbackResult, TestCircuitBreaker circuitBreaker)
 {
     return(GetCommand(commandKey, isolationStrategy, ExecutionResultTest.FAILURE, 0, fallbackResult, 0, circuitBreaker, null, 500, CacheEnabledTest.NO, "foo", 10, 10));
 }
Example #17
0
        public void CommandExecutionStarted(IHystrixCommandKey commandKey, IHystrixThreadPoolKey threadPoolKey, ExecutionIsolationStrategy isolationStrategy, int currentConcurrency)
        {
            HystrixCommandExecutionStarted @event = new HystrixCommandExecutionStarted(commandKey, threadPoolKey, isolationStrategy, currentConcurrency);

            _writeOnlyCommandStartSubject.OnNext(@event);
        }
Example #18
0
 public TestCommandBuilder(ExecutionIsolationStrategy isolationStrategy)
 {
     this.CommandPropertiesDefaults = HystrixCommandOptionsTest.GetUnitTestOptions();
     this.CommandPropertiesDefaults.ExecutionIsolationStrategy = isolationStrategy;
 }
 public void MarkCommandExecution(IHystrixCommandKey key, ExecutionIsolationStrategy isolationStrategy, int duration, IList <HystrixEventType> eventsDuringExecution)
 {
     // do nothing
 }
 protected C GetCircuitBreakerDisabledCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult)
 {
     return(GetCommand(isolationStrategy, executionResult, 0, FallbackResultTest.UNIMPLEMENTED, 0, new TestCircuitBreaker(), null, 500, CacheEnabledTest.NO, "foo", 10, 10, true));
 }
Example #21
0
 public virtual void MarkCommandExecution(HystrixCommandKey key, ExecutionIsolationStrategy isolationStrategy, TimeSpan duration, IEnumerable <HystrixEventType> eventsDuringExecution)
 {
     // do nothing
 }
Example #22
0
 public static TestCommandBuilder TestPropsBuilder(ExecutionIsolationStrategy isolationStrategy)
 {
     return(new TestCommandBuilder(isolationStrategy));
 }
        internal void MarkCommandStart(IHystrixCommandKey commandKey, IHystrixThreadPoolKey threadPoolKey, ExecutionIsolationStrategy isolationStrategy)
        {
            int currentCount = _concurrentExecutionCount.IncrementAndGet();

            HystrixThreadEventStream.GetInstance().CommandExecutionStarted(commandKey, threadPoolKey, isolationStrategy, currentCount);
        }
 protected C GetCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, int executionLatency)
 {
     return(GetCommand(isolationStrategy, executionResult, executionLatency, FallbackResultTest.UNIMPLEMENTED));
 }
 protected C GetCommand(ExecutionIsolationStrategy isolationStrategy, ExecutionResultTest executionResult, FallbackResultTest fallbackResult)
 {
     return(GetCommand(isolationStrategy, executionResult, 0, fallbackResult));
 }
        public static TestServiceCommand Get(IJellyfishContext ctx, ITestOutputHelper output, string commandName, ExecutionIsolationStrategy strategy,
                                             ExecutionResult executionResult          = ExecutionResult.NONE, FallbackResult fallbackResult = FallbackResult.UNIMPLEMENTED,
                                             Action <CommandPropertiesBuilder> setter = null, TestCircuitBreaker circuitBreaker             = null, IClock clock = null)
        {
            var builder = CommandPropertiesTest.GetUnitTestPropertiesSetter();

            builder.WithExecutionIsolationStrategy(strategy);
            if (setter != null)
            {
                setter(builder);
            }
            if (clock == null)
            {
                clock = new MockedClock();
            }

            var cmd = new TestServiceCommand(ctx, commandName, builder, clock, circuitBreaker ?? new TestCircuitBreaker(clock), new TestExecutionHook(output));

            cmd.Log = msg => output.WriteLine("({0}) - {1}", cmd.Id, msg);

            if (executionResult == ExecutionResult.SUCCESS)
            {
                cmd.Action = () =>
                {
                    cmd.Log("Execution success"); return(Task.FromResult(TestCommandFactory.EXECUTE_VALUE));
                };
            }
            else if (executionResult == ExecutionResult.FAILURE)
            {
                cmd.Action = () => { cmd.Log("Execution failure");; throw new Exception("Execution Failure for TestCommand"); };
            }
            else if (executionResult == ExecutionResult.HYSTRIX_FAILURE)
            {
                cmd.Action = () =>
                {
                    cmd.Log("Execution failure");
                    throw new Exception("Execution  Failure for TestCommand", new Exception("Fallback Failure for TestCommand"));
                };
            }
            else if (executionResult == ExecutionResult.RECOVERABLE_ERROR)
            {
                cmd.Action = () =>
                {
                    cmd.Log("Execution recoverable error");
                    throw new Exception("Execution ERROR for TestCommand");
                };
            }
            else if (executionResult == ExecutionResult.UNRECOVERABLE_ERROR)
            {
                cmd.Action = () =>
                {
                    cmd.Log("Execution unrecoverable error");
                    throw new StackOverflowException("Unrecoverable Error for TestCommand");
                };
            }
            else if (executionResult == ExecutionResult.BAD_REQUEST)
            {
                cmd.Action = () =>
                {
                    cmd.Log("Execution bad request");
                    throw new BadRequestException("Execution BadRequestException for TestCommand");
                };
            }

            if (fallbackResult == FallbackResult.SUCCESS)
            {
                cmd.Fallback = () =>
                {
                    cmd.Log("Execution fallback success");
                    return(Task.FromResult(TestCommandFactory.FALLBACK_VALUE));
                };
            }
            else if (fallbackResult == FallbackResult.FAILURE)
            {
                cmd.Fallback = () => { cmd.Log("Execution fallback error"); throw new Exception("Fallback Failure for TestCommand"); };
            }
            else if (fallbackResult == FallbackResult.UNIMPLEMENTED)
            {
                cmd.Fallback = () =>
                {
                    cmd.Log("Execution fallback unimplemented");
                    throw new NotImplementedException();
                };
            }

            return(cmd);
        }
 public HystrixCommandPropertiesSetter WithExecutionIsolationStrategy(ExecutionIsolationStrategy value)
 {
     ExecutionIsolationStrategy = value;
     return this;
 }