/** * @return true if one of the timeout-based await methods has timed out. * @see #clearTimeout() * @see #assertTimeout() * @see #assertNoTimeout() * @since 2.0.7 - experimental */ @Experimental public final boolean isTimeout() { return timeout; }
/** * Clears the timeout flag set by the await methods when they timed out. * @return this * @since 2.0.7 - experimental * @see #isTimeout() */ @SuppressWarnings("unchecked") @Experimental public final U clearTimeout() { timeout = false; return (U)this; }
/** * Returns true if the blockingX operators fail * with an IllegalStateException on a non-blocking scheduler * such as computation or single. * @return true if the blockingX operators fail on a non-blocking scheduler * @since 2.0.5 - experimental */ @Experimental public static boolean isFailOnNonBlockingScheduler() { return failNonBlockingScheduler; }
/** * Set the tag displayed along with an assertion failure's * other state information. * @param tag the string to display (null won't print any tag) * @return this * @since 2.0.7 - experimental */ @SuppressWarnings("unchecked") @Experimental public final U withTag(CharSequence tag) { this.tag = tag; return (U)this; }
/** * Explicitly named exception to indicate a Reactive-Streams * protocol violation. * @since 2.0.6 - experimental */ @Experimental public final class ProtocolViolationException extends IllegalStateException { private static final long serialVersionUID = 1644750035281290266L; /** * Creates an instance with the given message. * @param message the message */ public ProtocolViolationException(String message) { super(message); } }
/** * Wrapper for Throwable errors that are sent to `RxJavaCommonPlugins.onError`. * @since 2.0.6 - experimental */ @Experimental public final class UndeliverableException extends IllegalStateException { private static final long serialVersionUID = 1644750035281290266L; /** * Construct an instance by wrapping the given, non-null * cause Throwable. * @param cause the cause, not null */ public UndeliverableException(Throwable cause) { super(cause); } }
/** * Enables or disables the blockingX operators to fail * with an IllegalStateException on a non-blocking * scheduler such as computation or single. * @param enable enable or disable the feature * @since 2.0.5 - experimental */ @Experimental public static void setFailOnNonBlockingScheduler(boolean enable) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } failNonBlockingScheduler = enable; }
/** * Returns the current blocking handler or null if no custom handler * is set. * @return the current blocking handler or null if not specified * @since 2.0.5 - experimental */ @Experimental @Nullable public static BooleanSupplier getOnBeforeBlocking() { return onBeforeBlocking; }
/** * Asserts that some awaitX method has timed out. * @return this * @since 2.0.7 - experimental */ @SuppressWarnings("unchecked") @Experimental public final U assertTimeout() { if (!timeout) { throw fail("No timeout?!"); } return (U)this; }
/** * Await until the TestObserver/TestObserver receives the given * number of items or terminates by sleeping 10 milliseconds at a time * up to 5000 milliseconds of timeout. * @param atLeast the number of items expected at least * @return this * @see #awaitCount(int, Runnable, long) * @since 2.0.7 - experimental */ @Experimental public final U awaitCount(int atLeast) { return awaitCount(atLeast, TestWaitStrategy.SLEEP_10MS, 5000); }
/** * Asserts that some awaitX method has not timed out. * @return this * @since 2.0.7 - experimental */ @SuppressWarnings("unchecked") @Experimental public final U assertNoTimeout() { if (timeout) { throw fail("Timeout?!"); } return (U)this; } }
/** * Set the handler that is called when an operator attempts a blocking * await; the handler should return true to prevent the blocking * and to signal an IllegalStateException instead. * @param handler the handler to set, null resets to the default handler * that always returns false * @see #onBeforeBlocking() * @since 2.0.5 - experimental */ @Experimental public static void setOnBeforeBlocking(@Nullable BooleanSupplier handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } onBeforeBlocking = handler; }
/** * Await until the TestObserver/TestObserver receives the given * number of items or terminates by waiting according to the wait * strategy and up to 5000 milliseconds of timeout. * @param atLeast the number of items expected at least * @param waitStrategy a Runnable called when the current received count * hasn't reached the expected value and there was * no terminal event either, see {@link TestWaitStrategy} * for examples * @return this * @see #awaitCount(int, Runnable, long) * @since 2.0.7 - experimental */ @Experimental public final U awaitCount(int atLeast, Runnable waitStrategy) { return awaitCount(atLeast, waitStrategy, 5000); }
/** * Creates an UnicastSubject with the given internal buffer capacity hint, delay error flag and * a callback for the case when the single Subscriber cancels its subscription. * * <p>The callback, if not null, is called exactly once and * non-overlapped with any active replay. * * @param <T> the value type * @param capacityHint the hint to size the internal unbounded buffer * @param onTerminate the callback to run when the Subject is terminated or cancelled, null not allowed * @param delayError deliver pending onNext events before onError * @return an UnicastSubject instance * @since 2.0.8 - experimental */ @CheckReturnValue @Experimental public static <T> UnicastSubject<T> create(int capacityHint, Runnable onTerminate, boolean delayError) { return new UnicastSubject<T>(capacityHint, onTerminate, delayError); }
/** * Called before an operator attempts a blocking operation * such as awaiting a condition or signal * and should return true to indicate the operator * should not block but throw an IllegalArgumentException. * @return true if the blocking should be prevented * @see #setFailOnNonBlockingScheduler(boolean) * @since 2.0.5 - experimental */ @Experimental public static boolean onBeforeBlocking() { BooleanSupplier f = onBeforeBlocking; if (f != null) { try { return f.getAsBoolean(); } catch (Throwable ex) { throw ExceptionHelper.wrapOrThrow(ex); } } return false; }
/** * Assert that this TestObserver/TestObserver did not receive an onNext value which is equal to * the given value with respect to Objects.equals. * * @since 2.0.5 - experimental * @param value the value to expect not being received * @return this; */ @Experimental @SuppressWarnings("unchecked") public final U assertNever(T value) { int s = values.size(); for (int i = 0; i < s; i++) { T v = this.values.get(i); if (ObjectHelper.equals(v, value)) { throw fail("Value at position " + i + " is equal to " + valueAndClass(value) + "; Expected them to be different"); } } return (U) this; }
/** * Creates an UnicastSubject with an internal buffer capacity hint 16 and given delay error flag. * * <p>The callback, if not null, is called exactly once and * non-overlapped with any active replay. * * @param <T> the value type * @param delayError deliver pending onNext events before onError * @return an UnicastSubject instance * @since 2.0.8 - experimental */ @CheckReturnValue @Experimental public static <T> UnicastSubject<T> create(boolean delayError) { return new UnicastSubject<T>(bufferSize(), delayError); }
/** * Create an instance of the default {@link Scheduler} used for {@link Schedulers#newThread()} * except using {@code threadFactory} for thread creation. * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any * system properties for configuring new thread creation. Cannot be null. * @return the created Scheduler instance * @since 2.0.5 - experimental */ @Experimental @NonNull public static Scheduler createNewThreadScheduler(@NonNull ThreadFactory threadFactory) { return new NewThreadScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); }
/** * Create an instance of the default {@link Scheduler} used for {@link Schedulers#single()} * except using {@code threadFactory} for thread creation. * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any * system properties for configuring new thread creation. Cannot be null. * @return the created Scheduler instance * @since 2.0.5 - experimental */ @Experimental @NonNull public static Scheduler createSingleScheduler(@NonNull ThreadFactory threadFactory) { return new SingleScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); }
/** * Create an instance of the default {@link Scheduler} used for {@link Schedulers#computation()} * except using {@code threadFactory} for thread creation. * @param threadFactory thread factory to use for creating worker threads. Note that this takes precedence over any * system properties for configuring new thread creation. Cannot be null. * @return the created Scheduler instance * @since 2.0.5 - experimental */ @Experimental @NonNull public static Scheduler createComputationScheduler(@NonNull ThreadFactory threadFactory) { return new ComputationScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); }