@Test(expected = NullPointerException.class) public void ambArrayNull() { Single.ambArray((Single<Integer>[])null); }
/** * Signals the event of this or the other SingleSource whichever signals first. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambWith} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param other the other SingleSource to race for the first emission of success or error * @return the new Single instance. A subscription to this provided source will occur after subscribing * to the current source. * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public final Single<T> ambWith(SingleSource<? extends T> other) { ObjectHelper.requireNonNull(other, "other is null"); return ambArray(this, other); }
/** * Signals the event of this or the other SingleSource whichever signals first. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambWith} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param other the other SingleSource to race for the first emission of success or error * @return the new Single instance. A subscription to this provided source will occur after subscribing * to the current source. * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public final Single<T> ambWith(SingleSource<? extends T> other) { ObjectHelper.requireNonNull(other, "other is null"); return ambArray(this, other); }
@SuppressWarnings("unchecked") @Test public void ambArrayOneIsNull() { Single.ambArray(null, just1) .test() .assertError(NullPointerException.class); }
@SuppressWarnings("unchecked") @Test public void ambArrayEmpty() { Single.ambArray() .test() .assertFailure(NoSuchElementException.class); }
@SuppressWarnings("unchecked") @Test public void ambArrayOrder() { Single<Integer> error = Single.error(new RuntimeException()); Single.ambArray(Single.just(1), error).test().assertValue(1); } }
@SuppressWarnings("unchecked") @Test public void ambSingleSource() { assertSame(Single.never(), Single.ambArray(Single.never())); }
@SuppressWarnings("unchecked") @Test public void error() { Single.ambArray(Single.error(new TestException()), Single.just(1)) .test() .assertFailure(TestException.class); }
@Test public void nullSourceSuccessRace() { for (int i = 0; i < 1000; i++) { List<Throwable> errors = TestCommonHelper.trackPluginErrors(); try { final Subject<Integer> ps = ReplaySubject.create(); ps.onNext(1); @SuppressWarnings("unchecked") final Single<Integer> source = Single.ambArray(ps.singleOrError(), Single.<Integer>never(), Single.<Integer>never(), null); Runnable r1 = new Runnable() { @Override public void run() { source.test(); } }; Runnable r2 = new Runnable() { @Override public void run() { ps.onComplete(); } }; TestCommonHelper.race(r1, r2, Schedulers.single()); if (!errors.isEmpty()) { TestCommonHelper.assertError(errors, 0, NullPointerException.class); } } finally { RxJavaCommonPlugins.reset(); } } }
final Subject<Integer> ps2 = PublishSubject.create(); Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test();
final Subject<Integer> ps2 = PublishSubject.create(); Single.ambArray(ps1.singleOrError(), ps2.singleOrError()).test();