Created
April 23, 2013 21:43
-
-
Save tadas-subonis/5447647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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