public void TestSetNeitherCoreNorMaximumSize() { var properties = new HystrixThreadPoolOptions(HystrixThreadPoolKeyDefault.AsKey("TEST")); Assert.Equal(HystrixThreadPoolOptions.Default_CoreSize, properties.CoreSize); Assert.Equal(HystrixThreadPoolOptions.Default_MaximumSize, properties.MaximumSize); }
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"); } }
public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, MaxQueueSize = 2, QueueSizeRejectionThreshold = 2, AllowMaximumSizeToDivergeFromCoreSize = false, }; // Scheduler to test var scheduler = new HystrixQueuedTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); TaskActionClass tc3 = new TaskActionClass(output, 3); TaskActionClass tc4 = new TaskActionClass(output, 4); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t3 = new Task <int>((o) => tc3.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t4 = new Task <int>((o) => tc4.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Fill up queue t3.Start(scheduler); t4.Start(scheduler); // Allow all tasks to finish and cause continuation tasks to be queued tc1.Stop = true; tc2.Stop = true; tc3.Stop = true; tc4.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); Assert.True(t3.IsCompleted); Assert.Equal(3, t3.Result); Assert.True(t4.IsCompleted); Assert.Equal(4, t4.Result); }
private static IHystrixThreadPoolOptions GetThreadPoolOptions() { var opts = new HystrixThreadPoolOptions(TpKey) { MetricsRollingStatisticalWindowInMilliseconds = 100 }; return(opts); }
public void TestSetCoreSizeEqualToMaximumSize() { var properties = new HystrixThreadPoolOptions(HystrixThreadPoolKeyDefault.AsKey("TEST"), new HystrixThreadPoolOptions() { CoreSize = 7, MaximumSize = 7 }); Assert.Equal(7, properties.CoreSize); Assert.Equal(7, properties.MaximumSize); }
public void TestSetCoreSizeLessThanMaximumSize() { var properties = new HystrixThreadPoolOptions(HystrixThreadPoolKeyDefault.AsKey("TEST"), new HystrixThreadPoolOptions() { CoreSize = 2, MaximumSize = 8 }); Assert.Equal(2, properties.CoreSize); Assert.Equal(8, properties.MaximumSize); }
public void TestSetMaximumSizeOnlyGreaterThanDefaultCoreSize() { var properties = new HystrixThreadPoolOptions(HystrixThreadPoolKeyDefault.AsKey("TEST"), new HystrixThreadPoolOptions() { MaximumSize = 21 }); Assert.Equal(HystrixThreadPoolOptions.Default_CoreSize, properties.CoreSize); Assert.Equal(21, properties.MaximumSize); }
public void TestSetCoreSizeOnly() { var properties = new HystrixThreadPoolOptions(HystrixThreadPoolKeyDefault.AsKey("TEST"), new HystrixThreadPoolOptions() { CoreSize = 14 }); Assert.Equal(14, properties.CoreSize); Assert.Equal(HystrixThreadPoolOptions.Default_MaximumSize, properties.MaximumSize); }
private static IHystrixThreadPoolOptions GetThreadPoolOptions() { HystrixThreadPoolOptions opts = new HystrixThreadPoolOptions() { CoreSize = NUM_CONCURRENT_COMMANDS, MaxQueueSize = NUM_CONCURRENT_COMMANDS, QueueSizeRejectionThreshold = NUM_CONCURRENT_COMMANDS }; return(opts); }
public void TestContinuationTasks_DoNotCauseDeadlocks() { var dummyCommand = new DummyCommand(new HystrixCommandOptions() { GroupKey = HystrixCommandGroupKeyDefault.AsKey("foobar") }); var options = new HystrixThreadPoolOptions() { CoreSize = 2, }; // Scheduler to test var scheduler = new HystrixSyncTaskScheduler(options); TaskActionClass tc1 = new TaskActionClass(output, 1); TaskActionClass tc2 = new TaskActionClass(output, 2); Task <int> t1 = new Task <int>((o) => tc1.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); Task <int> t2 = new Task <int>((o) => tc2.Run(o), dummyCommand, CancellationToken.None, TaskCreationOptions.LongRunning); // Fill up to CoreSize t1.Start(scheduler); t2.Start(scheduler); // Make sure they are running Thread.Sleep(500); // Allow t1 task to finish and cause continuation task to be queued tc1.Stop = true; Thread.Sleep(1000); Assert.True(t1.IsCompleted); Assert.Equal(1, t1.Result); tc2.Stop = true; Thread.Sleep(1000); Assert.True(t2.IsCompleted); Assert.Equal(2, t2.Result); }