Search in sources :

Example 6 with CachedValuesHistogram

use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.

the class RollingCollapserBatchSizeDistributionStreamTest method testBatchesAgeOut.

//by doing a take(30), all metrics should fall out of window and we should observe an empty histogram
@Test
public void testBatchesAgeOut() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("Collapser-Batch-Size-B");
    stream = RollingCollapserBatchSizeDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(30).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println("OnNext @ " + System.currentTimeMillis());
        }
    });
    Collapser.from(key, 1).observe();
    Collapser.from(key, 2).observe();
    Collapser.from(key, 3).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 4).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 5).observe();
    Collapser.from(key, 6).observe();
    Collapser.from(key, 7).observe();
    Collapser.from(key, 8).observe();
    Collapser.from(key, 9).observe();
    try {
        Thread.sleep(200);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 10).observe();
    Collapser.from(key, 11).observe();
    Collapser.from(key, 12).observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(0, stream.getLatest().getTotalCount());
    assertEquals(0, stream.getLatestMean());
}
Also used : CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 7 with CachedValuesHistogram

use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.

the class RollingCollapserBatchSizeDistributionStreamTest method testBatches.

@Test
public void testBatches() {
    HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("Collapser-Batch-Size-B");
    stream = RollingCollapserBatchSizeDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println("OnNext @ " + System.currentTimeMillis());
        }
    });
    Collapser.from(key, 1).observe();
    Collapser.from(key, 2).observe();
    Collapser.from(key, 3).observe();
    try {
        Thread.sleep(250);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 4).observe();
    try {
        Thread.sleep(250);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 5).observe();
    Collapser.from(key, 6).observe();
    Collapser.from(key, 7).observe();
    Collapser.from(key, 8).observe();
    Collapser.from(key, 9).observe();
    try {
        Thread.sleep(250);
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    Collapser.from(key, 10).observe();
    Collapser.from(key, 11).observe();
    Collapser.from(key, 12).observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    //should have 4 batches: 3, 1, 5, 3
    assertEquals(4, stream.getLatest().getTotalCount());
    assertEquals(3, stream.getLatestMean());
    assertEquals(1, stream.getLatestPercentile(0));
    assertEquals(5, stream.getLatestPercentile(100));
}
Also used : CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 8 with CachedValuesHistogram

use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.

the class RollingCommandLatencyDistributionStreamTest method testEmptyStreamProducesEmptyDistributions.

@Test
public void testEmptyStreamProducesEmptyDistributions() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-A");
    stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println("OnNext @ " + System.currentTimeMillis());
            assertEquals(0, distribution.getTotalCount());
        }
    });
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(0, stream.getLatest().getTotalCount());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 9 with CachedValuesHistogram

use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.

the class RollingCommandLatencyDistributionStreamTest method testSingleBucketWithMultipleEventTypes.

/*
     * The following event types should not have their latency measured:
     * THREAD_POOL_REJECTED
     * SEMAPHORE_REJECTED
     * SHORT_CIRCUITED
     * RESPONSE_FROM_CACHE
     *
     * Newly measured (as of 1.5)
     * BAD_REQUEST
     * FAILURE
     * TIMEOUT
     */
@Test
public void testSingleBucketWithMultipleEventTypes() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-C");
    stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(10).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " Received distribution with count : " + distribution.getTotalCount() + " and mean : " + distribution.getMean());
            if (distribution.getTotalCount() < 4 && distribution.getTotalCount() > 0) {
                //buckets before timeout latency registers
                assertBetween(10, 50, (int) distribution.getMean());
            } else if (distribution.getTotalCount() == 4) {
                //now timeout latency of 600ms is there
                assertBetween(150, 250, (int) distribution.getMean());
            }
        }
    });
    Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    //latency = 600
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.TIMEOUT);
    Command cmd3 = Command.from(groupKey, key, HystrixEventType.FAILURE, 30);
    Command cmd4 = Command.from(groupKey, key, HystrixEventType.BAD_REQUEST, 40);
    cmd1.observe();
    cmd2.observe();
    cmd3.observe();
    cmd4.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    //now timeout latency of 600ms is there
    assertBetween(150, 350, stream.getLatestMean());
    assertBetween(10, 40, stream.getLatestPercentile(0.0));
    assertBetween(600, 800, stream.getLatestPercentile(100.0));
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Example 10 with CachedValuesHistogram

use of com.netflix.hystrix.metric.CachedValuesHistogram in project Hystrix by Netflix.

the class RollingCommandLatencyDistributionStreamTest method testMultipleBucketsBothGetStoredAndThenAgeOut.

/**
     * The extra takes on the stream should give enough time for all of the measured latencies to age out
     */
@Test
public void testMultipleBucketsBothGetStoredAndThenAgeOut() {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Latency-I");
    stream = RollingCommandLatencyDistributionStream.getInstance(key, 10, 100);
    stream.startCachingStreamValuesIfUnstarted();
    final CountDownLatch latch = new CountDownLatch(1);
    stream.observe().take(30).subscribe(new Subscriber<CachedValuesHistogram>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            fail(e.getMessage());
        }

        @Override
        public void onNext(CachedValuesHistogram distribution) {
            System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " Received distribution with count : " + distribution.getTotalCount() + " and mean : " + distribution.getMean());
            if (distribution.getTotalCount() == 2) {
                assertBetween(55, 90, (int) distribution.getMean());
            }
            if (distribution.getTotalCount() == 5) {
                assertEquals(60, 90, (long) distribution.getMean());
            }
        }
    });
    Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
    Command cmd2 = Command.from(groupKey, key, HystrixEventType.FAILURE, 100);
    cmd1.observe();
    cmd2.observe();
    try {
        Thread.sleep(500);
    } catch (InterruptedException ie) {
        fail("Interrupted ex");
    }
    Command cmd3 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 60);
    Command cmd4 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 60);
    Command cmd5 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 70);
    cmd3.observe();
    cmd4.observe();
    cmd5.observe();
    try {
        assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
    } catch (InterruptedException ex) {
        fail("Interrupted ex");
    }
    assertEquals(0, stream.getLatest().getTotalCount());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) CachedValuesHistogram(com.netflix.hystrix.metric.CachedValuesHistogram) CountDownLatch(java.util.concurrent.CountDownLatch) CommandStreamTest(com.netflix.hystrix.metric.CommandStreamTest) Test(org.junit.Test)

Aggregations

CachedValuesHistogram (com.netflix.hystrix.metric.CachedValuesHistogram)12 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 Test (org.junit.Test)12 HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)9 HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)3 ArrayList (java.util.ArrayList)3 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)1