use of io.reactivex.observers.TestObserver 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 ts = new TestObserver();
Observer s = new Observer() {
@Override
public void onSubscribe(Disposable s) {
ts.onSubscribe(s);
}
@Override
public void onNext(Object t) {
if (t.equals(1)) {
HalfSerializer.onComplete(a[0], wip, error);
}
ts.onNext(t);
}
@Override
public void onError(Throwable t) {
ts.onError(t);
}
@Override
public void onComplete() {
ts.onComplete();
}
};
a[0] = s;
s.onSubscribe(Disposables.empty());
HalfSerializer.onNext(s, 1, wip, error);
ts.assertResult(1);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class HalfSerializerObserverTest method onNextOnCompleteRace.
@Test
public void onNextOnCompleteRace() {
for (int i = 0; i < 500; i++) {
final AtomicInteger wip = new AtomicInteger();
final AtomicThrowable error = new AtomicThrowable();
final TestObserver<Integer> ts = new TestObserver<Integer>();
ts.onSubscribe(Disposables.empty());
Runnable r1 = new Runnable() {
@Override
public void run() {
HalfSerializer.onNext(ts, 1, wip, error);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
HalfSerializer.onComplete(ts, wip, error);
}
};
TestHelper.race(r1, r2, Schedulers.single());
ts.assertComplete().assertNoErrors();
assertTrue(ts.valueCount() <= 1);
}
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class HalfSerializerObserverTest method onErrorOnCompleteRace.
@Test
public void onErrorOnCompleteRace() {
for (int i = 0; i < 500; i++) {
final AtomicInteger wip = new AtomicInteger();
final AtomicThrowable error = new AtomicThrowable();
final TestObserver<Integer> ts = new TestObserver<Integer>();
ts.onSubscribe(Disposables.empty());
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
HalfSerializer.onError(ts, ex, wip, error);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
HalfSerializer.onComplete(ts, wip, error);
}
};
TestHelper.race(r1, r2, Schedulers.single());
if (ts.completions() != 0) {
ts.assertResult();
} else {
ts.assertFailure(TestException.class);
}
}
}
use of io.reactivex.observers.TestObserver in project RxRelay by JakeWharton.
the class PublishRelayTest method testReSubscribe.
/**
* Should be able to unsubscribe all Subscribers, have it stop emitting, then subscribe new ones and it start emitting again.
*/
@Test
public void testReSubscribe() {
final PublishRelay<Integer> ps = PublishRelay.create();
Observer<Integer> o1 = TestHelper.mockObserver();
TestObserver<Integer> ts = new TestObserver<Integer>(o1);
ps.subscribe(ts);
// emit
ps.accept(1);
// validate we got it
InOrder inOrder1 = inOrder(o1);
inOrder1.verify(o1, times(1)).onNext(1);
inOrder1.verifyNoMoreInteractions();
// unsubscribe
ts.dispose();
// emit again but nothing will be there to receive it
ps.accept(2);
Observer<Integer> o2 = TestHelper.mockObserver();
TestObserver<Integer> ts2 = new TestObserver<Integer>(o2);
ps.subscribe(ts2);
// emit
ps.accept(3);
// validate we got it
InOrder inOrder2 = inOrder(o2);
inOrder2.verify(o2, times(1)).onNext(3);
inOrder2.verifyNoMoreInteractions();
ts2.dispose();
}
use of io.reactivex.observers.TestObserver in project RxRelay by JakeWharton.
the class ReplayRelayTest method reentrantDrain.
@Test
public void reentrantDrain() {
TestScheduler scheduler = new TestScheduler();
final ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestObserver<Integer> ts = new TestObserver<Integer>() {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.accept(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.accept(1);
ts.assertValues(1, 2);
}
Aggregations