/** * @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; }
/** * 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")); }
/** * 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")); }
/** * Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()} * 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 createIoScheduler(@NonNull ThreadFactory threadFactory) { return new IoScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); }
/** * Create an instance of the default {@link Scheduler} used for {@link Schedulers#io()} * 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 createIoScheduler(@NonNull ThreadFactory threadFactory) { return new IoScheduler(ObjectHelper.requireNonNull(threadFactory, "threadFactory is null")); }
/** * 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")); }