Skip to content

Instantly share code, notes, and snippets.

@tadas-subonis
Created April 23, 2013 21:43
Show Gist options
  • Save tadas-subonis/5447647 to your computer and use it in GitHub Desktop.
Save tadas-subonis/5447647 to your computer and use it in GitHub Desktop.
void test(String[] args) throws Throwable {
/*
* Prepare
*/
ThreadPoolExecutor tpe = prepareTestThreadPool(threadCount, timeoutMillis);
long t0 = System.nanoTime();
for (int i = 0; i < threadCount; i++)
tpe.submit(new Runnable() { public void run() {}});
int count = countExecutorThreads();
if (millisElapsedSince(t0) < timeoutMillis)
equal(count, threadCount);
/*
* Execute
* (actually execution started when we started spawning runables,
* so it is a little bit hard to define boundary but lets put this
* one here)
*/
while (countExecutorThreads() > 0 &&
millisElapsedSince(t0) < 10 * 1000);
/*
* Assert
*/
equal(countExecutorThreads(), 0);
/*
* Cleanup
*/
tpe.shutdown();
check(tpe.allowsCoreThreadTimeOut());
check(tpe.awaitTermination(10, TimeUnit.SECONDS));
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new Exception("Some tests failed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment