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();
}
}
Aggregations