Search in sources :

Example 1 with UnicastProcessor

use of io.reactivex.rxjava3.processors.UnicastProcessor in project RxJava by ReactiveX.

the class FlowableObserveOnTest method outputFusedCancelReentrant.

@Test
public void outputFusedCancelReentrant() throws Exception {
    final UnicastProcessor<Integer> up = UnicastProcessor.create();
    final CountDownLatch cdl = new CountDownLatch(1);
    up.observeOn(Schedulers.single()).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        int count;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
            ((QueueSubscription<?>) s).requestFusion(QueueFuseable.ANY);
        }

        @Override
        public void onNext(Integer value) {
            if (++count == 1) {
                up.onNext(2);
                upstream.cancel();
                cdl.countDown();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
    up.onNext(1);
    cdl.await();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 2 with UnicastProcessor

use of io.reactivex.rxjava3.processors.UnicastProcessor in project RxJava by ReactiveX.

the class UnicastProcessorTest method onTerminateCalledWhenCanceled.

@Test
public void onTerminateCalledWhenCanceled() {
    final AtomicBoolean didRunOnTerminate = new AtomicBoolean();
    UnicastProcessor<Integer> up = UnicastProcessor.create(Observable.bufferSize(), new Runnable() {

        @Override
        public void run() {
            didRunOnTerminate.set(true);
        }
    });
    final Disposable subscribe = up.subscribe();
    assertFalse(didRunOnTerminate.get());
    subscribe.dispose();
    assertTrue(didRunOnTerminate.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 3 with UnicastProcessor

use of io.reactivex.rxjava3.processors.UnicastProcessor in project RxJava by ReactiveX.

the class UnicastProcessorTckTest method createFailedPublisher.

@Override
public Publisher<Integer> createFailedPublisher() {
    UnicastProcessor<Integer> up = UnicastProcessor.create();
    up.onError(new TestException());
    return up;
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 4 with UnicastProcessor

use of io.reactivex.rxjava3.processors.UnicastProcessor in project RxJava3_BuildMatrix by akarnokd.

the class FlowableObserveOnTest method outputFusedCancelReentrant.

@Test
public void outputFusedCancelReentrant() throws Exception {
    final UnicastProcessor<Integer> up = UnicastProcessor.create();
    final CountDownLatch cdl = new CountDownLatch(1);
    up.observeOn(Schedulers.single()).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        int count;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
            ((QueueSubscription<?>) s).requestFusion(QueueFuseable.ANY);
        }

        @Override
        public void onNext(Integer value) {
            if (++count == 1) {
                up.onNext(2);
                upstream.cancel();
                cdl.countDown();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
    up.onNext(1);
    cdl.await();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 5 with UnicastProcessor

use of io.reactivex.rxjava3.processors.UnicastProcessor in project RxJava3_BuildMatrix by akarnokd.

the class UnicastProcessorTckTest method createFailedPublisher.

@Override
public Publisher<Integer> createFailedPublisher() {
    UnicastProcessor<Integer> up = UnicastProcessor.create();
    up.onError(new TestException());
    return up;
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)8 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)2 TestException (io.reactivex.rxjava3.exceptions.TestException)2 QueueSubscription (io.reactivex.rxjava3.operators.QueueSubscription)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 Flowable.defer (io.reactivex.rxjava3.core.Flowable.defer)1 UnicastProcessor (io.reactivex.rxjava3.processors.UnicastProcessor)1 File (java.io.File)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 Path (java.nio.file.Path)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1