use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableTimeoutWithSelectorTest method timeoutSelectorNormal1.
@Test
public void timeoutSelectorNormal1() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> timeout = PublishSubject.create();
Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return timeout;
}
};
Observable<Integer> other = Observable.fromIterable(Arrays.asList(100));
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.timeout(timeout, timeoutFunc, other).subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
timeout.onNext(1);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(2);
inOrder.verify(o).onNext(3);
inOrder.verify(o).onNext(100);
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableWindowWithTimeTest method exactTimeBoundNoInterruptWindowOutputOnError.
@Test
@SuppressUndeliverable
public void exactTimeBoundNoInterruptWindowOutputOnError() throws Exception {
final AtomicBoolean isInterrupted = new AtomicBoolean();
final PublishSubject<Integer> ps = PublishSubject.create();
final CountDownLatch doOnNextDone = new CountDownLatch(1);
final CountDownLatch secondWindowProcessing = new CountDownLatch(1);
ps.window(100, TimeUnit.MILLISECONDS).doOnNext(new Consumer<Observable<Integer>>() {
int count;
@Override
public void accept(Observable<Integer> v) throws Exception {
System.out.println(Thread.currentThread());
if (count++ == 1) {
secondWindowProcessing.countDown();
try {
Thread.sleep(200);
isInterrupted.set(Thread.interrupted());
} catch (InterruptedException ex) {
isInterrupted.set(true);
}
doOnNextDone.countDown();
}
}
}).test();
ps.onNext(1);
assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS));
ps.onError(new TestException());
assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS));
assertFalse("The doOnNext got interrupted!", isInterrupted.get());
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableWindowWithTimeTest method exactOnError.
@Test
@SuppressUndeliverable
public void exactOnError() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> ps = PublishSubject.create();
TestObserver<Integer> to = ps.window(1, 1, TimeUnit.SECONDS, scheduler).flatMap(Functions.<Observable<Integer>>identity()).test();
ps.onError(new TestException());
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableWindowWithTimeTest method exactTimeAndSizeBoundNoInterruptWindowOutputOnError.
@Test
@SuppressUndeliverable
public void exactTimeAndSizeBoundNoInterruptWindowOutputOnError() throws Exception {
final AtomicBoolean isInterrupted = new AtomicBoolean();
final PublishSubject<Integer> ps = PublishSubject.create();
final CountDownLatch doOnNextDone = new CountDownLatch(1);
final CountDownLatch secondWindowProcessing = new CountDownLatch(1);
ps.window(100, TimeUnit.MILLISECONDS, 10).doOnNext(new Consumer<Observable<Integer>>() {
int count;
@Override
public void accept(Observable<Integer> v) throws Exception {
System.out.println(Thread.currentThread());
if (count++ == 1) {
secondWindowProcessing.countDown();
try {
Thread.sleep(200);
isInterrupted.set(Thread.interrupted());
} catch (InterruptedException ex) {
isInterrupted.set(true);
}
doOnNextDone.countDown();
}
}
}).test();
ps.onNext(1);
assertTrue(secondWindowProcessing.await(5, TimeUnit.SECONDS));
ps.onError(new TestException());
assertTrue(doOnNextDone.await(5, TimeUnit.SECONDS));
assertFalse("The doOnNext got interrupted!", isInterrupted.get());
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableWithLatestFromTest method simple.
@Test
public void simple() {
PublishSubject<Integer> source = PublishSubject.create();
PublishSubject<Integer> other = PublishSubject.create();
Observer<Integer> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
Observable<Integer> result = source.withLatestFrom(other, COMBINER);
result.subscribe(o);
source.onNext(1);
inOrder.verify(o, never()).onNext(anyInt());
other.onNext(1);
inOrder.verify(o, never()).onNext(anyInt());
source.onNext(2);
inOrder.verify(o).onNext((2 << 8) + 1);
other.onNext(2);
inOrder.verify(o, never()).onNext(anyInt());
other.onComplete();
inOrder.verify(o, never()).onComplete();
source.onNext(3);
inOrder.verify(o).onNext((3 << 8) + 2);
source.onComplete();
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
Aggregations