public async void TestFallbackMissing() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-Health-K"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = HealthCountsStream.GetInstance(key, 10, 100); Command cmd = CommandStreamTest.Command.From(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_MISSING); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); await Assert.ThrowsAsync <HystrixRuntimeException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(1L, stream.Latest.ErrorCount); Assert.Equal(1L, stream.Latest.TotalRequests); }
public async Task TestSingleFailure() { var key = HystrixCommandKeyDefault.AsKey("CMD-Health-C"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = HealthCountsStream.GetInstance(key, 10, 100); var cmd = Command.From(GroupKey, key, HystrixEventType.FAILURE, 0); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(1L, stream.Latest.ErrorCount); Assert.Equal(1L, stream.Latest.TotalRequests); }
public async void TestSingleBadRequest() { IHystrixCommandGroupKey groupKey = HystrixCommandGroupKeyDefault.AsKey("ThreadPool-E"); IHystrixThreadPoolKey threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("ThreadPool-E"); IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("RollingCounter-E"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingThreadPoolEventCounterStream.GetInstance(threadPoolKey, 10, 500); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); Command cmd = CommandStreamTest.Command.From(groupKey, key, HystrixEventType.BAD_REQUEST); await Assert.ThrowsAsync <HystrixBadRequestException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.Equal(2, stream.Latest.Length); Assert.Equal(1, stream.GetLatestCount(ThreadPoolEventType.EXECUTED)); Assert.Equal(0, stream.GetLatestCount(ThreadPoolEventType.REJECTED)); }
public async void TestSingleFailure() { var groupKey = HystrixCommandGroupKeyDefault.AsKey("ThreadPool-C"); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("ThreadPool-C"); var key = HystrixCommandKeyDefault.AsKey("RollingCounter-C"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingThreadPoolEventCounterStream.GetInstance(threadPoolKey, 10, 500); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); var cmd = CommandStreamTest.Command.From(groupKey, key, HystrixEventType.FAILURE, 20); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.Equal(2, stream.Latest.Length); Assert.Equal(1, stream.GetLatestCount(ThreadPoolEventType.EXECUTED)); Assert.Equal(0, stream.GetLatestCount(ThreadPoolEventType.REJECTED)); }
public void TestStartsAndEndsInSameBucketProduceValue() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-Concurrency-B"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandMaxConcurrencyStream.GetInstance(key, 10, 500); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); Command cmd1 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 100); Command cmd2 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 100); Task t1 = cmd1.ExecuteAsync(); Task t2 = cmd2.ExecuteAsync(); Task.WaitAll(t1, t2); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.Equal(2, stream.LatestRollingMax); }
public async void TestSingleSuccess() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-RollingCounter-B"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); Command cmd = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 20); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); long[] expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)HystrixEventType.SUCCESS] = 1; output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(expected, stream.Latest); }
public async Task TestSingleBadRequest() { var key = HystrixCommandKeyDefault.AsKey("CMD-Health-E"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = HealthCountsStream.GetInstance(key, 10, 100); var cmd = CommandStreamTest.Command.From(GroupKey, key, HystrixEventType.BAD_REQUEST); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); await Assert.ThrowsAsync <HystrixBadRequestException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(0L, stream.Latest.ErrorCount); Assert.Equal(0L, stream.Latest.TotalRequests); }
public void TestShortCircuited() { var key = HystrixCommandKeyDefault.AsKey("CMD-CumulativeCounter-G"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = CumulativeCommandEventCounterStream.GetInstance(key, 10, 500); var failure1 = Command.From(GroupKey, key, HystrixEventType.FAILURE, 0); var failure2 = Command.From(GroupKey, key, HystrixEventType.FAILURE, 0); var failure3 = Command.From(GroupKey, key, HystrixEventType.FAILURE, 0); var shortCircuit1 = Command.From(GroupKey, key, HystrixEventType.SUCCESS); var shortCircuit2 = Command.From(GroupKey, key, HystrixEventType.SUCCESS); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); // 3 failures in a row will trip circuit. let bucket roll once then submit 2 requests. // should see 3 FAILUREs and 2 SHORT_CIRCUITs and then 5 FALLBACK_SUCCESSes failure1.Execute(); failure2.Execute(); failure3.Execute(); Assert.True(WaitForHealthCountToUpdate(key.Name, 500, output), "health count took to long to update"); output.WriteLine(Time.CurrentTimeMillis + " running failures"); shortCircuit1.Execute(); shortCircuit2.Execute(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.True(shortCircuit1.IsResponseShortCircuited); Assert.True(shortCircuit2.IsResponseShortCircuited); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); var expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)HystrixEventType.FAILURE] = 3; expected[(int)HystrixEventType.SHORT_CIRCUITED] = 2; expected[(int)HystrixEventType.FALLBACK_SUCCESS] = 5; Assert.Equal(expected, stream.Latest); }
public async Task TestSingleBucketGetsStored() { var key = HystrixCommandKeyDefault.AsKey("CMD-Latency-B"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandLatencyDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); var cmd1 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 10); var cmd2 = Command.From(GroupKey, key, HystrixEventType.TIMEOUT); // latency = 600 await cmd1.Observe(); await cmd2.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); AssertBetween(100, 400, stream.LatestMean); AssertBetween(10, 100, stream.GetLatestPercentile(0.0)); AssertBetween(300, 800, stream.GetLatestPercentile(100.0)); }
public void TestResponseFromCacheDoesNotGetLatencyTracked() { var key = HystrixCommandKeyDefault.AsKey("CMD-Latency-G"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandLatencyDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); // should get 1 SUCCESS and 1 RESPONSE_FROM_CACHE var commands = Command.GetCommandsWithResponseFromCache(GroupKey, key); foreach (var cmd in commands) { _ = cmd.ExecuteAsync(); } Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(1, stream.Latest.GetTotalCount()); AssertBetween(0, 75, stream.LatestMean); }
public async void TestFallbackMissing() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-RollingCounter-K"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); Command cmd = Command.From(GroupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_MISSING); await Assert.ThrowsAsync <HystrixRuntimeException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)HystrixEventType.FAILURE] = 1; expected[(int)HystrixEventType.FALLBACK_MISSING] = 1; expected[(int)HystrixEventType.EXCEPTION_THROWN] = 1; Assert.Equal(expected, stream.Latest); }
public async Task TestSingleSuccess() { var groupKey = HystrixCommandGroupKeyDefault.AsKey("Cumulative-ThreadPool-B"); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("Cumulative-ThreadPool-B"); var key = HystrixCommandKeyDefault.AsKey("Cumulative-Counter-B"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = CumulativeThreadPoolEventCounterStream.GetInstance(threadPoolKey, 10, 100); var cmd = Command.From(groupKey, key, HystrixEventType.SUCCESS, 0); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(2, stream.Latest.Length); Assert.Equal(1, stream.GetLatestCount(ThreadPoolEventType.EXECUTED)); Assert.Equal(0, stream.GetLatestCount(ThreadPoolEventType.REJECTED)); }
public async void TestSingleSuccess() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-CumulativeCounter-B"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = CumulativeCommandEventCounterStream.GetInstance(key, 10, 500); // Stream should start Command cmd = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 0); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)(int)HystrixEventType.SUCCESS] = 1; Assert.Equal(expected, stream.Latest); }
public async void TestSingleBadRequest() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-CumulativeCounter-E"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = CumulativeCommandEventCounterStream.GetInstance(key, 10, 500); Command cmd = Command.From(GroupKey, key, HystrixEventType.BAD_REQUEST); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 2000), "Stream failed to start"); await Assert.ThrowsAsync <HystrixBadRequestException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 2000, output), "Latch took to long to update"); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)HystrixEventType.BAD_REQUEST] = 1; expected[(int)HystrixEventType.EXCEPTION_THROWN] = 1; Assert.Equal(expected, stream.Latest); }
public async void TestSingleTimeout() { var key = HystrixCommandKeyDefault.AsKey("CMD-RollingCounter-D"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); var expected = new long[HystrixEventTypeHelper.Values.Count]; expected[(int)HystrixEventType.TIMEOUT] = 1; expected[(int)HystrixEventType.FALLBACK_SUCCESS] = 1; stream = RollingCommandEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); var cmd = Command.From(GroupKey, key, HystrixEventType.TIMEOUT); await cmd.Observe(); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); Assert.Equal(expected, stream.Latest); }
public async Task TestSemaphoreRejectedCommandDoesNotGetLatencyTracked() { var key = HystrixCommandKeyDefault.AsKey("CMD-Latency-F"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandLatencyDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); // 10 commands with latency should occupy all semaphores. execute those, then wait for bucket to roll // next command should be a semaphore rejection var commands = new List <Command>(); for (var i = 0; i < 10; i++) { commands.Add(Command.From(GroupKey, key, HystrixEventType.SUCCESS, 500, ExecutionIsolationStrategy.SEMAPHORE)); } var semaphoreRejected = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 0, ExecutionIsolationStrategy.SEMAPHORE); var satTasks = new List <Task>(); foreach (var saturator in commands) { satTasks.Add(Task.Run(() => saturator.Execute())); } await Task.Delay(50); await Task.Run(() => semaphoreRejected.Execute()); Task.WaitAll(satTasks.ToArray()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(10, stream.Latest.GetTotalCount()); AssertBetween(500, 750, stream.LatestMean); Assert.True(semaphoreRejected.IsResponseSemaphoreRejected); }
public async void TestMultipleEventsOverTimeGetStoredAndAgeOut() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-RollingCounter-M"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Take(30 + LatchedObserver.STABLE_TICK_COUNT).Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); Command cmd1 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 20); Command cmd2 = Command.From(GroupKey, key, HystrixEventType.FAILURE, 10); await cmd1.Observe(); await cmd2.Observe(); Assert.True(latch.Wait(10000), "CountdownEvent was not set!"); Assert.Equal(HystrixEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[HystrixEventTypeHelper.Values.Count]; Assert.Equal(expected, stream.Latest); }
public async void TestThreadPoolRejectedCommandDoesNotGetLatencyTracked() { IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-Latency-E"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCommandLatencyDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); // 10 commands with latency should occupy the entire threadpool. execute those, then wait for bucket to roll // next command should be a thread-pool rejection List <Command> commands = new List <Command>(); for (int i = 0; i < 10; i++) { commands.Add(Command.From(GroupKey, key, HystrixEventType.SUCCESS, 500)); } Command threadPoolRejected = Command.From(GroupKey, key, HystrixEventType.SUCCESS); List <Task> satTasks = new List <Task>(); foreach (Command cmd in commands) { satTasks.Add(cmd.ExecuteAsync()); } await threadPoolRejected.Observe(); Task.WaitAll(satTasks.ToArray()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(10, stream.Latest.GetTotalCount()); AssertBetween(500, 750, stream.LatestMean); Assert.True(threadPoolRejected.IsResponseThreadPoolRejected); }
public void TestMultipleCommandsCarryOverMultipleBucketsForMultipleThreadPools() { var groupKeyX = HystrixCommandGroupKeyDefault.AsKey("ThreadPool-Concurrency-X"); var groupKeyY = HystrixCommandGroupKeyDefault.AsKey("ThreadPool-Concurrency-Y"); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("ThreadPool-Concurrency-X"); var keyX = HystrixCommandKeyDefault.AsKey("RollingConcurrency-X"); var keyY = HystrixCommandKeyDefault.AsKey("RollingConcurrency-Y"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingThreadPoolMaxConcurrencyStream.GetInstance(threadPoolKey, 10, 100); latchSubscription = stream.Observe().Take(10 + LatchedObserver.STABLE_TICK_COUNT).Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); var cmd1 = Command.From(groupKeyX, keyX, HystrixEventType.SUCCESS, 300); var cmd2 = Command.From(groupKeyY, keyY, HystrixEventType.SUCCESS, 300); var cmd3 = Command.From(groupKeyX, keyY, HystrixEventType.SUCCESS, 10); var cmd4 = Command.From(groupKeyX, keyY, HystrixEventType.SUCCESS, 10); Task t1 = cmd1.ExecuteAsync(); // Time.Wait(100); // bucket roll WaitForLatchedObserverToUpdate(observer, 1, 100, 125, output); Task t2 = cmd2.ExecuteAsync(); // Time.Wait(100); // bucket roll WaitForLatchedObserverToUpdate(observer, 1, 100, 125, output); Task t3 = cmd3.ExecuteAsync(); // Time.Wait(100); // bucket roll WaitForLatchedObserverToUpdate(observer, 1, 100, 125, output); Task t4 = cmd4.ExecuteAsync(); Task.WaitAll(t1, t2, t3, t4); WaitForLatchedObserverToUpdate(observer, 1, 100, 125, output); Assert.Equal(2, stream.LatestRollingMax); }
public void TestStartsAndEndsInSameBucketSemaphoreIsolated() { var groupKey = HystrixCommandGroupKeyDefault.AsKey("ThreadPool-Concurrency-C"); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("ThreadPool-Concurrency-C"); var key = HystrixCommandKeyDefault.AsKey("RollingConcurrency-C"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingThreadPoolMaxConcurrencyStream.GetInstance(threadPoolKey, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); var cmd1 = Command.From(groupKey, key, HystrixEventType.SUCCESS, 10, ExecutionIsolationStrategy.SEMAPHORE); var cmd2 = Command.From(groupKey, key, HystrixEventType.SUCCESS, 14, ExecutionIsolationStrategy.SEMAPHORE); Task t1 = cmd1.ExecuteAsync(); Task t2 = cmd2.ExecuteAsync(); Task.WaitAll(t1, t2); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); // since commands run in semaphore isolation, they are not tracked by threadpool metrics Assert.Equal(0, stream.LatestRollingMax); }
public async Task TestFallbackMissing() { var groupKey = HystrixCommandGroupKeyDefault.AsKey("Cumulative-ThreadPool-K"); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey("Cumulative-ThreadPool-K"); var key = HystrixCommandKeyDefault.AsKey("Cumulative-Counter-K"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = CumulativeThreadPoolEventCounterStream.GetInstance(threadPoolKey, 10, 100); var cmd = Command.From(groupKey, key, HystrixEventType.FAILURE, 0, HystrixEventType.FALLBACK_MISSING); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); await Assert.ThrowsAsync <HystrixRuntimeException>(async() => await cmd.Observe()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(2, stream.Latest.Length); Assert.Equal(1, stream.GetLatestCount(ThreadPoolEventType.EXECUTED)); Assert.Equal(0, stream.GetLatestCount(ThreadPoolEventType.REJECTED)); }
public void TestBatches() { IHystrixCollapserKey key = HystrixCollapserKeyDefault.AsKey("Collapser-Batch-Size-B"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCollapserBatchSizeDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); // First collapser created with key will be used for all command creations List <Task> tasks = new List <Task>(); var c1 = Collapser.From(output, key, 1); tasks.Add(c1.ExecuteAsync()); var c2 = Collapser.From(output, key, 2); tasks.Add(c2.ExecuteAsync()); var c3 = Collapser.From(output, key, 3); tasks.Add(c3.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 1 too long to start"); c1.CommandCreated = false; var c4 = Collapser.From(output, key, 4); tasks.Add(c4.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 2 too long to start"); c1.CommandCreated = false; var c5 = Collapser.From(output, key, 5); tasks.Add(c5.ExecuteAsync()); var c6 = Collapser.From(output, key, 6); tasks.Add(c6.ExecuteAsync()); var c7 = Collapser.From(output, key, 7); tasks.Add(c7.ExecuteAsync()); var c8 = Collapser.From(output, key, 8); tasks.Add(c8.ExecuteAsync()); var c9 = Collapser.From(output, key, 9); tasks.Add(c9.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 3 too long to start"); c1.CommandCreated = false; var c10 = Collapser.From(output, key, 10); tasks.Add(c10.ExecuteAsync()); var c11 = Collapser.From(output, key, 11); tasks.Add(c11.ExecuteAsync()); var c12 = Collapser.From(output, key, 12); tasks.Add(c12.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 4 too long to start"); Task.WaitAll(tasks.ToArray()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); // should have 4 batches: 3, 1, 5, 3 Assert.Equal(4, stream.Latest.GetTotalCount()); Assert.Equal(3, stream.LatestMean); Assert.Equal(1, stream.GetLatestPercentile(0)); Assert.Equal(5, stream.GetLatestPercentile(100)); }
public void TestBatchesAgeOut() { IHystrixCollapserKey key = HystrixCollapserKeyDefault.AsKey("Collapser-Batch-Size-B"); CountdownEvent latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCollapserBatchSizeDistributionStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Take(20 + LatchedObserver.STABLE_TICK_COUNT).Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); // First collapser created with key will be used for all command creations List <Task> tasks = new List <Task>(); var c1 = Collapser.From(output, key, 1); tasks.Add(c1.ExecuteAsync()); var c2 = Collapser.From(output, key, 2); tasks.Add(c2.ExecuteAsync()); var c3 = Collapser.From(output, key, 3); tasks.Add(c3.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 1 too long to start"); c1.CommandCreated = false; var c4 = Collapser.From(output, key, 4); tasks.Add(c4.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 2 too long to start"); c1.CommandCreated = false; var c5 = Collapser.From(output, key, 5); tasks.Add(c5.ExecuteAsync()); var c6 = Collapser.From(output, key, 6); tasks.Add(c6.ExecuteAsync()); var c7 = Collapser.From(output, key, 7); tasks.Add(c7.ExecuteAsync()); var c8 = Collapser.From(output, key, 8); tasks.Add(c8.ExecuteAsync()); var c9 = Collapser.From(output, key, 9); tasks.Add(c9.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 3 too long to start"); c1.CommandCreated = false; var c10 = Collapser.From(output, key, 10); tasks.Add(c10.ExecuteAsync()); var c11 = Collapser.From(output, key, 11); tasks.Add(c11.ExecuteAsync()); var c12 = Collapser.From(output, key, 12); tasks.Add(c12.ExecuteAsync()); Assert.True(Time.WaitUntil(() => c1.CommandCreated, 500), "Batch 4 too long to start"); Task.WaitAll(tasks.ToArray()); Assert.True(latch.Wait(10000), "CountdownEvent was not set!"); Assert.Equal(0, stream.Latest.GetTotalCount()); Assert.Equal(0, stream.LatestMean); }