use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testTwoRequestsWithValuesForWrongArgs.
@Test
public void testTwoRequestsWithValuesForWrongArgs() {
TestCollapserTimer timer = new TestCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 3, false, false, map1To3And2To2, onMissingError);
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 3, false, false, map1To3And2To2, onMissingError);
System.out.println("Starting to observe collapser1");
Observable<String> result1 = collapser1.observe();
Observable<String> result2 = collapser2.observe();
// let time pass that equals the default delay/period
timer.incrementTime(10);
TestSubscriber<String> testSubscriber1 = new TestSubscriber<String>();
result1.subscribe(testSubscriber1);
TestSubscriber<String> testSubscriber2 = new TestSubscriber<String>();
result2.subscribe(testSubscriber2);
testSubscriber1.awaitTerminalEvent();
testSubscriber2.awaitTerminalEvent();
testSubscriber1.assertError(RuntimeException.class);
testSubscriber1.assertNoValues();
testSubscriber2.assertCompleted();
testSubscriber2.assertNoErrors();
testSubscriber2.assertValues("2:2", "2:4", "2:6");
}
use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testEarlyUnsubscribeExecutedViaObserve.
@Test
public void testEarlyUnsubscribeExecutedViaObserve() throws Exception {
TestCollapserTimer timer = new TestCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestRequestCollapser(timer, 1);
Observable<String> response1 = collapser1.observe();
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestRequestCollapser(timer, 2);
Observable<String> response2 = collapser2.observe();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final AtomicReference<String> value1 = new AtomicReference<String>(null);
final AtomicReference<String> value2 = new AtomicReference<String>(null);
Subscription s1 = response1.doOnUnsubscribe(new Action0() {
@Override
public void call() {
System.out.println(System.currentTimeMillis() + " : s1 Unsubscribed!");
latch1.countDown();
}
}).subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
System.out.println(System.currentTimeMillis() + " : s1 OnCompleted");
latch1.countDown();
}
@Override
public void onError(Throwable e) {
System.out.println(System.currentTimeMillis() + " : s1 OnError : " + e);
latch1.countDown();
}
@Override
public void onNext(String s) {
System.out.println(System.currentTimeMillis() + " : s1 OnNext : " + s);
value1.set(s);
}
});
Subscription s2 = response2.doOnUnsubscribe(new Action0() {
@Override
public void call() {
System.out.println(System.currentTimeMillis() + " : s2 Unsubscribed!");
latch2.countDown();
}
}).subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
System.out.println(System.currentTimeMillis() + " : s2 OnCompleted");
latch2.countDown();
}
@Override
public void onError(Throwable e) {
System.out.println(System.currentTimeMillis() + " : s2 OnError : " + e);
latch2.countDown();
}
@Override
public void onNext(String s) {
System.out.println(System.currentTimeMillis() + " : s2 OnNext : " + s);
value2.set(s);
}
});
s1.unsubscribe();
// let time pass that equals the default delay/period
timer.incrementTime(10);
assertTrue(latch1.await(1000, TimeUnit.MILLISECONDS));
assertTrue(latch2.await(1000, TimeUnit.MILLISECONDS));
assertNull(value1.get());
assertEquals("2", value2.get());
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixCollapserMetrics metrics = collapser1.getMetrics();
assertSame(metrics, collapser2.getMetrics());
HystrixInvokableInfo<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
//1 should have been removed from batch
assertEquals(1, command.getNumberCollapsed());
}
use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testTwoRequestsWithEmptyResponseAndOnMissingComplete.
@Test
public void testTwoRequestsWithEmptyResponseAndOnMissingComplete() {
TestCollapserTimer timer = new TestCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 0, onMissingComplete);
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 0, onMissingComplete);
System.out.println("Starting to observe collapser1");
Observable<String> result1 = collapser1.observe();
Observable<String> result2 = collapser2.observe();
// let time pass that equals the default delay/period
timer.incrementTime(10);
TestSubscriber<String> testSubscriber1 = new TestSubscriber<String>();
result1.subscribe(testSubscriber1);
TestSubscriber<String> testSubscriber2 = new TestSubscriber<String>();
result2.subscribe(testSubscriber2);
testSubscriber1.awaitTerminalEvent();
testSubscriber2.awaitTerminalEvent();
testSubscriber1.assertCompleted();
testSubscriber1.assertNoErrors();
testSubscriber1.assertNoValues();
testSubscriber2.assertCompleted();
testSubscriber2.assertNoErrors();
testSubscriber2.assertNoValues();
}
use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testTwoRequestsWithEmptyResponseAndOnMissingThrow.
@Test
public void testTwoRequestsWithEmptyResponseAndOnMissingThrow() {
TestCollapserTimer timer = new TestCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 0, onMissingThrow);
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 0, onMissingThrow);
System.out.println("Starting to observe collapser1");
Observable<String> result1 = collapser1.observe();
Observable<String> result2 = collapser2.observe();
// let time pass that equals the default delay/period
timer.incrementTime(10);
TestSubscriber<String> testSubscriber1 = new TestSubscriber<String>();
result1.subscribe(testSubscriber1);
TestSubscriber<String> testSubscriber2 = new TestSubscriber<String>();
result2.subscribe(testSubscriber2);
testSubscriber1.awaitTerminalEvent();
testSubscriber2.awaitTerminalEvent();
testSubscriber1.assertError(RuntimeException.class);
testSubscriber1.assertNoValues();
testSubscriber2.assertError(RuntimeException.class);
testSubscriber2.assertNoValues();
}
use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.
the class HystrixObservableCollapserTest method testTwoRequestsWithErrorProducingBatchCommand.
@Test
public void testTwoRequestsWithErrorProducingBatchCommand() {
TestCollapserTimer timer = new TestCollapserTimer();
HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 3, true);
HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 3, true);
System.out.println("Starting to observe collapser1");
Observable<String> result1 = collapser1.observe();
Observable<String> result2 = collapser2.observe();
// let time pass that equals the default delay/period
timer.incrementTime(10);
TestSubscriber<String> testSubscriber1 = new TestSubscriber<String>();
result1.subscribe(testSubscriber1);
TestSubscriber<String> testSubscriber2 = new TestSubscriber<String>();
result2.subscribe(testSubscriber2);
testSubscriber1.awaitTerminalEvent();
testSubscriber2.awaitTerminalEvent();
testSubscriber1.assertError(RuntimeException.class);
testSubscriber1.assertNoValues();
testSubscriber2.assertError(RuntimeException.class);
testSubscriber2.assertNoValues();
}
Aggregations