use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.
the class HystrixConfigurationJsonStream method convertToString.
public static String convertToString(HystrixConfiguration config) throws IOException {
StringWriter jsonString = new StringWriter();
JsonGenerator json = jsonFactory.createGenerator(jsonString);
json.writeStartObject();
json.writeStringField("type", "HystrixConfig");
json.writeObjectFieldStart("commands");
for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig().entrySet()) {
final HystrixCommandKey key = entry.getKey();
final HystrixCommandConfiguration commandConfig = entry.getValue();
writeCommandConfigJson(json, key, commandConfig);
}
json.writeEndObject();
json.writeObjectFieldStart("threadpools");
for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> entry : config.getThreadPoolConfig().entrySet()) {
final HystrixThreadPoolKey threadPoolKey = entry.getKey();
final HystrixThreadPoolConfiguration threadPoolConfig = entry.getValue();
writeThreadPoolConfigJson(json, threadPoolKey, threadPoolConfig);
}
json.writeEndObject();
json.writeObjectFieldStart("collapsers");
for (Map.Entry<HystrixCollapserKey, HystrixCollapserConfiguration> entry : config.getCollapserConfig().entrySet()) {
final HystrixCollapserKey collapserKey = entry.getKey();
final HystrixCollapserConfiguration collapserConfig = entry.getValue();
writeCollapserConfigJson(json, collapserKey, collapserConfig);
}
json.writeEndObject();
json.writeEndObject();
json.close();
return jsonString.getBuffer().toString();
}
use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.
the class RollingCollapserBatchSizeDistributionStreamTest method testEmptyStreamProducesEmptyDistributions.
@Test
public void testEmptyStreamProducesEmptyDistributions() {
HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("Collapser-Batch-Size-A");
stream = RollingCollapserBatchSizeDistributionStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().skip(10).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());
}
use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.
the class RollingCollapserEventCounterStreamTest method testEmptyStreamProducesZeros.
@Test
public void testEmptyStreamProducesZeros() {
HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("RollingCollapser-A");
stream = RollingCollapserEventCounterStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
try {
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
} catch (InterruptedException ex) {
fail("Interrupted ex");
}
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
assertEquals(0, stream.getLatest(HystrixEventType.Collapser.ADDED_TO_BATCH));
assertEquals(0, stream.getLatest(HystrixEventType.Collapser.BATCH_EXECUTED));
assertEquals(0, stream.getLatest(HystrixEventType.Collapser.RESPONSE_FROM_CACHE));
}
use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.
the class RollingCollapserEventCounterStreamTest method testCollapsedAndResponseFromCacheAgeOutOfRollingWindow.
//by doing a take(30), we expect all values to return to 0 as they age out of rolling window
@Test
public void testCollapsedAndResponseFromCacheAgeOutOfRollingWindow() {
HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("RollingCollapser-D");
stream = RollingCollapserEventCounterStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(30).subscribe(getSubscriber(latch));
for (int i = 0; i < 3; i++) {
CommandStreamTest.Collapser.from(key, i).observe();
//same arg - should get a response from cache
CommandStreamTest.Collapser.from(key, i).observe();
//same arg - should get a response from cache
CommandStreamTest.Collapser.from(key, i).observe();
}
try {
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
} catch (InterruptedException ex) {
fail("Interrupted ex");
}
assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
long[] expected = new long[HystrixEventType.Collapser.values().length];
expected[HystrixEventType.Collapser.BATCH_EXECUTED.ordinal()] = 0;
expected[HystrixEventType.Collapser.ADDED_TO_BATCH.ordinal()] = 0;
expected[HystrixEventType.Collapser.RESPONSE_FROM_CACHE.ordinal()] = 0;
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertArrayEquals(expected, stream.getLatest());
}
use of com.netflix.hystrix.HystrixCollapserKey in project Hystrix by Netflix.
the class CumulativeCollapserEventCounterStreamTest method testCollapsedAndResponseFromCache.
@Test
public void testCollapsedAndResponseFromCache() {
HystrixCollapserKey key = HystrixCollapserKey.Factory.asKey("CumulativeCollapser-C");
stream = CumulativeCollapserEventCounterStream.getInstance(key, 10, 100);
stream.startCachingStreamValuesIfUnstarted();
final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
for (int i = 0; i < 3; i++) {
CommandStreamTest.Collapser.from(key, i).observe();
//same arg - should get a response from cache
CommandStreamTest.Collapser.from(key, i).observe();
//same arg - should get a response from cache
CommandStreamTest.Collapser.from(key, i).observe();
}
try {
assertTrue(latch.await(10000, TimeUnit.MILLISECONDS));
} catch (InterruptedException ex) {
fail("Interrupted ex");
}
assertEquals(HystrixEventType.Collapser.values().length, stream.getLatest().length);
long[] expected = new long[HystrixEventType.Collapser.values().length];
expected[HystrixEventType.Collapser.BATCH_EXECUTED.ordinal()] = 1;
expected[HystrixEventType.Collapser.ADDED_TO_BATCH.ordinal()] = 3;
expected[HystrixEventType.Collapser.RESPONSE_FROM_CACHE.ordinal()] = 6;
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertArrayEquals(expected, stream.getLatest());
}
Aggregations