use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onNextCrashes.
@Test
public void onNextCrashes() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onNext(1);
assertTrue(b.isCancelled());
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSubscriberTest method suppressAfterCompleteEvents.
@Test
public void suppressAfterCompleteEvents() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
ts.onNext(v);
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
s.onComplete();
s.onNext(1);
s.onError(new TestException());
s.onComplete();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTests method cacheWithCapacity.
@Test
public void cacheWithCapacity() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
Flowable<String> f = Flowable.<String>unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
subscriber.onNext("one");
subscriber.onComplete();
}
}).start();
}
}).cacheWithInitialCapacity(1);
// we then expect the following 2 subscriptions to get that same value
final CountDownLatch latch = new CountDownLatch(2);
// subscribe once
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
// subscribe again
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
fail("subscriptions did not receive values");
}
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTests method publishLast.
@Test
public void publishLast() throws InterruptedException {
final AtomicInteger count = new AtomicInteger();
ConnectableFlowable<String> connectable = Flowable.<String>unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
count.incrementAndGet();
new Thread(new Runnable() {
@Override
public void run() {
subscriber.onNext("first");
subscriber.onNext("last");
subscriber.onComplete();
}
}).start();
}
}).takeLast(1).publish();
// subscribe once
final CountDownLatch latch = new CountDownLatch(1);
connectable.subscribe(new Consumer<String>() {
@Override
public void accept(String value) {
assertEquals("last", value);
latch.countDown();
}
});
// subscribe twice
connectable.subscribe();
Disposable subscription = connectable.connect();
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
assertEquals(1, count.get());
subscription.dispose();
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTests method replay.
@Test
public void replay() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
ConnectableFlowable<String> f = Flowable.<String>unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
subscriber.onNext("one");
subscriber.onComplete();
}
}).start();
}
}).replay();
// we connect immediately and it will emit the value
Disposable connection = f.connect();
try {
// we then expect the following 2 subscriptions to get that same value
final CountDownLatch latch = new CountDownLatch(2);
// subscribe once
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
// subscribe again
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
fail("subscriptions did not receive values");
}
assertEquals(1, counter.get());
} finally {
connection.dispose();
}
}
Aggregations