public void TestEmptyStreamProducesZeros() { IHystrixCollapserKey key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-A"); stream = RollingCollapserEventCounterStream.GetInstance(key, 10, 100); stream.StartCachingStreamValuesIfUnstarted(); CountdownEvent latch = new CountdownEvent(1); stream.Observe().Take(10).Subscribe(GetSubscriber(output, latch)); // no writes try { Assert.True(latch.Wait(10000)); } catch (Exception) { Assert.True(false, "Interrupted ex"); } output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); Assert.Equal(0, stream.GetLatest(CollapserEventType.ADDED_TO_BATCH)); Assert.Equal(0, stream.GetLatest(CollapserEventType.BATCH_EXECUTED)); Assert.Equal(0, stream.GetLatest(CollapserEventType.RESPONSE_FROM_CACHE)); }
public void TestCollapsedAndResponseFromCacheAgeOutOfRollingWindow() { IHystrixCollapserKey key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-D"); stream = RollingCollapserEventCounterStream.GetInstance(key, 10, 100); stream.StartCachingStreamValuesIfUnstarted(); CountdownEvent latch = new CountdownEvent(1); stream.Observe().Take(30).Subscribe(GetSubscriber(output, latch)); for (int i = 0; i < 3; i++) { Collapser.From(output, key, i).Observe(); Collapser.From(output, key, i).Observe(); // same arg - should get a response from cache Collapser.From(output, key, i).Observe(); // same arg - should get a response from cache } try { Assert.True(latch.Wait(10000)); } catch (Exception) { Assert.True(false, "Interrupted ex"); } output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[CollapserEventTypeHelper.Values.Count]; expected[(int)CollapserEventType.BATCH_EXECUTED] = 0; expected[(int)CollapserEventType.ADDED_TO_BATCH] = 0; expected[(int)CollapserEventType.RESPONSE_FROM_CACHE] = 0; Assert.Equal <long[]>(expected, stream.Latest); }
public void TestCollapsed() { var key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-B"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCollapserEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); var cTasks = new List <Task>(); for (var i = 0; i < 3; i++) { cTasks.Add(Collapser.From(output, key, i).ExecuteAsync()); } Task.WaitAll(cTasks.ToArray()); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); var expected = new long[CollapserEventTypeHelper.Values.Count]; expected[(int)CollapserEventType.BATCH_EXECUTED] = 1; expected[(int)CollapserEventType.ADDED_TO_BATCH] = 3; Assert.Equal(expected, stream.Latest); }
public void TestCollapsedAndResponseFromCacheAgeOutOfRollingWindow() { var key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-D"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCollapserEventCounterStream.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"); var cTasks = new List <Task>(); for (var i = 0; i < 3; i++) { cTasks.Add(Collapser.From(output, key, i).ExecuteAsync()); cTasks.Add(Collapser.From(output, key, i).ExecuteAsync()); // same arg - should get a response from cache cTasks.Add(Collapser.From(output, key, i).ExecuteAsync()); // same arg - should get a response from cache } Task.WaitAll(cTasks.ToArray()); Assert.True(latch.Wait(10000), "CountdownEvent was not set!"); output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); var expected = new long[CollapserEventTypeHelper.Values.Count]; expected[(int)CollapserEventType.BATCH_EXECUTED] = 0; expected[(int)CollapserEventType.ADDED_TO_BATCH] = 0; expected[(int)CollapserEventType.RESPONSE_FROM_CACHE] = 0; Assert.Equal(expected, stream.Latest); }
public void TestCollapsedAndResponseFromCache() { IHystrixCollapserKey key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-C"); stream = RollingCollapserEventCounterStream.GetInstance(key, 10, 100); stream.StartCachingStreamValuesIfUnstarted(); CountdownEvent latch = new CountdownEvent(1); stream.Observe().Take(10).Subscribe(new LatchedObserver(output, latch)); for (int i = 0; i < 3; i++) { Collapser.From(output, key, i).Observe(); Collapser.From(output, key, i).Observe(); // same arg - should get a response from cache Collapser.From(output, key, i).Observe(); // same arg - should get a response from cache } Assert.True(latch.Wait(10000), "CountdownEvent was not set!"); output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); long[] expected = new long[CollapserEventTypeHelper.Values.Count]; expected[(int)CollapserEventType.BATCH_EXECUTED] = 1; expected[(int)CollapserEventType.ADDED_TO_BATCH] = 3; expected[(int)CollapserEventType.RESPONSE_FROM_CACHE] = 6; Assert.Equal(expected, stream.Latest); }
public void TestEmptyStreamProducesZeros() { var key = HystrixCollapserKeyDefault.AsKey("RollingCollapser-A"); var latch = new CountdownEvent(1); var observer = new LatchedObserver(output, latch); stream = RollingCollapserEventCounterStream.GetInstance(key, 10, 100); latchSubscription = stream.Observe().Subscribe(observer); Assert.True(Time.WaitUntil(() => observer.StreamRunning, 1000), "Stream failed to start"); Assert.True(WaitForLatchedObserverToUpdate(observer, 1, 500, output), "Latch took to long to update"); Assert.Equal(CollapserEventTypeHelper.Values.Count, stream.Latest.Length); Assert.Equal(0, stream.GetLatest(CollapserEventType.ADDED_TO_BATCH)); Assert.Equal(0, stream.GetLatest(CollapserEventType.BATCH_EXECUTED)); Assert.Equal(0, stream.GetLatest(CollapserEventType.RESPONSE_FROM_CACHE)); }