| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
import junit.framework.*; |
| 10 |
|
import edu.emory.mathcs.backport.java.util.concurrent.Semaphore; |
| 11 |
|
|
|
|
|
| 77.3% |
Uncovered Elements: 5 (22) |
Complexity: 8 |
Complexity Density: 0.57 |
|
| 12 |
|
public class ThreadLocalTest extends JSR166TestCase { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 13 |
0
|
public static void main(String[] args) {... |
| 14 |
0
|
junit.textui.TestRunner.run(suite()); |
| 15 |
|
} |
| 16 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 17 |
1
|
public static Test suite() {... |
| 18 |
1
|
return new TestSuite(ThreadLocalTest.class); |
| 19 |
|
} |
| 20 |
|
|
| 21 |
|
static ThreadLocal tl = new ThreadLocal() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 22 |
0
|
public Object initialValue() {... |
| 23 |
0
|
return one; |
| 24 |
|
} |
| 25 |
|
}; |
| 26 |
|
|
| 27 |
|
static InheritableThreadLocal itl = |
| 28 |
|
new InheritableThreadLocal() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 29 |
1
|
protected Object initialValue() {... |
| 30 |
1
|
return zero; |
| 31 |
|
} |
| 32 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 33 |
9
|
protected Object childValue(Object parentValue) {... |
| 34 |
9
|
return new Integer(((Integer)parentValue).intValue() + 1); |
| 35 |
|
} |
| 36 |
|
}; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
| 61 |
|
private class ITLThread extends Thread { |
| 62 |
|
final int[] x; |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
10
|
ITLThread(int[] array) { x = array; }... |
|
|
|
| 94.7% |
Uncovered Elements: 1 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 64 |
10
|
public void run() {... |
| 65 |
10
|
Thread child = null; |
| 66 |
10
|
if (((Integer)itl.get()).intValue() < x.length - 1) { |
| 67 |
9
|
child = new ITLThread(x); |
| 68 |
9
|
child.start(); |
| 69 |
|
} |
| 70 |
10
|
Thread.currentThread().yield(); |
| 71 |
|
|
| 72 |
5
|
int threadId = ((Integer)itl.get()).intValue(); |
| 73 |
55
|
for (int j = 0; j < threadId; j++) { |
| 74 |
45
|
x[threadId]++; |
| 75 |
45
|
Thread.currentThread().yield(); |
| 76 |
|
} |
| 77 |
|
|
| 78 |
10
|
if (child != null) { |
| 79 |
9
|
try { |
| 80 |
9
|
child.join(); |
| 81 |
|
} catch(InterruptedException e) { |
| 82 |
0
|
threadUnexpectedException(); |
| 83 |
|
} |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
1
PASS
|
|
| 91 |
1
|
public void testGenericITL() {... |
| 92 |
1
|
final int threadCount = 10; |
| 93 |
1
|
final int x[] = new int[threadCount]; |
| 94 |
1
|
Thread progenitor = new ITLThread(x); |
| 95 |
1
|
try { |
| 96 |
1
|
progenitor.start(); |
| 97 |
1
|
progenitor.join(); |
| 98 |
11
|
for(int i = 0; i < threadCount; i++) { |
| 99 |
10
|
assertEquals(i, x[i]); |
| 100 |
|
} |
| 101 |
|
} catch(InterruptedException e) { |
| 102 |
0
|
unexpectedException(); |
| 103 |
|
} |
| 104 |
|
} |
| 105 |
|
} |
| 106 |
|
|