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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations