Search in sources :

Example 46 with Observable

use of io.reactivex.Observable in project tutorials by eugenp.

the class FlowableTest method whenDropStrategyUsed_thenOnBackpressureDropped.

@Test
public void whenDropStrategyUsed_thenOnBackpressureDropped() {
    List testList = IntStream.range(0, 100000).boxed().collect(Collectors.toList());
    Observable observable = Observable.fromIterable(testList);
    TestSubscriber<Integer> testSubscriber = observable.toFlowable(BackpressureStrategy.DROP).observeOn(Schedulers.computation()).test();
    testSubscriber.awaitTerminalEvent();
    List<Integer> receivedInts = testSubscriber.getEvents().get(0).stream().mapToInt(object -> (int) object).boxed().collect(Collectors.toList());
    assertThat(receivedInts.size() < testList.size());
    assertThat(!receivedInts.contains(100000));
}
Also used : List(java.util.List) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 47 with Observable

use of io.reactivex.Observable in project tutorials by eugenp.

the class FlowableTest method whenMissingStrategyUsed_thenException.

@Test
public void whenMissingStrategyUsed_thenException() {
    Observable observable = Observable.range(1, 100000);
    TestSubscriber subscriber = observable.toFlowable(BackpressureStrategy.MISSING).observeOn(Schedulers.computation()).test();
    subscriber.awaitTerminalEvent();
    subscriber.assertError(MissingBackpressureException.class);
}
Also used : TestSubscriber(io.reactivex.subscribers.TestSubscriber) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 48 with Observable

use of io.reactivex.Observable in project tutorials by eugenp.

the class FlowableTest method whenLatestStrategyUsed_thenTheLastElementReceived.

@Test
public void whenLatestStrategyUsed_thenTheLastElementReceived() {
    List testList = IntStream.range(0, 100000).boxed().collect(Collectors.toList());
    Observable observable = Observable.fromIterable(testList);
    TestSubscriber<Integer> testSubscriber = observable.toFlowable(BackpressureStrategy.LATEST).observeOn(Schedulers.computation()).test();
    testSubscriber.awaitTerminalEvent();
    List<Integer> receivedInts = testSubscriber.getEvents().get(0).stream().mapToInt(object -> (int) object).boxed().collect(Collectors.toList());
    assertThat(receivedInts.size() < testList.size());
    assertThat(receivedInts.contains(100000));
}
Also used : List(java.util.List) Observable(io.reactivex.Observable) Test(org.junit.Test)

Example 49 with Observable

use of io.reactivex.Observable in project My-MVP by REBOOTERS.

the class RxJavaBaseActivity method basicRxjava2.

private void basicRxjava2() {
    Observable mObservable = Observable.create(new ObservableOnSubscribe() {

        @Override
        public void subscribe(ObservableEmitter e) throws Exception {
            e.onNext("1");
            e.onNext("2");
            e.onNext("3");
            e.onNext("4");
            e.onComplete();
        }
    });
    Observer mObserver = new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            Log.e(TAG, "onSubscribe: d=" + d);
            sb.append("\nonSubcribe: d=" + d);
        }

        @Override
        public void onNext(Object s) {
            Log.e(TAG, "onNext: " + s);
            sb.append("\nonNext: " + s);
        }

        @Override
        public void onError(Throwable e) {
            Log.e(TAG, "onError: " + e);
            sb.append("\nonError: " + e.toString());
            logContent.setText(sb.toString());
        }

        @Override
        public void onComplete() {
            Log.e(TAG, "onComplete");
            sb.append("\nonComplete: ");
            logContent.setText(sb.toString());
        }
    };
    mObservable.subscribe(mObserver);
}
Also used : Disposable(io.reactivex.disposables.Disposable) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Observer(io.reactivex.Observer) Observable(io.reactivex.Observable) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 50 with Observable

use of io.reactivex.Observable in project butter-android by butterproject.

the class MainPresenterImpl method displayProviderData.

private void displayProviderData(final int providerId) {
    this.selectedProviderId = providerId;
    final ProviderWrapper provider = providerManager.getProvider(providerId);
    final MediaProvider mediaProvider = provider.getMediaProvider();
    unsubscribeProviderId(providerId);
    Observable.concat(mediaProvider.genres().filter(genres -> genres != null && genres.size() > 0).map(g -> new NavInfo(R.id.nav_item_genre, 0, R.string.genres, providerId)).toObservable(), mediaProvider.navigation().flatMapObservable(Observable::fromIterable).map(item -> new NavInfo(item, providerId))).toList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new SingleObserver<List<NavInfo>>() {

        @Override
        public void onSubscribe(final Disposable d) {
            providerDataDisposable.add(providerId, d);
        }

        @Override
        public void onSuccess(final List<NavInfo> value) {
            // TODO: 8/5/17 Do we need this
            // boolean hasGenres = value.first != null && value.first.size() > 0;
            view.displayProvider(provider.getDisplayName(), value);
        }

        @Override
        public void onError(final Throwable e) {
        // TODO: 8/5/17 Display error
        }
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(android.support.annotation.NonNull) UiGenre(butter.droid.ui.main.genre.list.model.UiGenre) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Manifest(android.Manifest) PrefManager(butter.droid.base.manager.prefs.PrefManager) NavInfo(butter.droid.ui.main.pager.NavInfo) ProviderManager(butter.droid.base.manager.internal.provider.ProviderManager) KeyDisposable(butter.droid.base.utils.rx.KeyDisposable) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) R(butter.droid.R) ContextCompat(android.support.v4.content.ContextCompat) PreferencesHandler(butter.droid.base.content.preferences.PreferencesHandler) PreferencesActivity(butter.droid.ui.preferences.PreferencesActivity) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) ProviderWrapper(butter.droid.base.manager.internal.provider.model.ProviderWrapper) SingleObserver(io.reactivex.SingleObserver) TermsPresenterImpl(butter.droid.ui.terms.TermsPresenterImpl) MediaProvider(butter.droid.provider.MediaProvider) Activity(android.app.Activity) KeyDisposable(butter.droid.base.utils.rx.KeyDisposable) Disposable(io.reactivex.disposables.Disposable) MediaProvider(butter.droid.provider.MediaProvider) ArrayList(java.util.ArrayList) List(java.util.List) NavInfo(butter.droid.ui.main.pager.NavInfo) ProviderWrapper(butter.droid.base.manager.internal.provider.model.ProviderWrapper) 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