1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.httpinvoker;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.junit.After;
|
16
|
import org.unitils.UnitilsJUnit4;
|
17
|
|
18
|
/**
|
19
|
* @author cmathew
|
20
|
* @date 16 Oct 2015
|
21
|
*
|
22
|
*/
|
23
|
public abstract class ThreadedTest extends UnitilsJUnit4 {
|
24
|
|
25
|
private Set<TestThread> threadPool = new HashSet<TestThread>();
|
26
|
|
27
|
protected void invokeThread(TestThread thread) {
|
28
|
threadPool.add(thread);
|
29
|
thread.start();
|
30
|
}
|
31
|
|
32
|
@After
|
33
|
public void cleanup() throws Throwable {
|
34
|
try {
|
35
|
for(TestThread thread : threadPool) {
|
36
|
if(thread.isAlive()) {
|
37
|
thread.join();
|
38
|
}
|
39
|
}
|
40
|
|
41
|
for(TestThread thread : threadPool) {
|
42
|
if(thread.getThrowable() != null) {
|
43
|
throw thread.getThrowable();
|
44
|
}
|
45
|
}
|
46
|
} finally {
|
47
|
threadPool.clear();
|
48
|
}
|
49
|
}
|
50
|
}
|