Search in sources :

Example 11 with io.reactivex.rxjava3.subscribers

use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.

the class ParallelRunOn method subscribe.

@Override
public void subscribe(Subscriber<? super T>[] subscribers) {
    subscribers = RxJavaPlugins.onSubscribe(this, subscribers);
    if (!validate(subscribers)) {
        return;
    }
    int n = subscribers.length;
    @SuppressWarnings("unchecked") final Subscriber<T>[] parents = new Subscriber[n];
    if (scheduler instanceof SchedulerMultiWorkerSupport) {
        SchedulerMultiWorkerSupport multiworker = (SchedulerMultiWorkerSupport) scheduler;
        multiworker.createWorkers(n, new MultiWorkerCallback(subscribers, parents));
    } else {
        for (int i = 0; i < n; i++) {
            createSubscriber(i, subscribers, parents, scheduler.createWorker());
        }
    }
    source.subscribe(parents);
}
Also used : ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) SchedulerMultiWorkerSupport(io.reactivex.rxjava3.internal.schedulers.SchedulerMultiWorkerSupport)

Example 12 with io.reactivex.rxjava3.subscribers

use of io.reactivex.rxjava3.subscribers in project RxRelay by JakeWharton.

the class PublishRelayTest method testReSubscribe.

/**
 * Should be able to unsubscribe all Subscribers, have it stop emitting, then subscribe new ones and it start emitting again.
 */
@Test
public void testReSubscribe() {
    final PublishRelay<Integer> ps = PublishRelay.create();
    Observer<Integer> o1 = TestHelper.mockObserver();
    TestObserver<Integer> ts = new TestObserver<Integer>(o1);
    ps.subscribe(ts);
    // emit
    ps.accept(1);
    // validate we got it
    InOrder inOrder1 = inOrder(o1);
    inOrder1.verify(o1, times(1)).onNext(1);
    inOrder1.verifyNoMoreInteractions();
    // unsubscribe
    ts.dispose();
    // emit again but nothing will be there to receive it
    ps.accept(2);
    Observer<Integer> o2 = TestHelper.mockObserver();
    TestObserver<Integer> ts2 = new TestObserver<Integer>(o2);
    ps.subscribe(ts2);
    // emit
    ps.accept(3);
    // validate we got it
    InOrder inOrder2 = inOrder(o2);
    inOrder2.verify(o2, times(1)).onNext(3);
    inOrder2.verifyNoMoreInteractions();
    ts2.dispose();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InOrder(org.mockito.InOrder) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 13 with io.reactivex.rxjava3.subscribers

use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.

the class FlowableTakeUntilTest method untilPublisherMainError.

@Test
public void untilPublisherMainError() {
    PublishProcessor<Integer> main = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestSubscriber<Integer> ts = main.takeUntil(other).test();
    assertTrue("Main no subscribers?", main.hasSubscribers());
    assertTrue("Other no subscribers?", other.hasSubscribers());
    main.onError(new TestException());
    assertFalse("Main has subscribers?", main.hasSubscribers());
    assertFalse("Other has subscribers?", other.hasSubscribers());
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 14 with io.reactivex.rxjava3.subscribers

use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.

the class ParallelRunOnTest method missingBackpressure.

@Test
public void missingBackpressure() {
    new ParallelFlowable<Integer>() {

        @Override
        public int parallelism() {
            return 1;
        }

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
            subscribers[0].onNext(2);
            subscribers[0].onNext(3);
        }
    }.runOn(ImmediateThinScheduler.INSTANCE, 1).sequential(1).test(0).assertFailure(MissingBackpressureException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 15 with io.reactivex.rxjava3.subscribers

use of io.reactivex.rxjava3.subscribers in project RxJava by ReactiveX.

the class ParallelInvalid method subscribe.

@Override
public void subscribe(Subscriber<? super Object>[] subscribers) {
    TestException ex = new TestException();
    for (Subscriber<? super Object> s : subscribers) {
        EmptySubscription.error(ex, s);
        s.onError(ex);
        s.onNext(0);
        s.onComplete();
        s.onComplete();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)19 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 TestException (io.reactivex.rxjava3.exceptions.TestException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)4 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 Disposable (io.reactivex.rxjava3.disposables.Disposable)2 Pattern (java.util.regex.Pattern)2 Subscriber (org.reactivestreams.Subscriber)2 SchedulerMultiWorkerSupport (io.reactivex.rxjava3.internal.schedulers.SchedulerMultiWorkerSupport)1 ConnectConsumer (io.reactivex.rxjava3.internal.util.ConnectConsumer)1 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)1 InOrder (org.mockito.InOrder)1