Search in sources :

Example 6 with TestSubscriber

use of rx.observers.TestSubscriber 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 7 with TestSubscriber

use of rx.observers.TestSubscriber 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 8 with TestSubscriber

use of rx.observers.TestSubscriber 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 9 with TestSubscriber

use of rx.observers.TestSubscriber 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");
}
Also used : RealCollapserTimer(com.netflix.hystrix.collapser.RealCollapserTimer) CollapserTimer(com.netflix.hystrix.collapser.CollapserTimer) TestCollapserTimer(com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer) RealCollapserTimer(com.netflix.hystrix.collapser.RealCollapserTimer) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 10 with TestSubscriber

use of rx.observers.TestSubscriber 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)

Aggregations

TestSubscriber (rx.observers.TestSubscriber)238 Test (org.junit.Test)213 Intent (android.content.Intent)48 Environment (com.kickstarter.libs.Environment)43 Cursor (android.database.Cursor)36 Changes (com.pushtorefresh.storio.contentresolver.Changes)34 Project (com.kickstarter.models.Project)33 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)21 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 TargetApi (android.annotation.TargetApi)18 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)18 StorIOException (com.pushtorefresh.storio.StorIOException)17 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)16 Matchers.anyString (org.mockito.Matchers.anyString)16 User (com.kickstarter.models.User)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 Uri (android.net.Uri)14 NonNull (android.support.annotation.NonNull)14