Search in sources :

Example 91 with Observable

use of io.reactivex.Observable in project RxJava by ReactiveX.

the class ObservableObserveOnTest method nonFusedPollThrows.

@Test
public void nonFusedPollThrows() {
    new Observable<Integer>() {

        @Override
        protected void subscribeActual(Observer<? super Integer> observer) {
            observer.onSubscribe(Disposables.empty());
            @SuppressWarnings("unchecked") ObserveOnObserver<Integer> oo = (ObserveOnObserver<Integer>) observer;
            oo.queue = new SimpleQueue<Integer>() {

                @Override
                public boolean offer(Integer value) {
                    return false;
                }

                @Override
                public boolean offer(Integer v1, Integer v2) {
                    return false;
                }

                @Nullable
                @Override
                public Integer poll() throws Exception {
                    throw new TestException();
                }

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public void clear() {
                }
            };
            oo.clear();
            oo.schedule();
        }
    }.observeOn(Schedulers.single()).test().awaitDone(5, TimeUnit.SECONDS).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException) ObserveOnObserver(io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver) Observer(io.reactivex.Observer) ObserveOnObserver(io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver) Observable(io.reactivex.Observable) Nullable(io.reactivex.annotations.Nullable) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 92 with Observable

use of io.reactivex.Observable in project RxJava by ReactiveX.

the class ObservableObserveOnTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestScheduler scheduler = new TestScheduler();
        TestObserver<Integer> to = new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onComplete();
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.observeOn(scheduler).test();
        scheduler.triggerActions();
        to.assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) ObserveOnObserver(io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 93 with Observable

use of io.reactivex.Observable in project RxJava by ReactiveX.

the class ObservableElementAtTest method badSourceObservable.

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

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposables.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.elementAt(0).toObservable().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 94 with Observable

use of io.reactivex.Observable in project RxJava by ReactiveX.

the class ObservableMergeMaxConcurrentTest method testMaxConcurrent.

@Test
public void testMaxConcurrent() {
    for (int times = 0; times < 100; times++) {
        int observableCount = 100;
        // Test maxConcurrent from 2 to 12
        int maxConcurrent = 2 + (times % 10);
        AtomicInteger subscriptionCount = new AtomicInteger(0);
        List<Observable<String>> os = new ArrayList<Observable<String>>();
        List<SubscriptionCheckObservable> scos = new ArrayList<SubscriptionCheckObservable>();
        for (int i = 0; i < observableCount; i++) {
            SubscriptionCheckObservable sco = new SubscriptionCheckObservable(subscriptionCount, maxConcurrent);
            scos.add(sco);
            os.add(Observable.unsafeCreate(sco));
        }
        Iterator<String> iter = Observable.merge(os, maxConcurrent).blockingIterable().iterator();
        List<String> actual = new ArrayList<String>();
        while (iter.hasNext()) {
            actual.add(iter.next());
        }
        //            System.out.println("actual: " + actual);
        assertEquals(5 * observableCount, actual.size());
        for (SubscriptionCheckObservable sco : scos) {
            assertFalse(sco.failed);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Observable(io.reactivex.Observable)

Example 95 with Observable

use of io.reactivex.Observable in project RxJava by ReactiveX.

the class ObservableUsingTest method performTestUsingWithSubscribingTwice.

private void performTestUsingWithSubscribingTwice(boolean disposeEagerly) {
    // When subscribe is called, a new resource should be created.
    Callable<Resource> resourceFactory = new Callable<Resource>() {

        @Override
        public Resource call() {
            return new Resource() {

                boolean first = true;

                @Override
                public String getTextFromWeb() {
                    if (first) {
                        first = false;
                        return "Hello world!";
                    }
                    return "Nothing";
                }

                @Override
                public void dispose() {
                // do nothing
                }
            };
        }
    };
    Function<Resource, Observable<String>> observableFactory = new Function<Resource, Observable<String>>() {

        @Override
        public Observable<String> apply(Resource res) {
            return Observable.fromArray(res.getTextFromWeb().split(" "));
        }
    };
    Observer<String> observer = TestHelper.mockObserver();
    Observable<String> o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly);
    o.subscribe(observer);
    o.subscribe(observer);
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext("Hello");
    inOrder.verify(observer, times(1)).onNext("world!");
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verify(observer, times(1)).onNext("Hello");
    inOrder.verify(observer, times(1)).onNext("world!");
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Callable(java.util.concurrent.Callable) Observable(io.reactivex.Observable)

Aggregations

Observable (io.reactivex.Observable)170 List (java.util.List)54 ArrayList (java.util.ArrayList)39 Test (org.junit.Test)36 Collectors (java.util.stream.Collectors)29 InOrder (org.mockito.InOrder)27 TestException (io.reactivex.exceptions.TestException)24 Page (io.nem.symbol.sdk.api.Page)19 Address (io.nem.symbol.sdk.model.account.Address)18 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)18 Disposable (io.reactivex.disposables.Disposable)18 Bundle (android.os.Bundle)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 Function (io.reactivex.functions.Function)15 TestObserver (io.reactivex.observers.TestObserver)15 Schedulers (io.reactivex.schedulers.Schedulers)15 Nullable (android.support.annotation.Nullable)14 MerkleStateInfo (io.nem.symbol.sdk.model.blockchain.MerkleStateInfo)14 ApiClient (io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient)14 AsyncResult (io.vertx.core.AsyncResult)14