Search in sources :

Example 11 with BooleanSubscription

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());
    }
}
Also used : TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Example 12 with BooleanSubscription

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();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 13 with BooleanSubscription

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");
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 14 with BooleanSubscription

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());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 15 with BooleanSubscription

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());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)227 Test (org.junit.Test)152 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)81 TestException (io.reactivex.rxjava3.exceptions.TestException)40 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)32 IOException (java.io.IOException)26 InOrder (org.mockito.InOrder)19 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)12 Subscriber (org.reactivestreams.Subscriber)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Assert (org.junit.Assert)10 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)8 Functions (io.reactivex.rxjava3.internal.functions.Functions)8 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)8 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)8 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)8 java.util (java.util)8