use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTakeTest2 method cancelIgnored.
@Test
public void cancelIgnored() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
BooleanSubscription bs = new BooleanSubscription();
s.onSubscribe(bs);
assertTrue(bs.isCancelled());
s.onNext(1);
s.onComplete();
s.onError(new TestException());
s.onSubscribe(null);
}
}.take(0).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertError(errors, 1, NullPointerException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTakeTest method multiTake.
@Test
public void multiTake() {
final AtomicInteger count = new AtomicInteger();
Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription bs = new BooleanSubscription();
s.onSubscribe(bs);
for (int i = 0; !bs.isCancelled(); i++) {
System.out.println("Emit: " + i);
count.incrementAndGet();
s.onNext(i);
}
}
}).take(100).take(1).blockingForEach(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
System.out.println("Receive: " + t1);
}
});
assertEquals(1, count.get());
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method throttlingWithError.
@Test
public void throttlingWithError() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
Exception error = new TestException();
// Should be published since it is first
publishNext(subscriber, 100, "one");
// Should be skipped since onError will arrive before the timeout expires
publishNext(subscriber, 200, "two");
// Should be published as soon as the timeout expires.
publishError(subscriber, 300, error);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber).onNext("one");
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method throttlingWithCompleted.
@Test
public void throttlingWithCompleted() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
// publish as it's first
publishNext(subscriber, 100, "one");
// skip as it's last within the first 400
publishNext(subscriber, 300, "two");
// publish
publishNext(subscriber, 900, "three");
// skip
publishNext(subscriber, 905, "four");
// Should be published as soon as the timeout expires.
publishCompleted(subscriber, 1000);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("one");
inOrder.verify(subscriber, times(0)).onNext("two");
inOrder.verify(subscriber, times(1)).onNext("three");
inOrder.verify(subscriber, times(0)).onNext("four");
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method lateOnTimeoutError.
@Test
public void lateOnTimeoutError() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final Subscriber<?>[] sub = { null, null };
final Flowable<Integer> pp2 = new Flowable<Integer>() {
int count;
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
sub[count++] = s;
}
};
TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2)).test();
pp.onNext(0);
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
final Throwable ex = new TestException();
Runnable r2 = new Runnable() {
@Override
public void run() {
sub[0].onError(ex);
}
};
TestHelper.race(r1, r2);
ts.assertValueAt(0, 0);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
Aggregations