use of io.reactivex.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableAmbTest method ambMany.
@Ignore("No 2-9 arg overloads")
@SuppressWarnings("unchecked")
@Test
public void ambMany() throws Exception {
for (int i = 2; i < 10; i++) {
Class<?>[] clazz = new Class[i];
Arrays.fill(clazz, Publisher.class);
PublishProcessor<Integer>[] ps = new PublishProcessor[i];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
ps[k] = PublishProcessor.create();
}
Method m = Flowable.class.getMethod("amb", clazz);
Flowable<Integer> obs = (Flowable<Integer>) m.invoke(null, (Object[]) ps);
TestSubscriber<Integer> ts = TestSubscriber.create();
obs.subscribe(ts);
for (int k = 0; k < i; k++) {
assertTrue("@" + i + "/" + k + " has no observers?", ps[k].hasSubscribers());
}
ps[j].onNext(j);
ps[j].onComplete();
for (int k = 0; k < i; k++) {
assertFalse("@" + i + "/" + k + " has observers?", ps[k].hasSubscribers());
}
ts.assertValue(j);
ts.assertNoErrors();
ts.assertComplete();
}
}
}
use of io.reactivex.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableAmbTest method ambManyComplete.
@Ignore("No 2-9 arg overloads")
@SuppressWarnings("unchecked")
@Test
public void ambManyComplete() throws Exception {
for (int i = 2; i < 10; i++) {
Class<?>[] clazz = new Class[i];
Arrays.fill(clazz, Publisher.class);
PublishProcessor<Integer>[] ps = new PublishProcessor[i];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
ps[k] = PublishProcessor.create();
}
Method m = Flowable.class.getMethod("amb", clazz);
Flowable<Integer> obs = (Flowable<Integer>) m.invoke(null, (Object[]) ps);
TestSubscriber<Integer> ts = TestSubscriber.create();
obs.subscribe(ts);
for (int k = 0; k < i; k++) {
assertTrue("@" + i + "/" + k + " has no observers?", ps[k].hasSubscribers());
}
ps[j].onComplete();
for (int k = 0; k < i; k++) {
assertFalse("@" + i + "/" + k + " has observers?", ps[k].hasSubscribers());
}
ts.assertNoValues();
ts.assertNoErrors();
ts.assertComplete();
}
}
}
use of io.reactivex.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableDelayTest method testDelayWithFlowableNormal1.
@Test
public void testDelayWithFlowableNormal1() {
PublishProcessor<Integer> source = PublishProcessor.create();
final List<PublishProcessor<Integer>> delays = new ArrayList<PublishProcessor<Integer>>();
final int n = 10;
for (int i = 0; i < n; i++) {
PublishProcessor<Integer> delay = PublishProcessor.create();
delays.add(delay);
}
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return delays.get(t1);
}
};
Subscriber<Object> o = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
for (int i = 0; i < n; i++) {
source.onNext(i);
delays.get(i).onNext(i);
inOrder.verify(o).onNext(i);
}
source.onComplete();
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableAmbTest method ambManyError.
@Ignore("No 2-9 arg overloads")
@SuppressWarnings("unchecked")
@Test
public void ambManyError() throws Exception {
for (int i = 2; i < 10; i++) {
Class<?>[] clazz = new Class[i];
Arrays.fill(clazz, Publisher.class);
PublishProcessor<Integer>[] ps = new PublishProcessor[i];
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
ps[k] = PublishProcessor.create();
}
Method m = Flowable.class.getMethod("amb", clazz);
Flowable<Integer> obs = (Flowable<Integer>) m.invoke(null, (Object[]) ps);
TestSubscriber<Integer> ts = TestSubscriber.create();
obs.subscribe(ts);
for (int k = 0; k < i; k++) {
assertTrue("@" + i + "/" + k + " has no observers?", ps[k].hasSubscribers());
}
ps[j].onError(new TestException(Integer.toString(j)));
for (int k = 0; k < i; k++) {
assertFalse("@" + i + "/" + k + " has observers?", ps[k].hasSubscribers());
}
ts.assertNoValues();
ts.assertError(TestException.class);
ts.assertNotComplete();
assertEquals(Integer.toString(j), ts.errors().get(0).getMessage());
}
}
}
use of io.reactivex.processors.PublishProcessor in project RxJava by ReactiveX.
the class FlowableAsObservableTest method testHidingError.
@Test
public void testHidingError() {
PublishProcessor<Integer> src = PublishProcessor.create();
Flowable<Integer> dst = src.hide();
assertFalse(dst instanceof PublishProcessor);
@SuppressWarnings("unchecked") DefaultSubscriber<Object> o = mock(DefaultSubscriber.class);
dst.subscribe(o);
src.onError(new TestException());
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
verify(o).onError(any(TestException.class));
}
Aggregations