use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class AbstractSchedulerTests method subscribeOnNestedConcurrency.
@Test
public final void subscribeOnNestedConcurrency() throws InterruptedException {
final Scheduler scheduler = getScheduler();
Flowable<String> f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten").flatMap(new Function<String, Flowable<String>>() {
@Override
public Flowable<String> apply(final String v) {
return Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext("value_after_map-" + v);
subscriber.onComplete();
}
}).subscribeOn(scheduler);
}
});
ConcurrentObserverValidator<String> observer = new ConcurrentObserverValidator<>();
f.subscribe(observer);
if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
if (observer.error.get() != null) {
observer.error.get().printStackTrace();
fail("Error: " + observer.error.get().getMessage());
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class TestSchedulerTest method nestedSchedule.
@Test
public final void nestedSchedule() {
final TestScheduler scheduler = new TestScheduler();
final Scheduler.Worker inner = scheduler.createWorker();
try {
final Runnable calledOp = mock(Runnable.class);
Flowable<Object> poller;
poller = Flowable.unsafeCreate(new Publisher<Object>() {
@Override
public void subscribe(final Subscriber<? super Object> aSubscriber) {
final BooleanSubscription bs = new BooleanSubscription();
aSubscriber.onSubscribe(bs);
inner.schedule(new Runnable() {
@Override
public void run() {
if (!bs.isCancelled()) {
calledOp.run();
inner.schedule(this, 5, TimeUnit.SECONDS);
}
}
});
}
});
InOrder inOrder = Mockito.inOrder(calledOp);
Disposable sub;
sub = poller.subscribe();
scheduler.advanceTimeTo(6, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(2)).run();
sub.dispose();
scheduler.advanceTimeTo(11, TimeUnit.SECONDS);
inOrder.verify(calledOp, never()).run();
sub = poller.subscribe();
scheduler.advanceTimeTo(12, TimeUnit.SECONDS);
inOrder.verify(calledOp, times(1)).run();
} finally {
inner.dispose();
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class SafeSubscriberTest method onNextFailureSafe.
@Test
public void onNextFailureSafe() {
AtomicReference<Throwable> onError = new AtomicReference<>();
try {
SafeSubscriber<String> safeObserver = new SafeSubscriber<>(OBSERVER_ONNEXT_FAIL(onError));
safeObserver.onSubscribe(new BooleanSubscription());
safeObserver.onNext("one");
assertNotNull(onError.get());
assertTrue(onError.get() instanceof SafeSubscriberTestException);
assertEquals("onNextFail", onError.get().getMessage());
} catch (Exception e) {
fail("expects exception to be passed to onError");
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class SafeSubscriberTest method dispose.
@Test
public void dispose() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
SafeSubscriber<Integer> so = new SafeSubscriber<>(ts);
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
ts.dispose();
assertTrue(bs.isCancelled());
// assertTrue(so.isDisposed());
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class BehaviorProcessorTest method onSubscribe.
@Test
public void onSubscribe() {
BehaviorProcessor<Object> p = BehaviorProcessor.create();
BooleanSubscription bs = new BooleanSubscription();
p.onSubscribe(bs);
assertFalse(bs.isCancelled());
p.onComplete();
bs = new BooleanSubscription();
p.onSubscribe(bs);
assertTrue(bs.isCancelled());
}
Aggregations