use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableDelayThrows.
@Test
public void delayWithObservableDelayThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
delay.onError(new TestException());
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableAsTimed.
@Test
public void delayWithObservableAsTimed() {
Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3);
final Observable<Long> delayer = Observable.timer(500L, TimeUnit.MILLISECONDS, scheduler);
Function<Long, Observable<Long>> delayFunc = new Function<Long, Observable<Long>>() {
@Override
public Observable<Long> apply(Long t1) {
return delayer;
}
};
Observable<Long> delayed = source.delay(delayFunc);
delayed.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS);
verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(0L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(1L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(2L);
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableDelayFunctionThrows.
@Test
public void delayWithObservableDelayFunctionThrows() {
PublishSubject<Integer> source = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
throw new TestException();
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableFromSupplierTest method shouldNotDeliverResultIfSubscriberUnsubscribedBeforeEmission.
@SuppressWarnings("unchecked")
@Test
public void shouldNotDeliverResultIfSubscriberUnsubscribedBeforeEmission() throws Throwable {
Supplier<String> func = mock(Supplier.class);
final CountDownLatch funcLatch = new CountDownLatch(1);
final CountDownLatch observerLatch = new CountDownLatch(1);
when(func.get()).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
observerLatch.countDown();
try {
funcLatch.await();
} catch (InterruptedException e) {
// It's okay, unsubscription causes Thread interruption
// Restoring interruption status of the Thread
Thread.currentThread().interrupt();
}
return "should_not_be_delivered";
}
});
Observable<String> fromSupplierObservable = Observable.fromSupplier(func);
Observer<Object> observer = TestHelper.mockObserver();
TestObserver<String> outer = new TestObserver<>(observer);
fromSupplierObservable.subscribeOn(Schedulers.computation()).subscribe(outer);
// Wait until func will be invoked
observerLatch.await();
// Unsubscribing before emission
outer.dispose();
// Emitting result
funcLatch.countDown();
// func must be invoked
verify(func).get();
// Observer must not be notified at all
verify(observer).onSubscribe(any(Disposable.class));
verifyNoMoreInteractions(observer);
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableBufferTest method openCloseBadClose.
@Test
public void openCloseBadClose() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Observable.never().buffer(Observable.just(1).concatWith(Observable.<Integer>never()), Functions.justFunction(new Observable<Object>() {
@Override
protected void subscribeActual(Observer<? super Object> observer) {
assertFalse(((Disposable) observer).isDisposed());
Disposable bs1 = Disposable.empty();
Disposable bs2 = Disposable.empty();
observer.onSubscribe(bs1);
assertFalse(bs1.isDisposed());
assertFalse(bs2.isDisposed());
observer.onSubscribe(bs2);
assertFalse(bs1.isDisposed());
assertTrue(bs2.isDisposed());
observer.onError(new IOException());
assertTrue(((Disposable) observer).isDisposed());
observer.onComplete();
observer.onNext(1);
observer.onError(new TestException());
}
})).test().assertFailure(IOException.class);
TestHelper.assertError(errors, 0, ProtocolViolationException.class);
TestHelper.assertUndeliverable(errors, 1, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations