use of io.reactivex.rxjava3.subscribers.SerializedSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method startOnce.
@Test
public void startOnce() {
List<Throwable> error = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = new TestSubscriber<>();
final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
so.onSubscribe(new BooleanSubscription());
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
assertTrue(bs.isCancelled());
TestHelper.assertError(error, 0, IllegalStateException.class, "Subscription already set!");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.subscribers.SerializedSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method onCompleteRace.
@Test
public void onCompleteRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestSubscriber<Integer> ts = new TestSubscriber<>();
final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
Runnable r = new Runnable() {
@Override
public void run() {
so.onComplete();
}
};
TestHelper.race(r, r);
ts.awaitDone(5, TimeUnit.SECONDS).assertResult();
}
}
use of io.reactivex.rxjava3.subscribers.SerializedSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method onNextOnCompleteRace.
@Test
public void onNextOnCompleteRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestSubscriber<Integer> ts = new TestSubscriber<>();
final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onComplete();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.onNext(1);
}
};
TestHelper.race(r1, r2);
ts.awaitDone(5, TimeUnit.SECONDS).assertNoErrors().assertComplete();
assertTrue(ts.values().size() <= 1);
}
}
use of io.reactivex.rxjava3.subscribers.SerializedSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method onCompleteOnErrorRace.
@Test
public void onCompleteOnErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
final Throwable ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.onComplete();
}
};
TestHelper.race(r1, r2);
ts.awaitDone(5, TimeUnit.SECONDS);
if (ts.completions() != 0) {
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} else {
ts.assertFailure(TestException.class).assertError(ex);
assertTrue("" + errors, errors.isEmpty());
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.subscribers.SerializedSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method nullOnNext.
@Test
public void nullOnNext() {
TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
so.onSubscribe(new BooleanSubscription());
so.onNext(null);
ts.assertFailureAndMessage(NullPointerException.class, ExceptionHelper.nullWarning("onNext called with a null value."));
}
Aggregations