use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method testSwitchWithComplete.
@Test
public void testSwitchWithComplete() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 60, "one");
publishNext(observer, 100, "two");
}
}));
publishNext(observer, 200, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 0, "three");
publishNext(observer, 100, "four");
}
}));
publishCompleted(observer, 250);
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyString());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("two");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("three");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("four");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method badSourceTimeout.
@Test
public void badSourceTimeout() {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onNext(1);
observer.onNext(2);
observer.onError(new TestException("First"));
observer.onNext(3);
observer.onComplete();
observer.onError(new TestException("Second"));
}
}.timeout(Functions.justFunction(Flowable.never()), Flowable.<Integer>never()).take(1).test().assertResult(1);
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableStrictTest method noCancelOnError.
@Test
public void noCancelOnError() {
final BooleanSubscription bs = new BooleanSubscription();
Flowable.fromPublisher(new Publisher<Object>() {
@Override
public void subscribe(Subscriber<? super Object> p) {
p.onSubscribe(bs);
p.onError(new TestException());
}
}).strict().subscribe(new Subscriber<Object>() {
Subscription s;
@Override
public void onSubscribe(Subscription s) {
this.s = s;
}
@Override
public void onNext(Object t) {
// not called
}
@Override
public void onError(Throwable t) {
s.cancel();
}
@Override
public void onComplete() {
// not called
}
});
assertFalse(bs.isCancelled());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableStrictTest method badRequestOnNextRace.
@Test
public void badRequestOnNextRace() {
for (int i = 0; i < 500; i++) {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
final PublishProcessor<Integer> pp = PublishProcessor.create();
final StrictSubscriber<Integer> s = new StrictSubscriber<Integer>(ts);
s.onSubscribe(new BooleanSubscription());
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
s.request(0);
}
};
TestHelper.race(r1, r2);
if (ts.valueCount() == 0) {
ts.assertFailure(IllegalArgumentException.class);
} else {
ts.assertValue(1).assertNoErrors().assertNotComplete();
}
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableStrictTest method doubleOnSubscribe.
@Test
public void doubleOnSubscribe() {
final BooleanSubscription bs1 = new BooleanSubscription();
final BooleanSubscription bs2 = new BooleanSubscription();
final TestSubscriber<Object> ts = TestSubscriber.create();
Flowable.fromPublisher(new Publisher<Object>() {
@Override
public void subscribe(Subscriber<? super Object> p) {
p.onSubscribe(bs1);
p.onSubscribe(bs2);
}
}).strict().subscribe(new Subscriber<Object>() {
@Override
public void onSubscribe(Subscription s) {
ts.onSubscribe(s);
}
@Override
public void onNext(Object t) {
ts.onNext(t);
}
@Override
public void onError(Throwable t) {
ts.onError(t);
}
@Override
public void onComplete() {
ts.onComplete();
}
});
ts.assertFailure(IllegalStateException.class);
assertTrue(bs1.isCancelled());
assertTrue(bs2.isCancelled());
String es = ts.errors().get(0).toString();
assertTrue(es, es.contains("ยง2.12"));
}
Aggregations