Beispiel #1
0
        public void TtestOneCommandCarriesOverToNextBucket()
        {
            IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-Concurrency-C");

            stream = RollingCommandMaxConcurrencyStream.GetInstance(key, 10, 100);
            stream.StartCachingStreamValuesIfUnstarted();

            CountdownEvent latch = new CountdownEvent(1);

            stream.Observe().Take(10).Subscribe(GetSubscriber(output, latch));

            Command cmd1 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 160);
            Command cmd2 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 10);
            Command cmd3 = Command.From(GroupKey, key, HystrixEventType.SUCCESS, 15);

            cmd1.Observe();
            Time.Wait(100); // bucket roll
            cmd2.Observe();
            Time.Wait(1);
            cmd3.Observe();

            Assert.True(latch.Wait(10000));
            Assert.Equal(3, stream.LatestRollingMax);
        }
        public void TestEmptyStreamProducesZeros()
        {
            IHystrixCommandKey key = HystrixCommandKeyDefault.AsKey("CMD-Concurrency-A");

            stream = RollingCommandMaxConcurrencyStream.GetInstance(key, 10, 500);
            stream.StartCachingStreamValuesIfUnstarted();

            CountdownEvent latch = new CountdownEvent(1);

            stream.Observe().Take(5).Subscribe(
                GetSubscriber(output, latch));

            // no writes
            try
            {
                Assert.True(latch.Wait(10000));
            }
            catch (Exception)
            {
                Assert.True(false, "Interrupted ex");
            }

            Assert.Equal(0, stream.LatestRollingMax);
        }