Search in sources :

Example 51 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableReplayTest method testTimedAndSizedTruncationError.

@Test
public void testTimedAndSizedTruncationError() {
    TestScheduler test = new TestScheduler();
    SizeAndTimeBoundReplayBuffer<Integer> buf = new SizeAndTimeBoundReplayBuffer<Integer>(2, 2000, TimeUnit.MILLISECONDS, test);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertFalse(buf.hasError());
    List<Integer> values = new ArrayList<Integer>();
    buf.next(1);
    test.advanceTimeBy(1, TimeUnit.SECONDS);
    buf.next(2);
    test.advanceTimeBy(1, TimeUnit.SECONDS);
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(2), values);
    buf.next(3);
    buf.next(4);
    values.clear();
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(3, 4), values);
    test.advanceTimeBy(2, TimeUnit.SECONDS);
    buf.next(5);
    values.clear();
    buf.collect(values);
    Assert.assertEquals(Arrays.asList(5), values);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertFalse(buf.hasError());
    test.advanceTimeBy(2, TimeUnit.SECONDS);
    buf.error(new TestException());
    values.clear();
    buf.collect(values);
    Assert.assertTrue(values.isEmpty());
    Assert.assertEquals(1, buf.size);
    Assert.assertFalse(buf.hasCompleted());
    Assert.assertTrue(buf.hasError());
}
Also used : TestException(io.reactivex.exceptions.TestException)

Example 52 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableReplayTest method connectConsumerThrows.

@Test
public void connectConsumerThrows() {
    ConnectableFlowable<Integer> co = Flowable.range(1, 2).replay();
    try {
        co.connect(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable t) throws Exception {
                throw new TestException();
            }
        });
        fail("Should have thrown");
    } catch (TestException ex) {
    // expected
    }
    co.test().assertEmpty().cancel();
    co.connect();
    co.test().assertResult(1, 2);
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestException(io.reactivex.exceptions.TestException) TestException(io.reactivex.exceptions.TestException)

Example 53 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableGroupByTest method errorFused.

@Test
public void errorFused() {
    TestSubscriber<Object> ts = SubscriberFusion.newTest(QueueSubscription.ANY);
    Flowable.error(new TestException()).groupBy(Functions.justFunction(1)).subscribe(ts);
    SubscriberFusion.assertFusion(ts, QueueSubscription.ASYNC).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 54 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableGroupByTest method errorFusedDelayed.

@Test
public void errorFusedDelayed() {
    TestSubscriber<Object> ts = SubscriberFusion.newTest(QueueSubscription.ANY);
    Flowable.error(new TestException()).groupBy(Functions.justFunction(1), true).subscribe(ts);
    SubscriberFusion.assertFusion(ts, QueueSubscription.ASYNC).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 55 with TestException

use of io.reactivex.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableIgnoreElementsTest method testErrorReceived.

@Test
public void testErrorReceived() {
    TestObserver<Object> ts = new TestObserver<Object>();
    TestException ex = new TestException("boo");
    Flowable.error(ex).ignoreElements().subscribe(ts);
    ts.assertNoValues();
    ts.assertTerminated();
    // FIXME no longer testable
    //        ts.assertUnsubscribed();
    ts.assertError(TestException.class);
    ts.assertErrorMessage("boo");
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.exceptions.TestException)417 Test (org.junit.Test)255 InOrder (org.mockito.InOrder)35 IOException (java.io.IOException)28 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)26 TestObserver (io.reactivex.observers.TestObserver)26 Observable (io.reactivex.Observable)24 Function (io.reactivex.functions.Function)24 TestSubscriber (io.reactivex.subscribers.TestSubscriber)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 TestScheduler (io.reactivex.schedulers.TestScheduler)11 Observer (io.reactivex.Observer)8 QueueDisposable (io.reactivex.internal.fuseable.QueueDisposable)8 Disposable (io.reactivex.disposables.Disposable)7 CrashingIterable (io.reactivex.internal.util.CrashingIterable)6 Action (io.reactivex.functions.Action)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)2 ScalarDisposable (io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2