use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetry.
@Test
public void noCancelPreviousRetry() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retry(5).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class MaybeConsumersTest method onCompleteCrash.
@Test
public void onCompleteCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
subscribeAutoDispose(processor, composite, this, this, new Action() {
@Override
public void run() throws Exception {
throw new IOException();
}
});
processor.onComplete();
assertTrue(events.toString(), events.isEmpty());
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableAmbTest method noWinnerCompleteDispose.
@Test
public void noWinnerCompleteDispose() throws Exception {
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch cdl = new CountDownLatch(1);
Completable.ambArray(Completable.complete().subscribeOn(Schedulers.single()).observeOn(Schedulers.computation()), Completable.never()).subscribe(new Action() {
@Override
public void run() throws Exception {
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
assertTrue(cdl.await(500, TimeUnit.SECONDS));
assertFalse("Interrupted!", interrupted.get());
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableAndThenCompletableTest method andThenNoInterrupt.
@Test
public void andThenNoInterrupt() throws InterruptedException {
for (int k = 0; k < 100; k++) {
final int count = 10;
final CountDownLatch latch = new CountDownLatch(count);
final boolean[] interrupted = { false };
for (int i = 0; i < count; i++) {
Completable.complete().subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).andThen(Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
try {
Thread.sleep(30);
} catch (InterruptedException e) {
System.out.println("Interrupted! " + Thread.currentThread());
interrupted[0] = true;
}
}
})).subscribe(new Action() {
@Override
public void run() throws Exception {
latch.countDown();
}
});
}
latch.await();
assertFalse("The second Completable was interrupted!", interrupted[0]);
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableConcatDelayErrorTest method normalPublisherPrefetch.
@Test
public void normalPublisherPrefetch() throws Throwable {
Action action1 = mock(Action.class);
Action action2 = mock(Action.class);
Completable.concatDelayError(Flowable.fromArray(Completable.fromAction(action1), Completable.error(new TestException()), Completable.fromAction(action2)), 1).test().assertFailure(TestException.class);
verify(action1).run();
verify(action2).run();
}
Aggregations