private void rethrowExceptionIfAny() { if (storedException != null) { throw rethrow(storedException); } }
public static void sleepSecondsThrowException(int seconds) { try { TimeUnit.SECONDS.sleep(seconds); } catch (InterruptedException e) { throw rethrow(e); } }
public static void sleepMillisThrowException(int millis) { try { MILLISECONDS.sleep(millis); } catch (InterruptedException e) { throw rethrow(e); } }
public static void sleepSecondsThrowException(int seconds) { try { TimeUnit.SECONDS.sleep(seconds); } catch (InterruptedException e) { throw rethrow(e); } }
public static void sleepMillisThrowException(int millis) { try { TimeUnit.MILLISECONDS.sleep(millis); } catch (InterruptedException e) { throw rethrow(e); } }
/** * Waits for all threads to finish. * * If {@link #throwException} is <code>true</code> this method will throw the first occurred exception of a thread. */ public void awaitCompletion() { for (Thread thread : threads) { try { thread.join(); } catch (InterruptedException e) { throw rethrow(e); } } if (caughtException != null) { throw rethrow(caughtException); } }
/** * Waits for all threads to finish. * * If {@link #throwException} is <code>true</code> this method will throw the first occurred exception of a thread. */ public void awaitCompletion() { for (Thread thread : threads) { try { thread.join(); } catch (InterruptedException e) { throw rethrow(e); } } if (caughtException != null) { throw rethrow(caughtException); } }
private void acquirePermit(int count) { throttlingLogger.info("At: " + counter.get()); try { if (!semaphore.tryAcquire(count, DEFAULT_TIMEOUT_MINUTES, MINUTES)) { throw new IllegalStateException("Timeout when trying to acquire a permit! Completed: " + counter.get()); } } catch (InterruptedException e) { throw rethrow(e); } }
@Override public void run() { try { if (!runner.run()) { success.set(false); } } catch (Exception e) { throw rethrow(e); } } });
static Properties getUserProperties() { FileInputStream inputStream = null; try { Properties properties = new Properties(); File userPropertiesFile = new File(SimulatorProperties.PROPERTIES_FILE_NAME).getAbsoluteFile(); if (!userPropertiesFile.exists()) { return properties; } inputStream = new FileInputStream(userPropertiesFile); properties.load(inputStream); return properties; } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }
void load(File file) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); properties.load(inputStream); if (containsKey("HAZELCAST_VERSION_SPEC")) { throw new IOException("'HAZELCAST_VERSION_SPEC' property is deprecated, Use 'VERSION_SPEC' instead."); } } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }
@SuppressWarnings({"unchecked", "PMD.PreserveStackTrace"}) private Object newTestInstance() { String testClassName = testCase.getClassname(); try { Class testClazz = TestContainer.class.getClassLoader().loadClass(testClassName); Constructor constructor = testClazz.getConstructor(); return constructor.newInstance(); } catch (IllegalTestException e) { throw rethrow(e); } catch (NoSuchMethodException e) { throw new IllegalTestException(format("Test class '%s' should have a public no arg constructor", testClassName)); } catch (Exception e) { throw new IllegalTestException("Could not create instance of " + testClassName, e); } }
public static StringBuilder execute(String command) { StringBuilder sb = new StringBuilder(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing bash command: " + command); } try { // create a process for the shell ProcessBuilder pb = new ProcessBuilder("bash", "-c", command); pb = pb.redirectErrorStream(true); Process shell = pb.start(); new BashStreamGobbler(shell.getInputStream(), sb).start(); // wait for the shell to finish and get the return code int shellExitStatus = shell.waitFor(); if (shellExitStatus != 0) { LOGGER.error(format("Failed to execute [%s]", command)); LOGGER.error(sb.toString()); exitWithError(); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Bash output: " + NEW_LINE + sb); } } return sb; } catch (Exception e) { throw rethrow(e); } }
throw rethrow(exception);
@Override public void run() { try { worker.beforeRun(); worker.run(); worker.afterRun(); } catch (Exception e) { throw rethrow(e); } } }
task.run(); } catch (Exception e) { throw rethrow(e);
@Override public final void run() { String threadName = Thread.currentThread().getName(); logger.info(threadName + " started"); try { beforeRun(); boolean explicitStop = false; try { timeStepLoop(); } catch (StopException e) { explicitStop = true; logger.info(threadName + " stopped using StopException"); } afterRun(); logger.info(threadName + " completed normally" + (explicitStop ? " with StopException" : "")); } catch (Throwable e) { logger.warning(threadName + " completed with exception " + e.getClass().getName() + " message: " + e.getMessage()); throw rethrow(e); } }
@Override @SuppressWarnings("unchecked") public void pushEntry(K key, V value) { acquirePermit(1); try { ICompletableFuture<V> future = storeAsync(key, value); future.andThen(callback); } catch (Exception e) { releasePermit(1); throw rethrow(e); } }
private void registerTestPhaseTasks() { try { registerSetupTask(); registerPrepareTasks(false); registerPrepareTasks(true); taskPerPhaseMap.put(WARMUP, runStrategy.getWarmupCallable()); registerTask(AfterWarmup.class, new AfterWarmupFilter(false), LOCAL_AFTER_WARMUP); registerTask(AfterWarmup.class, new AfterWarmupFilter(true), GLOBAL_AFTER_WARMUP); taskPerPhaseMap.put(RUN, runStrategy.getRunCallable()); registerTask(Verify.class, new VerifyFilter(false), LOCAL_VERIFY); registerTask(Verify.class, new VerifyFilter(true), GLOBAL_VERIFY); registerTask(Teardown.class, new TeardownFilter(false), LOCAL_TEARDOWN); registerTask(Teardown.class, new TeardownFilter(true), GLOBAL_TEARDOWN); } catch (IllegalTestException e) { throw rethrow(e); } catch (Exception e) { throw new IllegalTestException(format("Error during search for annotated test methods in %s: [%s] %s", testClass.getName(), e.getClass().getSimpleName(), e.getMessage()), e); } }
public boolean run() { logDetails(); test.initStartTime(); try { run0(); } catch (TestCaseAbortedException e) { echo(e.getMessage()); // unblock other TestCaseRunner threads, if fail fast is not set and they have no failures on their own TestPhase testPhase = e.testPhase; while (testPhase != null) { decrementAndGetCountDownLatch(testPhase); testPhase = testPhase.getNextTestPhaseOrNull(); } } catch (Exception e) { throw rethrow(e); } finally { test.setCompletedStatus(hasFailure() ? FAILED : SUCCESS); } return test.getCompletedStatus() == SUCCESS; }