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));
}
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);
}
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));
}
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);
}
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
}
});
}
Aggregations