Search in sources :

Example 86 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableTakeTimedTest method takeTimedErrorBeforeTime.

@Test
public void takeTimedErrorBeforeTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    result.subscribe(subscriber);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onError(new TestException());
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.onNext(4);
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(2);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onNext(4);
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 87 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableTakeUntilTest method untilPublisherMainError.

@Test
public void untilPublisherMainError() {
    PublishProcessor<Integer> main = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestSubscriber<Integer> ts = main.takeUntil(other).test();
    assertTrue("Main no subscribers?", main.hasSubscribers());
    assertTrue("Other no subscribers?", other.hasSubscribers());
    main.onError(new TestException());
    assertFalse("Main has subscribers?", main.hasSubscribers());
    assertFalse("Other has subscribers?", other.hasSubscribers());
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 88 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableThrottleFirstTest method throttle.

@Test
public void throttle() {
    Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
    TestScheduler s = new TestScheduler();
    PublishProcessor<Integer> o = PublishProcessor.create();
    o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
    // send events with simulated time increments
    s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    // deliver
    o.onNext(1);
    // skip
    o.onNext(2);
    s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
    // deliver
    o.onNext(3);
    s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(4);
    s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
    // skip
    o.onNext(5);
    // skip
    o.onNext(6);
    s.advanceTimeTo(1001, TimeUnit.MILLISECONDS);
    // deliver
    o.onNext(7);
    s.advanceTimeTo(1501, TimeUnit.MILLISECONDS);
    o.onComplete();
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onNext(7);
    inOrder.verify(subscriber).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 89 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableThrottleLatestTest method normalEmitLast.

@Test
public void normalEmitLast() {
    TestScheduler sch = new TestScheduler();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch, true).test();
    pp.onNext(1);
    ts.assertValuesOnly(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onNext(3);
    ts.assertValuesOnly(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3);
    pp.onNext(4);
    ts.assertValuesOnly(1, 3);
    pp.onNext(5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    pp.onNext(6);
    ts.assertValuesOnly(1, 3, 5, 6);
    pp.onNext(7);
    pp.onComplete();
    ts.assertResult(1, 3, 5, 6, 7);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 3, 5, 6, 7);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 90 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableThrottleLatestTest method normal.

@Test
public void normal() {
    TestScheduler sch = new TestScheduler();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch).test();
    pp.onNext(1);
    ts.assertValuesOnly(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onNext(3);
    ts.assertValuesOnly(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3);
    pp.onNext(4);
    ts.assertValuesOnly(1, 3);
    pp.onNext(5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertValuesOnly(1, 3, 5);
    pp.onNext(6);
    ts.assertValuesOnly(1, 3, 5, 6);
    pp.onNext(7);
    pp.onComplete();
    ts.assertResult(1, 3, 5, 6);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 3, 5, 6);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)124 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)25 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)24 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)18 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)18 Disposable (io.reactivex.rxjava3.disposables.Disposable)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Assert (org.junit.Assert)8 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)6 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)6 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)6 IOException (java.io.IOException)6 TimeUnit (java.util.concurrent.TimeUnit)6 Functions (io.reactivex.rxjava3.internal.functions.Functions)5 FlowableReplay (io.reactivex.rxjava3.internal.operators.flowable.FlowableReplay)4 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)4 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)4