use of com.netflix.hystrix.collapser.CollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testTwoRequestsWhichShouldEachEmitTwice.
@Test
public void testTwoRequestsWhichShouldEachEmitTwice() throws Exception {
// TestCollapserTimer timer = new TestCollapserTimer();
CollapserTimer timer = new RealCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 3, false, false, prefixMapper, onMissingComplete);
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 3, false, false, prefixMapper, onMissingComplete);
TestSubscriber<String> testSubscriber1 = new TestSubscriber<String>();
TestSubscriber<String> testSubscriber2 = new TestSubscriber<String>();
System.out.println(System.currentTimeMillis() + "Starting to observe collapser1");
collapser1.observe().subscribe(testSubscriber1);
collapser2.observe().subscribe(testSubscriber2);
System.out.println(System.currentTimeMillis() + "Done with collapser observe()s");
// Note that removing these awaits breaks the unit test. That implies that the above subscribe does not wait for a terminal event
testSubscriber1.awaitTerminalEvent();
testSubscriber2.awaitTerminalEvent();
testSubscriber1.assertCompleted();
testSubscriber1.assertNoErrors();
testSubscriber1.assertValues("1:1", "1:2", "1:3");
testSubscriber2.assertCompleted();
testSubscriber2.assertNoErrors();
testSubscriber2.assertValues("2:2", "2:4", "2:6");
}
use of com.netflix.hystrix.collapser.CollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testCollapserUnderConcurrency.
@Test
public void testCollapserUnderConcurrency() throws InterruptedException {
final CollapserTimer timer = new RealCollapserTimer();
final int NUM_THREADS_SUBMITTING_WORK = 8;
final int NUM_REQUESTS_PER_THREAD = 8;
final CountDownLatch latch = new CountDownLatch(NUM_THREADS_SUBMITTING_WORK);
List<Runnable> runnables = new ArrayList<Runnable>();
final ConcurrentLinkedQueue<TestSubscriber<String>> subscribers = new ConcurrentLinkedQueue<TestSubscriber<String>>();
HystrixRequestContext context = HystrixRequestContext.initializeContext();
final AtomicInteger uniqueInt = new AtomicInteger(0);
for (int i = 0; i < NUM_THREADS_SUBMITTING_WORK; i++) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
for (int j = 0; j < NUM_REQUESTS_PER_THREAD; j++) {
HystrixObservableCollapser<String, String, String, String> collapser = new TestCollapserWithMultipleResponses(timer, uniqueInt.getAndIncrement(), 3, false);
Observable<String> o = collapser.toObservable();
TestSubscriber<String> subscriber = new TestSubscriber<String>();
o.subscribe(subscriber);
subscribers.offer(subscriber);
}
// System.out.println("Runnable done on thread : " + Thread.currentThread().getName());
} finally {
latch.countDown();
}
}
});
}
for (Runnable r : runnables) {
threadPool.submit(new HystrixContextRunnable(r));
}
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
for (TestSubscriber<String> subscriber : subscribers) {
subscriber.awaitTerminalEvent();
if (subscriber.getOnErrorEvents().size() > 0) {
System.out.println("ERROR : " + subscriber.getOnErrorEvents());
for (Throwable ex : subscriber.getOnErrorEvents()) {
ex.printStackTrace();
}
}
subscriber.assertCompleted();
subscriber.assertNoErrors();
System.out.println("Received : " + subscriber.getOnNextEvents());
subscriber.assertValueCount(3);
}
context.shutdown();
}
use of com.netflix.hystrix.collapser.CollapserTimer in project Hystrix by Netflix.
the class HystrixCollapserTest method testVoidResponseTypeFireAndForgetCollapsing3.
/**
* Test a Void response type with execute - response being set in mapResponseToRequest to null
*
* @throws Exception
*/
@Test
public void testVoidResponseTypeFireAndForgetCollapsing3() throws Exception {
CollapserTimer timer = new RealCollapserTimer();
TestCollapserWithVoidResponseType collapser1 = new TestCollapserWithVoidResponseType(timer, 1);
assertNull(collapser1.execute());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
Iterator<HystrixInvokableInfo<?>> cmdIterator = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator();
assertEquals(1, cmdIterator.next().getNumberCollapsed());
}
Aggregations