Search in sources :

Example 1 with TestCollapserTimer

use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.

the class HystrixObservableCollapserTest method testTwoRequestsWithValuesForOneArgOnlyAndOnMissingComplete.

@Test
public void testTwoRequestsWithValuesForOneArgOnlyAndOnMissingComplete() {
    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, 5, 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.assertValues("2:2", "2:4", "2:6", "2:8", "2:10");
}
Also used : TestSubscriber(rx.observers.TestSubscriber) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) Test(org.junit.Test)

Example 2 with TestCollapserTimer

use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.

the class HystrixObservableCollapserTest method testTwoRequestsWhenBatchCommandFails.

@Test
public void testTwoRequestsWhenBatchCommandFails() {
    TestCollapserTimer timer = new TestCollapserTimer();
    HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 3, false, true, map1To3And2To2, onMissingError);
    HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 3, false, true, 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.getOnErrorEvents().get(0).printStackTrace();
    testSubscriber1.assertNoValues();
    testSubscriber2.assertError(RuntimeException.class);
    testSubscriber2.assertNoValues();
}
Also used : TestSubscriber(rx.observers.TestSubscriber) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) Test(org.junit.Test)

Example 3 with TestCollapserTimer

use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.

the class HystrixObservableCollapserTest method testTwoRequestsWithValuesForOneArgOnlyAndOnMissingFillInStaticValue.

@Test
public void testTwoRequestsWithValuesForOneArgOnlyAndOnMissingFillInStaticValue() {
    TestCollapserTimer timer = new TestCollapserTimer();
    HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 0, onMissingFillIn);
    HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 5, onMissingFillIn);
    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.assertValues("fillin");
    testSubscriber2.assertCompleted();
    testSubscriber2.assertNoErrors();
    testSubscriber2.assertValues("2:2", "2:4", "2:6", "2:8", "2:10");
}
Also used : TestSubscriber(rx.observers.TestSubscriber) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) Test(org.junit.Test)

Example 4 with TestCollapserTimer

use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.

the class HystrixObservableCollapserTest method testTwoRequestsWithValuesForOneArgOnlyAndOnMissingThrow.

@Test
public void testTwoRequestsWithValuesForOneArgOnlyAndOnMissingThrow() {
    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, 5, 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.assertCompleted();
    testSubscriber2.assertNoErrors();
    testSubscriber2.assertValues("2:2", "2:4", "2:6", "2:8", "2:10");
}
Also used : TestSubscriber(rx.observers.TestSubscriber) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) Test(org.junit.Test)

Example 5 with TestCollapserTimer

use of com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer in project Hystrix by Netflix.

the class HystrixObservableCollapserTest method testTwoRequestsWithValuesForOneArgOnlyAndOnMissingError.

@Test
public void testTwoRequestsWithValuesForOneArgOnlyAndOnMissingError() {
    TestCollapserTimer timer = new TestCollapserTimer();
    HystrixObservableCollapser<String, String, String, String> collapser1 = new TestCollapserWithMultipleResponses(timer, 1, 0, onMissingError);
    HystrixObservableCollapser<String, String, String, String> collapser2 = new TestCollapserWithMultipleResponses(timer, 2, 5, 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(IllegalStateException.class);
    testSubscriber1.assertNoValues();
    testSubscriber2.assertCompleted();
    testSubscriber2.assertNoErrors();
    testSubscriber2.assertValues("2:2", "2:4", "2:6", "2:8", "2:10");
}
Also used : TestSubscriber(rx.observers.TestSubscriber) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) Test(org.junit.Test)

Aggregations

TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)23 Test (org.junit.Test)23 TestSubscriber (rx.observers.TestSubscriber)15 CountDownLatch (java.util.concurrent.CountDownLatch)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Subscription (rx.Subscription)7 Action0 (rx.functions.Action0)7 CollapserTimer (com.netflix.hystrix.collapser.CollapserTimer)1 RealCollapserTimer (com.netflix.hystrix.collapser.RealCollapserTimer)1