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