use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableRetryTest method singleSubscriptionOnFirst.
@Test
public void singleSubscriptionOnFirst() throws Exception {
final AtomicInteger inc = new AtomicInteger(0);
Publisher<Integer> onSubscribe = new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
final int emit = inc.incrementAndGet();
subscriber.onNext(emit);
subscriber.onComplete();
}
};
int first = Flowable.unsafeCreate(onSubscribe).retryWhen(new Function<Flowable<? extends Throwable>, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Flowable<? extends Throwable> attempt) {
return attempt.zipWith(Flowable.just(1), new BiFunction<Throwable, Integer, Object>() {
@Override
public Object apply(Throwable o, Integer integer) {
return 0;
}
});
}
}).blockingFirst();
assertEquals("Observer did not receive the expected output", 1, first);
assertEquals("Subscribe was not called once", 1, inc.get());
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowablePublishMulticastTest method dontDropItemsWhenNoReadyConsumers.
@Test
public void dontDropItemsWhenNoReadyConsumers() {
final MulticastProcessor<Integer> mp = new MulticastProcessor<>(128, true);
mp.onSubscribe(new BooleanSubscription());
mp.onNext(1);
TestSubscriber<Integer> ts = new TestSubscriber<>();
final MulticastSubscription<Integer> ms1 = new MulticastSubscription<>(ts, mp);
ts.onSubscribe(ms1);
assertTrue(mp.add(ms1));
ms1.set(Long.MIN_VALUE);
mp.drain();
assertFalse(mp.queue.isEmpty());
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowablePublishMulticastTest method cancelledWhileFindingRequests.
@Test
public void cancelledWhileFindingRequests() {
final MulticastProcessor<Integer> mp = new MulticastProcessor<>(128, true);
final MulticastSubscription<Integer> ms1 = new MulticastSubscription<>(null, mp);
assertTrue(mp.add(ms1));
mp.onSubscribe(new BooleanSubscription());
ms1.set(Long.MIN_VALUE);
mp.drain();
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableMapTest method sourceIgnoresCancel.
@Test
public void sourceIgnoresCancel() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
s.onNext(1);
s.onNext(2);
s.onError(new IOException());
s.onComplete();
}
}).map(new Function<Integer, Object>() {
@Override
public Object apply(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations