use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableFromSupplierTest method shouldAllowToThrowCheckedException.
@Test
public void shouldAllowToThrowCheckedException() {
final Exception checkedException = new Exception("test exception");
Flowable<Object> fromSupplierFlowable = Flowable.fromSupplier(new Supplier<Object>() {
@Override
public Object get() throws Exception {
throw checkedException;
}
});
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
fromSupplierFlowable.subscribe(subscriber);
verify(subscriber).onSubscribe(any(Subscription.class));
verify(subscriber).onError(checkedException);
verifyNoMoreInteractions(subscriber);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableGroupByTest method firstGroupsCompleteAndParentSlowToThenEmitFinalGroupsAndThenComplete.
@Test
public void firstGroupsCompleteAndParentSlowToThenEmitFinalGroupsAndThenComplete() throws InterruptedException {
// there are two groups to first complete
final CountDownLatch first = new CountDownLatch(2);
final ArrayList<String> results = new ArrayList<>();
Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> sub) {
sub.onSubscribe(new BooleanSubscription());
sub.onNext(1);
sub.onNext(2);
sub.onNext(1);
sub.onNext(2);
try {
first.await();
} catch (InterruptedException e) {
sub.onError(e);
return;
}
sub.onNext(3);
sub.onNext(3);
sub.onComplete();
}
}).groupBy(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer t) {
return t;
}
}).flatMap(new Function<GroupedFlowable<Integer, Integer>, Flowable<String>>() {
@Override
public Flowable<String> apply(final GroupedFlowable<Integer, Integer> group) {
if (group.getKey() < 3) {
return group.map(new Function<Integer, String>() {
@Override
public String apply(Integer t1) {
return "first groups: " + t1;
}
}).take(2).doOnComplete(new Action() {
@Override
public void run() {
first.countDown();
}
});
} else {
return group.map(new Function<Integer, String>() {
@Override
public String apply(Integer t1) {
return "last group: " + t1;
}
});
}
}
}).blockingForEach(new Consumer<String>() {
@Override
public void accept(String s) {
results.add(s);
}
});
System.out.println("Results: " + results);
assertEquals(6, results.size());
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure2.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure2() throws InterruptedException {
Flowable<Integer> w = Flowable.range(1, Flowable.bufferSize() * 2);
Flowable<Integer> f = w.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 > 100;
}
});
final CountDownLatch latch = new CountDownLatch(1);
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(Integer t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request 1 item and expect to receive more
ts.request(1);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure() throws InterruptedException {
Flowable<String> w = Flowable.just("one", "two", "three");
Flowable<String> f = w.filter(new Predicate<String>() {
@Override
public boolean test(String t1) {
return t1.equals("three");
}
});
final CountDownLatch latch = new CountDownLatch(1);
TestSubscriber<String> ts = new TestSubscriber<String>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(String t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request "one" and "two", expecting to receive them before requesting more
ts.request(2);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableFromCallableTest method shouldAllowToThrowCheckedException.
@Test
public void shouldAllowToThrowCheckedException() {
final Exception checkedException = new Exception("test exception");
Flowable<Object> fromCallableFlowable = Flowable.fromCallable(new Callable<Object>() {
@Override
public Object call() throws Exception {
throw checkedException;
}
});
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
fromCallableFlowable.subscribe(subscriber);
verify(subscriber).onSubscribe(any(Subscription.class));
verify(subscriber).onError(checkedException);
verifyNoMoreInteractions(subscriber);
}
Aggregations