Search in sources :

Example 6 with HystrixCommand

use of com.netflix.hystrix.HystrixCommand in project Hystrix by Netflix.

the class HystrixMetricsPollerTest method testStartStopStart.

@Test
public void testStartStopStart() {
    final AtomicInteger metricsCount = new AtomicInteger();
    HystrixMetricsPoller poller = new HystrixMetricsPoller(new HystrixMetricsPoller.MetricsAsJsonPollerListener() {

        @Override
        public void handleJsonMetric(String json) {
            System.out.println("Received: " + json);
            metricsCount.incrementAndGet();
        }
    }, 100);
    try {
        HystrixCommand<Boolean> test = new HystrixCommand<Boolean>(HystrixCommandGroupKey.Factory.asKey("HystrixMetricsPollerTest")) {

            @Override
            protected Boolean run() {
                return true;
            }
        };
        test.execute();
        poller.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int v1 = metricsCount.get();
        assertTrue(v1 > 0);
        poller.pause();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int v2 = metricsCount.get();
        // they should be the same since we were paused
        System.out.println("First poll got : " + v1 + ", second got : " + v2);
        assertTrue(v2 == v1);
        poller.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int v3 = metricsCount.get();
        // we should have more metrics again
        assertTrue(v3 > v1);
    } finally {
        poller.shutdown();
    }
}
Also used : HystrixCommand(com.netflix.hystrix.HystrixCommand) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

HystrixCommand (com.netflix.hystrix.HystrixCommand)6 Test (org.junit.Test)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Observable (rx.Observable)2 BatchExecutorClient (ai.grakn.client.BatchExecutorClient)1 ConcurrencyUtil.allObservable (ai.grakn.util.ConcurrencyUtil.allObservable)1 Tracer (brave.Tracer)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HystrixCollapser (com.netflix.hystrix.HystrixCollapser)1 HystrixObservableCollapser (com.netflix.hystrix.HystrixObservableCollapser)1 HystrixObservableCommand (com.netflix.hystrix.HystrixObservableCommand)1 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Stream (java.util.stream.Stream)1 IOUtils (org.apache.commons.io.IOUtils)1 Header (org.apache.http.Header)1 Ignore (org.junit.Ignore)1