use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class SingleFlattenStreamAsFlowableTest method requestOneByOne.
@Test
public void requestOneByOne() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
Single.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {
Subscription upstream;
@Override
public void onSubscribe(@NonNull Subscription s) {
ts.onSubscribe(new BooleanSubscription());
upstream = s;
s.request(1);
}
@Override
public void onNext(Integer t) {
ts.onNext(t);
upstream.request(1);
}
@Override
public void onError(Throwable t) {
ts.onError(t);
}
@Override
public void onComplete() {
ts.onComplete();
}
});
ts.assertResult(1, 2, 3, 4, 5);
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onSuccessCrash.
@Test
public void onSuccessCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onSuccess(any());
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onSuccess(1);
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onSuccess(1);
order.verifyNoMoreInteractions();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
});
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onSubscribe(any());
Disposable d = Disposable.empty();
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
observer.onSubscribe(d);
// none of the following should arrive at the consumer
observer.onSuccess(1);
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verifyNoMoreInteractions();
assertTrue(d.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertUndeliverable(errors, 1, IOException.class);
});
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class ParallelMapTest method conditionalCancelIgnored.
@Test
public void conditionalCancelIgnored() {
Flowable<Integer> f = new Flowable<Integer>() {
@Override
protected void subscribeActual(@NonNull Subscriber<@NonNull ? super @NonNull Integer> s) {
@SuppressWarnings("unchecked") ConditionalSubscriber<Integer> subscriber = (ConditionalSubscriber<Integer>) s;
subscriber.onSubscribe(new BooleanSubscription());
subscriber.tryOnNext(1);
subscriber.tryOnNext(2);
}
};
ParallelFlowable.fromArray(f).map(v -> {
throw new TestException();
}).filter(v -> true).sequential().test().assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.
the class Scheduler method schedulePeriodicallyDirect.
/**
* Schedules a periodic execution of the given task with the given initial time delay and repeat period.
*
* <p>
* This method is safe to be called from multiple threads but there are no
* ordering guarantees between tasks.
*
* <p>
* The periodic execution is at a fixed rate, that is, the first execution will be after the
* {@code initialDelay}, the second after {@code initialDelay + period}, the third after
* {@code initialDelay + 2 * period}, and so on.
*
* @param run the task to schedule
* @param initialDelay the initial delay amount, non-positive values indicate non-delayed scheduling
* @param period the period at which the task should be re-executed
* @param unit the unit of measure of the delay amount
* @return the Disposable that let's one cancel this particular delayed task.
* @throws NullPointerException if {@code run} or {@code unit} is {@code null}
* @since 2.0
*/
@NonNull
public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, @NonNull TimeUnit unit) {
final Worker w = createWorker();
final Runnable decoratedRun = RxJavaPlugins.onSchedule(run);
PeriodicDirectTask periodicTask = new PeriodicDirectTask(decoratedRun, w);
Disposable d = w.schedulePeriodically(periodicTask, initialDelay, period, unit);
if (d == EmptyDisposable.INSTANCE) {
return d;
}
return periodicTask;
}
Aggregations