use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleDoOnTerminateTest method doOnTerminateSuccess.
@Test
public void doOnTerminateSuccess() {
final AtomicBoolean atomicBoolean = new AtomicBoolean();
Single.just(1).doOnTerminate(new Action() {
@Override
public void run() throws Exception {
atomicBoolean.set(true);
}
}).test().assertResult(1);
assertTrue(atomicBoolean.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleFlatMapTest method flatMapPublisherCancelDuringSingle.
@Test
public void flatMapPublisherCancelDuringSingle() {
final AtomicBoolean disposed = new AtomicBoolean();
TestSubscriberEx<Integer> ts = Single.<Integer>never().doOnDispose(new Action() {
@Override
public void run() throws Exception {
disposed.set(true);
}
}).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
return Flowable.range(v, 5);
}
}).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
assertFalse(disposed.get());
ts.cancel();
assertTrue(disposed.get());
ts.assertNotTerminated();
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleFlatMapTest method flatMapPublisherCancelDuringFlowable.
@Test
public void flatMapPublisherCancelDuringFlowable() {
final AtomicBoolean disposed = new AtomicBoolean();
TestSubscriberEx<Integer> ts = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
return Flowable.<Integer>never().doOnCancel(new Action() {
@Override
public void run() throws Exception {
disposed.set(true);
}
});
}
}).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
assertFalse(disposed.get());
ts.cancel();
assertTrue(disposed.get());
ts.assertNotTerminated();
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class BoundedSubscriberTest method badSourceOnSubscribe.
@Test
public void badSourceOnSubscribe() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
BooleanSubscription s2 = new BooleanSubscription();
s.onSubscribe(s2);
assertFalse(s1.isCancelled());
assertTrue(s2.isCancelled());
s.onNext(1);
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 badSourceOnSubscribe.
@Test
public void badSourceOnSubscribe() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
BooleanSubscription s2 = new BooleanSubscription();
s.onSubscribe(s2);
assertFalse(s1.isCancelled());
assertTrue(s2.isCancelled());
s.onNext(1);
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);
}
Aggregations