use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableSubscriberTest method forEachWhile.
@Test
public void forEachWhile() {
PublishProcessor<Integer> pp = PublishProcessor.create();
final List<Integer> list = new ArrayList<>();
Disposable d = pp.forEachWhile(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
list.add(v);
return v < 3;
}
});
assertFalse(d.isDisposed());
pp.onNext(1);
pp.onNext(2);
pp.onNext(3);
assertFalse(pp.hasSubscribers());
assertEquals(Arrays.asList(1, 2, 3), list);
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableThrottleLastTests method throttle.
@Test
public void throttle() {
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// skip
o.onNext(1);
// deliver
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// skip
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// deliver
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(2);
inOrder.verify(subscriber).onNext(6);
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 FlowableThrottleWithTimeoutTests method throttle.
@Test
public void throttle() {
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// skip
o.onNext(1);
// deliver
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// skip
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// deliver at 1300 after 500ms has passed since onNext(5)
o.onNext(6);
s.advanceTimeTo(1300, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1800, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(6);
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 FlowableReplayTest method disposeNoNeedForResetTimeBound.
@Test
public void disposeNoNeedForResetTimeBound() {
PublishProcessor<Integer> pp = PublishProcessor.create();
ConnectableFlowable<Integer> cf = pp.replay(10, TimeUnit.MINUTES);
TestSubscriber<Integer> ts = cf.test();
Disposable d = cf.connect();
pp.onNext(1);
d.dispose();
ts = cf.test();
ts.assertEmpty();
cf.connect();
ts.assertEmpty();
pp.onNext(2);
ts.assertValuesOnly(2);
}
use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableReplayTest method disposeNoNeedForReset.
@Test
public void disposeNoNeedForReset() {
PublishProcessor<Integer> pp = PublishProcessor.create();
ConnectableFlowable<Integer> cf = pp.replay();
TestSubscriber<Integer> ts = cf.test();
Disposable d = cf.connect();
pp.onNext(1);
d.dispose();
ts = cf.test();
ts.assertEmpty();
cf.connect();
ts.assertEmpty();
pp.onNext(2);
ts.assertValuesOnly(2);
}
Aggregations