public static ExecutorLifecycle withNormalCleanupBehavior(Supplier<ExecutorService> executorServiceSupplier) { return new ExecutorLifecycle(executorServiceSupplier, normalCleanupBehavior()); }
/** * {@inheritDoc} */ @Override public void uncaughtException(Thread thread, Throwable throwable) { if (!conditionSettings.shouldExceptionBeIgnored(throwable)) { uncaughtThrowable.set(throwable); // We shutdown the executor "now" in order to fail the test immediately conditionSettings.getExecutorLifecycle().executeUnexpectedCleanupBehavior(executor); } }
public static ExecutorLifecycle withoutCleanup(Supplier<ExecutorService> executorServiceSupplier) { return new ExecutorLifecycle(executorServiceSupplier, noCleanup()); }
/** * Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility. * The supplier will be called only once and the thread it returns will be reused during all condition evaluations. * This is an advanced feature and it should only be used sparingly. * * @param threadSupplier A supplier of the thread that Awaitility will use when polling * @since 3.0.0 */ public static void pollThread(final Function<Runnable, Thread> threadSupplier) { defaultExecutorLifecycle = ExecutorLifecycle.withNormalCleanupBehavior(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return InternalExecutorServiceFactory.create(threadSupplier); } }); }
/** * Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility. * Note that the executor service must be shutdown manually! * This is an advanced feature and it should only be used sparingly. * * @param executorService The executor service that Awaitility will use when polling condition evaluations * @since 3.0.0 */ public static void pollExecutorService(final ExecutorService executorService) { defaultExecutorLifecycle = ExecutorLifecycle.withoutCleanup(executorService); }
/** * <p>Constructor for ConditionAwaiter.</p> * * @param conditionEvaluator a {@link ConditionEvaluator} object. * @param conditionSettings a {@link org.awaitility.core.ConditionSettings} object. */ ConditionAwaiter(final ConditionEvaluator conditionEvaluator, final ConditionSettings conditionSettings) { if (conditionEvaluator == null) { throw new IllegalArgumentException("You must specify a condition (was null)."); } if (conditionSettings == null) { throw new IllegalArgumentException("You must specify the condition settings (was null)."); } if (conditionSettings.shouldCatchUncaughtExceptions()) { Thread.setDefaultUncaughtExceptionHandler(this); } this.conditionSettings = conditionSettings; this.conditionEvaluator = conditionEvaluator; this.executor = conditionSettings.getExecutorLifecycle().supplyExecutorService(); this.uncaughtThrowable = new AtomicReference<Throwable>(); }
} finally { uncaughtThrowable.set(null); conditionSettings.getExecutorLifecycle().executeNormalCleanupBehavior(executor);
/** * Instructs Awaitility to execute the polling of the condition from the same as the test. * This is an advanced feature and you should be careful when combining this with conditions that * wait forever (or a long time) since Awaitility cannot interrupt the thread when using the same * thread as the test. For safety you should always combine tests using this feature with a test framework specific timeout, * for example in JUnit: *<pre> * @Test(timeout = 2000L) * public void myTest() { * Awaitility.pollInSameThread(); * await().forever().until(...); * } *</pre> * * @since 3.0.0 */ public static void pollInSameThread() { defaultExecutorLifecycle = ExecutorLifecycle.withNormalCleanupBehavior(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return InternalExecutorServiceFactory.sameThreadExecutorService(); } }); }
public static ExecutorLifecycle withoutCleanup(final ExecutorService executorService) { return withoutCleanup(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return executorService; } }); }
/** * <p>Constructor for ConditionAwaiter.</p> * * @param conditionEvaluator a {@link ConditionEvaluator} object. * @param conditionSettings a {@link org.awaitility.core.ConditionSettings} object. */ ConditionAwaiter(final ConditionEvaluator conditionEvaluator, final ConditionSettings conditionSettings) { if (conditionEvaluator == null) { throw new IllegalArgumentException("You must specify a condition (was null)."); } if (conditionSettings == null) { throw new IllegalArgumentException("You must specify the condition settings (was null)."); } if (conditionSettings.shouldCatchUncaughtExceptions()) { Thread.setDefaultUncaughtExceptionHandler(this); } this.conditionSettings = conditionSettings; this.conditionEvaluator = conditionEvaluator; this.executor = conditionSettings.getExecutorLifecycle().supplyExecutorService(); this.uncaughtThrowable = new AtomicReference<Throwable>(); }
} finally { uncaughtThrowable.set(null); conditionSettings.getExecutorLifecycle().executeNormalCleanupBehavior(executor);
/** * Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility. * The supplier will be called only once and the thread it returns will be reused during all condition evaluations. * This is an advanced feature and it should only be used sparingly. * * @param threadSupplier A supplier of the thread that Awaitility will use when polling * @return the condition factory */ public ConditionFactory pollThread(final Function<Runnable, Thread> threadSupplier) { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, false, exceptionsIgnorer, conditionEvaluationListener, ExecutorLifecycle.withNormalCleanupBehavior(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return InternalExecutorServiceFactory.create(threadSupplier); } })); }
public static ExecutorLifecycle withNormalCleanupBehavior(Supplier<ExecutorService> executorServiceSupplier) { return new ExecutorLifecycle(executorServiceSupplier, normalCleanupBehavior()); }
public static ExecutorLifecycle withoutCleanup(Supplier<ExecutorService> executorServiceSupplier) { return new ExecutorLifecycle(executorServiceSupplier, noCleanup()); }
/** * Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility. * Note that the executor service must be shutdown manually! * * This is an advanced feature and it should only be used sparingly. * * @param executorService The executor service that Awaitility will use when polling condition evaluations * @return the condition factory */ public ConditionFactory pollExecutorService(ExecutorService executorService) { if (executorService != null && executorService instanceof ScheduledExecutorService) { throw new IllegalArgumentException("Poll executor service cannot be an instance of " + ScheduledExecutorService.class.getName()); } return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, false, exceptionsIgnorer, conditionEvaluationListener, ExecutorLifecycle.withoutCleanup(executorService)); }
/** * {@inheritDoc} */ @Override public void uncaughtException(Thread thread, Throwable throwable) { if (!conditionSettings.shouldExceptionBeIgnored(throwable)) { uncaughtThrowable.set(throwable); // We shutdown the executor "now" in order to fail the test immediately conditionSettings.getExecutorLifecycle().executeUnexpectedCleanupBehavior(executor); } }
/** * Instructs Awaitility to execute the polling of the condition from the same as the test. * This is an advanced feature and you should be careful when combining this with conditions that * wait forever (or a long time) since Awaitility cannot interrupt the thread when it's using the same * thread as the test. For safety you should always combine tests using this feature with a test framework specific timeout, * for example in JUnit: *<pre> * @Test(timeout = 2000L) * public void myTest() { * Awaitility.pollInSameThread(); * await().forever().until(...); * } *</pre> * @return the condition factory */ public ConditionFactory pollInSameThread() { return new ConditionFactory(alias, timeoutConstraint, pollInterval, pollDelay, false, exceptionsIgnorer, conditionEvaluationListener, ExecutorLifecycle.withNormalCleanupBehavior(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return InternalExecutorServiceFactory.sameThreadExecutorService(); } })); }
public static ExecutorLifecycle withoutCleanup(final ExecutorService executorService) { return withoutCleanup(new Supplier<ExecutorService>() { @Override public ExecutorService get() { return executorService; } }); }
executorLifecycle = ExecutorLifecycle.withNormalCleanupBehavior(new Supplier<ExecutorService>() { @Override public ExecutorService get() {
/** * Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility. * Note that the executor service must be shutdown manually! * This is an advanced feature and it should only be used sparingly. * * @param executorService The executor service that Awaitility will use when polling condition evaluations * @since 3.0.0 */ public static void pollExecutorService(final ExecutorService executorService) { defaultExecutorLifecycle = ExecutorLifecycle.withoutCleanup(executorService); }