use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableTakeLastTimedTest method takeLastTimedThrowingSource.
@Test
public void takeLastTimedThrowingSource() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Object> source = PublishSubject.create();
Observable<Object> result = source.takeLast(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
result.subscribe(o);
// T: 0ms
source.onNext(1);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 250ms
source.onNext(2);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 500ms
source.onNext(3);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 750ms
source.onNext(4);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 1000ms
source.onNext(5);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 1250ms
source.onError(new TestException());
inOrder.verify(o, times(1)).onError(any(TestException.class));
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SerializedSubjectTest method publishSubjectValueError.
@Test
public void publishSubjectValueError() {
PublishSubject<Integer> async = PublishSubject.create();
TestException te = new TestException();
async.onError(te);
Subject<Integer> serial = async.toSerialized();
assertFalse(serial.hasObservers());
assertFalse(serial.hasComplete());
assertTrue(serial.hasThrowable());
assertSame(te, serial.getThrowable());
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SerializedSubjectTest method onNextOnErrorRace.
@Test
public void onNextOnErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
TestObserver<Integer> to = s.test();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
s.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
s.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertError(ex).assertNotComplete();
if (to.values().size() != 0) {
to.assertValue(1);
}
}
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SerializedSubjectTest method onSubscribeOnSubscribeRace.
@Test
public void onSubscribeOnSubscribeRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
TestObserver<Integer> to = s.test();
final Disposable bs1 = Disposable.empty();
final Disposable bs2 = Disposable.empty();
Runnable r1 = new Runnable() {
@Override
public void run() {
s.onSubscribe(bs1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
s.onSubscribe(bs2);
}
};
TestHelper.race(r1, r2);
to.assertEmpty();
}
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SerializedSubjectTest method onErrorQueued.
@Test
public void onErrorQueued() {
Subject<Integer> sp = PublishSubject.<Integer>create().toSerialized();
TestObserver<Integer> to = new TestObserver<Integer>() {
@Override
public void onNext(@NonNull Integer t) {
super.onNext(t);
if (t == 1) {
sp.onNext(2);
sp.onNext(3);
sp.onSubscribe(Disposable.empty());
sp.onError(new TestException());
}
}
};
sp.subscribe(to);
sp.onNext(1);
// errors skip ahead
to.assertFailure(TestException.class, 1);
}
Aggregations