use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class ExceptionsTest method stackOverflowWouldOccur.
@Test
public void stackOverflowWouldOccur() {
final PublishSubject<Integer> a = PublishSubject.create();
final PublishSubject<Integer> b = PublishSubject.create();
final int MAX_STACK_DEPTH = 800;
final AtomicInteger depth = new AtomicInteger();
a.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Integer n) {
b.onNext(n + 1);
}
});
b.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
// TODO Auto-generated method stub
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Integer n) {
if (depth.get() < MAX_STACK_DEPTH) {
depth.set(Thread.currentThread().getStackTrace().length);
a.onNext(n + 1);
}
}
});
a.onNext(1);
assertTrue(depth.get() >= MAX_STACK_DEPTH);
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class CompletableTimeoutTest method errorTimeoutRace.
@Test
public void errorTimeoutRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestScheduler scheduler = new TestScheduler();
final PublishSubject<Integer> ps = PublishSubject.create();
TestObserverEx<Void> to = ps.ignoreElements().timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).to(TestHelper.<Void>testConsumer());
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
ps.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};
TestHelper.race(r1, r2);
to.assertTerminated();
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class CompletableMergeIterableTest method errorRace.
@Test
public void errorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishSubject<Integer> ps1 = PublishSubject.create();
final PublishSubject<Integer> ps2 = PublishSubject.create();
TestObserver<Void> to = Completable.merge(Arrays.asList(ps1.ignoreElements(), ps2.ignoreElements())).test();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
ps1.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ps2.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class SingleFlatMapObservableTest method errorOther.
@Test
public void errorOther() {
SingleSubject<Integer> ss = SingleSubject.create();
PublishSubject<Integer> ps = PublishSubject.create();
TestObserver<Integer> to = ss.flatMapObservable(Functions.justFunction(ps)).test();
assertTrue(ss.hasObservers());
assertFalse(ps.hasObservers());
ss.onSuccess(1);
assertFalse(ss.hasObservers());
assertTrue(ps.hasObservers());
ps.onError(new TestException());
assertFalse(ss.hasObservers());
assertFalse(ps.hasObservers());
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.
the class CompletableAndThenObservableTest method errorMain.
@Test
public void errorMain() {
CompletableSubject cs = CompletableSubject.create();
PublishSubject<Integer> ps = PublishSubject.create();
TestObserver<Integer> to = cs.andThen(ps).test();
assertTrue(cs.hasObservers());
assertFalse(ps.hasObservers());
cs.onError(new TestException());
assertFalse(cs.hasObservers());
assertFalse(ps.hasObservers());
to.assertFailure(TestException.class);
}
Aggregations