use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeTimerTest method timer.
@Test
public void timer() {
final TestScheduler testScheduler = new TestScheduler();
final AtomicLong atomicLong = new AtomicLong();
Maybe.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Consumer<Long>() {
@Override
public void accept(final Long value) throws Exception {
atomicLong.incrementAndGet();
}
});
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(0, atomicLong.get());
testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
assertEquals(1, atomicLong.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableDelayTest method onErrorCalledOnScheduler.
@Test
public void onErrorCalledOnScheduler() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Thread> thread = new AtomicReference<>();
Flowable.<String>error(new Exception()).delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread()).doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
}).onErrorResumeWith(Flowable.<String>empty()).subscribe();
latch.await();
assertNotEquals(Thread.currentThread(), thread.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableDoOnEachTest method ignoreCancel.
@Test
public void ignoreCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Object>() {
@Override
public void subscribe(Subscriber<? super Object> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).doOnNext(new Consumer<Object>() {
@Override
public void accept(Object e) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableDelaySubscriptionOtherTest method noSubscriptionIfOtherErrors.
@Test
public void noSubscriptionIfOtherErrors() {
PublishProcessor<Object> other = PublishProcessor.create();
TestSubscriber<Integer> ts = new TestSubscriber<>();
final AtomicInteger subscribed = new AtomicInteger();
Flowable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onError(new TestException());
Assert.assertEquals("Premature subscription", 0, subscribed.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableGenerateTest method disposerThrows.
@Test
public void disposerThrows() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.generate(new Supplier<Object>() {
@Override
public Object get() throws Exception {
return 1;
}
}, new BiConsumer<Object, Emitter<Object>>() {
@Override
public void accept(Object s, Emitter<Object> e) throws Exception {
e.onComplete();
}
}, new Consumer<Object>() {
@Override
public void accept(Object d) throws Exception {
throw new TestException();
}
}).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations