Search in sources :

Example 86 with Flowable

use of io.reactivex.rxjava3.core.Flowable 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);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) Test(org.junit.Test) NonNull(io.reactivex.rxjava3.annotations.NonNull) TimeUnit(java.util.concurrent.TimeUnit) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) List(java.util.List) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) Functions(io.reactivex.rxjava3.internal.functions.Functions) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) Subscriber(org.reactivestreams.Subscriber) NonNull(io.reactivex.rxjava3.annotations.NonNull) ConditionalSubscriber(io.reactivex.rxjava3.operators.ConditionalSubscriber) Test(org.junit.Test)

Example 87 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class ConnectableFlowable method connect.

/**
 * Instructs the {@code ConnectableFlowable} to begin emitting the items from its underlying
 * {@link Flowable} to its {@link Subscriber}s.
 * <p>
 * To disconnect from a synchronous source, use the {@link #connect(io.reactivex.rxjava3.functions.Consumer)} method.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The behavior is determined by the implementor of this abstract class.</dd>
 * </dl>
 *
 * @return the subscription representing the connection
 * @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
 */
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
    ConnectConsumer cc = new ConnectConsumer();
    connect(cc);
    return cc.disposable;
}
Also used : ConnectConsumer(io.reactivex.rxjava3.internal.util.ConnectConsumer)

Example 88 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class BlockingFlowableLatestTest method hasNextThrows.

@Test(expected = RuntimeException.class)
public void hasNextThrows() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    it.hasNext();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 89 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class BlockingFlowableLatestTest method simple.

@Test
public void simple() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    // which onComplete will overwrite the previous value
    for (int i = 0; i < 9; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertTrue(it.hasNext());
        Assert.assertEquals(Long.valueOf(i), it.next());
    }
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    Assert.assertFalse(it.hasNext());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 90 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class BlockingFlowableLatestTest method simpleJustNext.

@Test(expected = NoSuchElementException.class)
public void simpleJustNext() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingLatest();
    Iterator<Long> it = iter.iterator();
    // which onComplete will overwrite the previous value
    for (int i = 0; i < 10; i++) {
        scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
        Assert.assertEquals(Long.valueOf(i), it.next());
    }
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Aggregations

Test (org.junit.Test)159 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)121 TestException (io.reactivex.rxjava3.exceptions.TestException)95 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)49 InOrder (org.mockito.InOrder)41 IOException (java.io.IOException)27 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 Disposable (io.reactivex.rxjava3.disposables.Disposable)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)9 java.util (java.util)9 Assert (org.junit.Assert)9 Subscriber (org.reactivestreams.Subscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 java.util.concurrent.atomic (java.util.concurrent.atomic)8 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)7 Functions (io.reactivex.rxjava3.internal.functions.Functions)7 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)7