Пример #1
0
 public CommandWithCustomThreadPool(TestCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool, TimeSpan sleepTime, HystrixCommandPropertiesSetter properties)
     : base(new TestCommandBuilder()
 {
     ThreadPool                = threadPool,
     CircuitBreaker            = circuitBreaker,
     Metrics                   = circuitBreaker.Metrics,
     CommandPropertiesDefaults = properties,
 })
 {
     this.sleepTime = sleepTime;
 }
 public TestCommandRejection(TestCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool, TimeSpan sleepTime, TimeSpan timeout, int fallbackBehavior)
     : base(new TestCommandBuilder()
 {
     ThreadPool                = threadPool,
     CircuitBreaker            = circuitBreaker,
     Metrics                   = circuitBreaker.Metrics,
     CommandPropertiesDefaults = UnitTestSetterFactory.GetCommandPropertiesSetter().WithExecutionIsolationThreadTimeout(timeout)
 })
 {
     this.fallbackBehavior = fallbackBehavior;
     this.sleepTime        = sleepTime;
 }
        public void TestShutdown()
        {
            // other unit tests will probably have run before this so get the count
            int count = HystrixThreadPoolFactory.threadPools.Count;

            IHystrixThreadPool pool = HystrixThreadPoolFactory.GetInstance(HystrixThreadPoolKeyDefault.AsKey("threadPoolFactoryTest"),
                                                                           HystrixThreadPoolOptionsTest.GetUnitTestPropertiesBuilder());

            Assert.Equal(count + 1, HystrixThreadPoolFactory.threadPools.Count);
            Assert.False(pool.GetScheduler().IsShutdown);

            HystrixThreadPoolFactory.Shutdown();

            // ensure all pools were removed from the cache
            Assert.Equal(0, HystrixThreadPoolFactory.threadPools.Count);
            Assert.True(pool.GetScheduler().IsShutdown);
        }
        public void ThreadPool_ShutdownWithWait()
        {
            // other unit tests will probably have run before this so get the count
            int count = HystrixThreadPoolFactory.ThreadPoolCount;

            IHystrixThreadPool pool = HystrixThreadPoolFactory.GetInstance("threadPoolFactoryTest",
                                                                           UnitTestSetterFactory.GetThreadPoolPropertiesSetter());

            Assert.AreEqual(count + 1, HystrixThreadPoolFactory.ThreadPoolCount);
            Assert.IsFalse(pool.Executor.IsShutdown);

            HystrixThreadPoolFactory.Shutdown(TimeSpan.FromSeconds(1.0));

            // ensure all pools were removed from the cache
            Assert.AreEqual(0, HystrixThreadPoolFactory.ThreadPoolCount);
            Assert.IsTrue(pool.Executor.IsShutdown);
        }
Пример #5
0
        public HystrixCommand(
            IHystrixCommandGroupKey group,
            IHystrixCommandKey key,
            IHystrixThreadPoolKey threadPoolKey,
            IHystrixCircuitBreaker circuitBreaker,
            IHystrixThreadPool threadPool,
            IHystrixCommandOptions commandOptionsDefaults,
            IHystrixThreadPoolOptions threadPoolOptionsDefaults,
            HystrixCommandMetrics metrics,
            SemaphoreSlim fallbackSemaphore,
            SemaphoreSlim executionSemaphore,
            HystrixOptionsStrategy optionsStrategy,
            HystrixCommandExecutionHook executionHook,
            Action run,
            Action fallback,
            ILogger logger = null)
            : base(group, key, threadPoolKey, circuitBreaker, threadPool, commandOptionsDefaults, threadPoolOptionsDefaults, metrics, fallbackSemaphore, executionSemaphore, optionsStrategy, executionHook, null, null, logger)
        {
            if (run == null)
            {
                _run = () => Run();
            }
            else
            {
                _run = run;
            }

            if (fallback == null)
            {
                _fallback = () => RunFallback();
            }
            else
            {
                _fallback = fallback;
            }
        }
 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 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);
        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));
        }
Пример #9
0
 public TestCommandBuilder SetThreadPool(IHystrixThreadPool threadPool)
 {
     this.ThreadPool = threadPool;
     return(this);
 }