public void shutdown() { ThreadSpawner spawner = new ThreadSpawner("workerJvmManagerShutdown", true); for (final WorkerProcess workerProcess : new ArrayList<WorkerProcess>(workerProcesses.values())) { spawner.spawn(new Runnable() { @Override public void run() { shutdown(workerProcess); } }); } spawner.awaitCompletion(); }
/** * Creates a {@link ThreadSpawner} which can report exceptions to the {@link ExceptionReporter} or throw them directly. * * @param identifier identifier to give reported exceptions a context * @param throwException <code>true</code> if exceptions should be directly thrown, * <code>false</code> if {@link ExceptionReporter} should be used */ public ThreadSpawner(String identifier, boolean throwException) { this.identifier = identifier; this.throwException = throwException; this.exceptionHandler = initExceptionHandler(throwException); }
private ThreadSpawner spawnThreads(TimeStepRunner[] runners, boolean warmup) { ThreadSpawner spawner = new ThreadSpawner(testContext.getTestId()); for (TimeStepRunner runner : runners) { String executionGroup = runner.executionGroup; String name = testContext.getTestId(); if (!executionGroup.equals("")) { name += "-" + executionGroup; } name += warmup ? "-warmup" : "-run"; name += "Thread"; spawner.spawn(name, runner); } return spawner; }
/** * Spawns a new thread for the given {@link Runnable}. * * @param runnable the {@link Runnable} to execute * @return the created thread */ public Thread spawn(Runnable runnable) { return spawn(testId + "-Thread", runnable); }
@Override public Object call() throws Exception { try { LOGGER.info(format("Spawning %d worker threads for running %s", totalThreadCount, testContext.getTestId())); if (totalThreadCount <= 0) { return null; } runners = createRunners(false); onRunStarted(); ThreadSpawner spawner = spawnThreads(runners, false); spawner.awaitCompletion(); return null; } finally { onRunCompleted(); } } };
/** * Spawns a new thread for the given {@link Runnable}. * * @param namePrefix the name prefix for the thread * @param runnable the {@link Runnable} to execute * @return the created thread */ public Thread spawn(String namePrefix, Runnable runnable) { checkNotNull(namePrefix, "namePrefix can't be null"); checkNotNull(runnable, "runnable can't be null"); String name = newName(namePrefix); Thread thread; if (throwException) { thread = new ThrowExceptionThread(name, runnable); thread.setUncaughtExceptionHandler(exceptionHandler); } else { thread = new ReportExceptionThread(testId, name, runnable); } threads.add(thread); thread.start(); return thread; }
/** * Spawns a new thread for the given {@link Runnable}. * * @param namePrefix the name prefix for the thread * @param runnable the {@link Runnable} to execute * @return the created thread */ public Thread spawn(String namePrefix, Runnable runnable) { checkNotNull(namePrefix, "namePrefix can't be null"); checkNotNull(runnable, "runnable can't be null"); String name = getName(namePrefix); Thread thread; if (throwException) { thread = new ThrowExceptionThread(name, runnable); thread.setUncaughtExceptionHandler(exceptionHandler); } else { thread = new ReportExceptionThread(identifier, name, runnable); } threads.add(thread); thread.start(); return thread; }
private ThreadSpawner spawnThreads(IWorker[] workers) throws Exception { ThreadSpawner spawner = new ThreadSpawner(testContext.getTestId()); for (IWorker worker : workers) { spawner.spawn(new WorkerTask(worker)); } return spawner; }
/** * Spawns a new thread for the given {@link Runnable}. * * @param runnable the {@link Runnable} to execute * @return the created thread */ public Thread spawn(Runnable runnable) { return spawn(identifier + "-Thread", runnable); }
@Override public Object call() throws Exception { try { LOGGER.info(format("Spawning %d worker threads for warmup %s", totalThreadCount, testContext.getTestId())); if (totalThreadCount <= 0) { return null; } runners = createRunners(true); onRunStarted(); ThreadSpawner spawner = spawnThreads(runners, true); spawner.awaitCompletion(); return null; } finally { onRunCompleted(); } } };
@Run public void run() { ThreadSpawner spawner = new ThreadSpawner(name); for (int queueIndex = 0; queueIndex < queueLength; queueIndex++) { for (int i = 0; i < threadsPerQueue; i++) { spawner.spawn(new Worker(queueIndex)); } } spawner.awaitCompletion(); }
@Override public Object call() throws Exception { try { LOGGER.info(format("Spawning %d worker threads for test %s", threadCount, testContext.getTestId())); if (threadCount <= 0) { return null; } // create the workers. IWorker[] workers = createWorkers(); onRunStarted(); // spawn workers-threads and wait for completion ThreadSpawner spawner = spawnThreads(workers); spawner.awaitCompletion(); // call the afterCompletion() method on a single instance of the worker workers[0].afterCompletion(); return null; } finally { onRunCompleted(); } } };
/** * Creates a {@link ThreadSpawner} which can report exceptions to the {@link ExceptionReporter} or throw them directly. * * @param testId testId to give reported exceptions a context * @param throwException <code>true</code> if exceptions should be directly thrown, * <code>false</code> if {@link ExceptionReporter} should be used */ public ThreadSpawner(String testId, boolean throwException) { this.testId = testId; this.throwException = throwException; this.exceptionHandler = initExceptionHandler(throwException); }
@Run public void run() { ThreadSpawner spawner = new ThreadSpawner(name); for (int i = 0; i < threadCount; i++) { spawner.spawn(new Worker()); } spawner.awaitCompletion(); }
private boolean runParallel() { final AtomicBoolean success = new AtomicBoolean(true); ThreadSpawner spawner = new ThreadSpawner("runParallel", true); for (final TestCaseRunner runner : runners) { spawner.spawn(new Runnable() { @Override public void run() { try { if (!runner.run()) { success.set(false); } } catch (Exception e) { throw rethrow(e); } } }); } spawner.awaitCompletion(); return success.get(); }
@Run public void run() { ThreadSpawner spawner = new ThreadSpawner(name); for (int i = 0; i < threadCount; i++) { spawner.spawn(new Worker()); } spawner.awaitCompletion(); }
@Run public void run() { ThreadSpawner spawner = new ThreadSpawner(name); for (int i = 0; i < threadCount; i++) { spawner.spawn(new Worker()); } spawner.awaitCompletion(); }
@Run public void run() { ThreadSpawner spawner = new ThreadSpawner(name); for (int i = 0; i < mapIntegrityThreadCount; i++) { integrityThreads[i] = new MapIntegrityThread(); spawner.spawn(integrityThreads[i]); } for (int i = 0; i < stressThreadCount; i++) { spawner.spawn(new StressThread()); } spawner.awaitCompletion(); }
public static void checkInstallation(Bash bash, SimulatorProperties properties, ComponentRegistry registry) { if (runMode(properties) != RunMode.Remote) { return; } ThreadSpawner spawner = new ThreadSpawner("checkInstallation", true); for (AgentData agentData : registry.getAgents()) { spawner.spawn(new CheckAgentInstallationTask(agentData, bash)); } spawner.awaitCompletion(); }
private void startWorkers(boolean isMember, Map<SimulatorAddress, List<WorkerProcessSettings>> deploymentPlan) { ThreadSpawner spawner = new ThreadSpawner("createWorkers", true); int workerIndex = 0; String workerType = isMember ? "member" : "client"; for (Map.Entry<SimulatorAddress, List<WorkerProcessSettings>> entry : deploymentPlan.entrySet()) { SimulatorAddress agentAddress = entry.getKey(); AgentData agent = componentRegistry.getAgent(agentAddress); List<WorkerProcessSettings> workersSettings = entry.getValue(); spawner.spawn(new StartWorkersOnAgentTask(workersSettings, startupDelayMs * workerIndex, agent, workerType)); if (isMember) { workerIndex++; } } spawner.awaitCompletion(); }