Search in sources :

Example 61 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableUnsubscribeOnTest method signalAfterDispose.

@Test
public void signalAfterDispose() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onNext(1);
                subscriber.onNext(2);
                subscriber.onError(new TestException());
                subscriber.onComplete();
            }
        }.unsubscribeOn(Schedulers.single()).take(1).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 62 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableWindowWithFlowableTest method takeOneAnotherBoundary.

@Test
public void takeOneAnotherBoundary() {
    final AtomicReference<Subscriber<? super Object>> refMain = new AtomicReference<>();
    final AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
    TestSubscriberEx<Flowable<Object>> ts = new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            refMain.set(subscriber);
        }
    }.window(new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            ref.set(subscriber);
        }
    }).to(TestHelper.<Flowable<Object>>testConsumer());
    ts.assertValueCount(1).assertNotTerminated().cancel();
    ref.get().onNext(1);
    ts.assertValueCount(1).assertNotTerminated();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 63 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableWindowWithFlowableTest method mainCompleteBoundaryErrorRace.

@Test
public void mainCompleteBoundaryErrorRace() {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final AtomicReference<Subscriber<? super Object>> refMain = new AtomicReference<>();
            final AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
            TestSubscriberEx<Flowable<Object>> ts = new Flowable<Object>() {

                @Override
                protected void subscribeActual(Subscriber<? super Object> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    refMain.set(subscriber);
                }
            }.window(new Flowable<Object>() {

                @Override
                protected void subscribeActual(Subscriber<? super Object> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    ref.set(subscriber);
                }
            }).to(TestHelper.<Flowable<Object>>testConsumer());
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    refMain.get().onComplete();
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    ref.get().onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueCount(1).assertTerminated();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 64 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowablePublishTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onNext(1);
                subscriber.onComplete();
                subscriber.onNext(2);
                subscriber.onError(new TestException());
                subscriber.onComplete();
            }
        }.publish().autoConnect().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable) Test(org.junit.Test)

Example 65 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowablePublishTest method publish.

@Test
public void publish() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    ConnectableFlowable<String> f = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    subscriber.onNext("one");
                    subscriber.onComplete();
                }
            }).start();
        }
    }).publish();
    final CountDownLatch latch = new CountDownLatch(2);
    // subscribe once
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    // subscribe again
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    Disposable connection = f.connect();
    try {
        if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
            fail("subscriptions did not receive values");
        }
        assertEquals(1, counter.get());
    } finally {
        connection.dispose();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) HasUpstreamPublisher(io.reactivex.rxjava3.internal.fuseable.HasUpstreamPublisher) Test(org.junit.Test)

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