use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableFromActionTest method fromActionInvokesLazy.
@Test
public void fromActionInvokesLazy() {
final AtomicInteger atomicInteger = new AtomicInteger();
Completable completable = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
atomicInteger.incrementAndGet();
}
});
assertEquals(0, atomicInteger.get());
completable.test().assertResult();
assertEquals(1, atomicInteger.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class BoundedSubscriberTest method badSourceEmitAfterDone.
@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
s.onNext(1);
s.onComplete();
s.onNext(2);
s.onError(new TestException());
s.onComplete();
}
});
final List<Object> received = new ArrayList<>();
BoundedSubscriber<Object> subscriber = new BoundedSubscriber<>(new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
received.add(v);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
received.add(e);
}
}, new Action() {
@Override
public void run() throws Exception {
received.add(100);
}
}, new Consumer<Subscription>() {
@Override
public void accept(Subscription s) throws Exception {
s.request(128);
}
}, 128);
source.subscribe(subscriber);
assertEquals(Arrays.asList(1, 100), received);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class LambdaSubscriberTest method badSourceEmitAfterDone.
@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
s.onNext(1);
s.onComplete();
s.onNext(2);
s.onError(new TestException());
s.onComplete();
}
});
final List<Object> received = new ArrayList<>();
LambdaSubscriber<Object> subscriber = new LambdaSubscriber<>(new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
received.add(v);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
received.add(e);
}
}, new Action() {
@Override
public void run() throws Exception {
received.add(100);
}
}, new Consumer<Subscription>() {
@Override
public void accept(Subscription s) throws Exception {
s.request(Long.MAX_VALUE);
}
});
source.subscribe(subscriber);
assertEquals(Arrays.asList(1, 100), received);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableDoAfterTerminateTest method ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce.
@Test
public void ifFinallyActionThrowsExceptionShouldNotBeSwallowedAndActionShouldBeCalledOnce() throws Throwable {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Action finallyAction = Mockito.mock(Action.class);
doThrow(new IllegalStateException()).when(finallyAction).run();
TestSubscriber<String> testSubscriber = new TestSubscriber<>();
Flowable.just("value").doAfterTerminate(finallyAction).subscribe(testSubscriber);
testSubscriber.assertValue("value");
verify(finallyAction).run();
TestHelper.assertError(errors, 0, IllegalStateException.class);
// Actual result:
// Not only IllegalStateException was swallowed
// But finallyAction was called twice!
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableDoFinallyTest method actionThrowsConditional.
@Test
public void actionThrowsConditional() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.just(1).doFinally(new Action() {
@Override
public void run() throws Exception {
throw new TestException();
}
}).filter(Functions.alwaysTrue()).test().assertResult(1).cancel();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations