Search in sources :

Example 1 with ObservableOnSubscribe

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

the class ObservableCreateTest method basicSerialized.

@Test
@SuppressUndeliverable
public void basicSerialized() {
    final Disposable d = Disposable.empty();
    Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e = e.serialize();
            e.setDisposable(d);
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
            e.onComplete();
            e.onError(new TestException());
            e.onNext(4);
            e.onError(new TestException());
            e.onComplete();
        }
    }).test().assertResult(1, 2, 3);
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with ObservableOnSubscribe

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

the class ObservableCreateTest method basicWithCancellable.

@Test
@SuppressUndeliverable
public void basicWithCancellable() {
    final Disposable d1 = Disposable.empty();
    final Disposable d2 = Disposable.empty();
    Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.setDisposable(d1);
            e.setCancellable(new Cancellable() {

                @Override
                public void cancel() throws Exception {
                    d2.dispose();
                }
            });
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
            e.onComplete();
            e.onError(new TestException());
            e.onNext(4);
            e.onError(new TestException());
            e.onComplete();
        }
    }).test().assertResult(1, 2, 3);
    assertTrue(d1.isDisposed());
    assertTrue(d2.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) Cancellable(io.reactivex.rxjava3.functions.Cancellable) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ObservableOnSubscribe

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

the class ObservableCreateTest method onErrorRace.

@Test
public void onErrorRace() {
    Observable<Object> source = Observable.create(new ObservableOnSubscribe<Object>() {

        @Override
        public void subscribe(ObservableEmitter<Object> e) throws Exception {
            final ObservableEmitter<Object> f = e.serialize();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    f.onError(null);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    f.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
        }
    });
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            source.test().assertFailure(Throwable.class);
        }
    } finally {
        RxJavaPlugins.reset();
    }
    assertFalse(errors.isEmpty());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ObservableOnSubscribe

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

the class ObservableCreateTest method onErrorCrash.

@Test
public void onErrorCrash() {
    Observable.create(new ObservableOnSubscribe<Object>() {

        @Override
        public void subscribe(ObservableEmitter<Object> e) throws Exception {
            Disposable d = Disposable.empty();
            e.setDisposable(d);
            try {
                e.onError(new IOException());
                fail("Should have thrown");
            } catch (TestException ex) {
            // expected
            }
            assertTrue(d.isDisposed());
        }
    }).subscribe(new Observer<Object>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Object value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ObservableOnSubscribe

use of io.reactivex.rxjava3.core.ObservableOnSubscribe in project Mycat2 by MyCATApache.

the class ValuesCsvScanPlan method execute.

@Override
public Observable execute(RootContext rootContext) {
    return (Observable) Observable.create((ObservableOnSubscribe<VectorSchemaRoot>) emitter -> {
        int size = 0;
        for (VectorSchemaRoot vectorSchemaRoot : observable) {
            size += vectorSchemaRoot.getRowCount();
            emitter.onNext(vectorSchemaRoot);
        }
        LOGGER.debug(" size:{}", size);
        emitter.onComplete();
    });
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) ObservableOnSubscribe(io.reactivex.rxjava3.core.ObservableOnSubscribe) Observable(io.reactivex.rxjava3.core.Observable)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)9 Test (org.junit.Test)8 Disposable (io.reactivex.rxjava3.disposables.Disposable)7 IOException (java.io.IOException)7 Observable (io.reactivex.rxjava3.core.Observable)2 ObservableOnSubscribe (io.reactivex.rxjava3.core.ObservableOnSubscribe)2 ArrayAdapter (android.widget.ArrayAdapter)1 ListView (android.widget.ListView)1 RefreshLayoutBase (com.apache.fastandroid.demo.widget.refresh.RefreshLayoutBase)1 RefreshListView (com.apache.fastandroid.demo.widget.refresh.RefreshListView)1 OkHttpClientBuilder (com.xxf.arch.http.OkHttpClientBuilder)1 DownloadTask (com.xxf.arch.model.DownloadTask)1 NonNull (io.reactivex.rxjava3.annotations.NonNull)1 ObservableEmitter (io.reactivex.rxjava3.core.ObservableEmitter)1 Cancellable (io.reactivex.rxjava3.functions.Cancellable)1 Consumer (io.reactivex.rxjava3.functions.Consumer)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1