Search in sources :

Example 81 with Observer

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

the class HalfSerializerObserverTest method reentrantOnNextOnComplete.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnComplete() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Observer[] a = { null };
    final TestObserver to = new TestObserver();
    Observer observer = new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            to.onSubscribe(d);
        }

        @Override
        public void onNext(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onComplete(a[0], wip, error);
            }
            to.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            to.onError(t);
        }

        @Override
        public void onComplete() {
            to.onComplete();
        }
    };
    a[0] = observer;
    observer.onSubscribe(Disposable.empty());
    HalfSerializer.onNext(observer, 1, wip, error);
    to.assertResult(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 82 with Observer

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

the class HalfSerializerObserverTest method reentrantErrorOnError.

@Test
@SuppressUndeliverable
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantErrorOnError() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Observer[] a = { null };
    final TestObserver to = new TestObserver();
    Observer observer = new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            to.onSubscribe(d);
        }

        @Override
        public void onNext(Object t) {
            to.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            to.onError(t);
            HalfSerializer.onError(a[0], new IOException(), wip, error);
        }

        @Override
        public void onComplete() {
            to.onComplete();
        }
    };
    a[0] = observer;
    observer.onSubscribe(Disposable.empty());
    HalfSerializer.onError(observer, new TestException(), wip, error);
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 83 with Observer

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

the class ObservableWindowWithStartEndObservableTest method openError.

@Test
public void openError() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        TestException ex1 = new TestException();
        TestException ex2 = new TestException();
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            AtomicReference<Observer<? super Integer>> ref1 = new AtomicReference<>();
            AtomicReference<Observer<? super Integer>> ref2 = new AtomicReference<>();
            Observable<Integer> o1 = Observable.<Integer>unsafeCreate(ref1::set);
            Observable<Integer> o2 = Observable.<Integer>unsafeCreate(ref2::set);
            TestObserver<Observable<Integer>> to = BehaviorSubject.createDefault(1).window(o1, v -> o2).doOnNext(w -> w.test()).test();
            ref1.get().onSubscribe(Disposable.empty());
            ref1.get().onNext(1);
            ref2.get().onSubscribe(Disposable.empty());
            TestHelper.race(() -> ref1.get().onError(ex1), () -> ref2.get().onError(ex2));
            to.assertError(RuntimeException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
            errors.clear();
        }
    });
}
Also used : java.util(java.util) Observer(io.reactivex.rxjava3.core.Observer) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) TestException(io.reactivex.rxjava3.exceptions.TestException) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) java.util.concurrent.atomic(java.util.concurrent.atomic) IOException(java.io.IOException) io.reactivex.rxjava3.observers(io.reactivex.rxjava3.observers) TimeUnit(java.util.concurrent.TimeUnit) Functions(io.reactivex.rxjava3.internal.functions.Functions) Observable(io.reactivex.rxjava3.core.Observable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) org.junit(org.junit) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) TestException(io.reactivex.rxjava3.exceptions.TestException) Observer(io.reactivex.rxjava3.core.Observer) Observable(io.reactivex.rxjava3.core.Observable)

Example 84 with Observer

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

the class ObservableZipIterableTest method zipIterableNextThrows.

@Test
public void zipIterableNextThrows() {
    PublishSubject<String> r1 = PublishSubject.create();
    /* define an Observer to receive aggregated events */
    Observer<String> o = TestHelper.mockObserver();
    InOrder io = inOrder(o);
    Iterable<String> r2 = new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            return new Iterator<String>() {

                @Override
                public boolean hasNext() {
                    return true;
                }

                @Override
                public String next() {
                    throw new TestException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }
    };
    r1.zipWith(r2, zipr2).subscribe(o);
    r1.onError(new TestException());
    io.verify(o).onError(any(TestException.class));
    verify(o, never()).onNext(any(String.class));
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) CrashingIterable(io.reactivex.rxjava3.internal.util.CrashingIterable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 85 with Observer

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

the class ObservableThrottleFirstTest method before.

@Before
public void before() {
    scheduler = new TestScheduler();
    innerScheduler = scheduler.createWorker();
    observer = TestHelper.mockObserver();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Aggregations

Test (org.junit.Test)139 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)75 Observable (io.reactivex.rxjava3.core.Observable)49 Disposable (io.reactivex.rxjava3.disposables.Disposable)49 TestObserver (io.reactivex.rxjava3.observers.TestObserver)37 IOException (java.io.IOException)29 Observer (io.reactivex.rxjava3.core.Observer)23 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)11 Function (io.reactivex.rxjava3.functions.Function)10 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 io.reactivex.rxjava3.subjects (io.reactivex.rxjava3.subjects)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5