1 package org.apache.maven.surefire.junitcore.pc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.junitcore.JUnitCoreParameters;
23 import org.apache.maven.surefire.junitcore.Logger;
24 import org.apache.maven.surefire.testset.TestSetFailedException;
25 import org.junit.AfterClass;
26 import org.junit.BeforeClass;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.experimental.theories.DataPoint;
31 import org.junit.experimental.theories.Theories;
32 import org.junit.experimental.theories.Theory;
33 import org.junit.rules.ExpectedException;
34 import org.junit.rules.Stopwatch;
35 import org.junit.runner.JUnitCore;
36 import org.junit.runner.Result;
37 import org.junit.runner.RunWith;
38
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.Map;
42 import java.util.concurrent.ExecutionException;
43
44 import static org.apache.maven.surefire.junitcore.pc.ParallelComputerUtil.*;
45 import static org.apache.maven.surefire.junitcore.JUnitCoreParameters.*;
46 import static org.hamcrest.core.Is.is;
47 import static org.junit.Assert.*;
48 import static java.util.concurrent.TimeUnit.MILLISECONDS;
49
50
51
52
53
54
55
56
57
58 @RunWith( Theories.class )
59 public final class ParallelComputerUtilTest
60 {
61 @DataPoint
62 public static final int CPU_1 = 1;
63
64 @DataPoint
65 public static final int CPU_4 = 4;
66
67 @Rule
68 public final ExpectedException exception = ExpectedException.none();
69
70 @Rule
71 public final Stopwatch stopwatch = new Stopwatch() {};
72
73 @BeforeClass
74 public static void beforeClass()
75 {
76 ParallelComputerUtil.overrideAvailableProcessors( 1 );
77 }
78
79 @AfterClass
80 public static void afterClass()
81 {
82 ParallelComputerUtil.setDefaultAvailableProcessors();
83 }
84
85 @Before
86 public void beforeTest()
87 {
88 assertFalse( Thread.currentThread().isInterrupted() );
89 }
90
91 private static Map<String, String> parallel( String parallel )
92 {
93 return Collections.singletonMap( PARALLEL_KEY, parallel );
94 }
95
96 @Test
97 public void unknownParallel()
98 throws TestSetFailedException
99 {
100 Map<String, String> properties = new HashMap<String, String>();
101 exception.expect( TestSetFailedException.class );
102 resolveConcurrency( new JUnitCoreParameters( properties ), null );
103 }
104
105 @Test
106 public void unknownThreadCountSuites()
107 throws TestSetFailedException
108 {
109 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suites" ) );
110 assertTrue( params.isParallelSuites() );
111 assertFalse( params.isParallelClasses() );
112 assertFalse( params.isParallelMethods() );
113 exception.expect( TestSetFailedException.class );
114 resolveConcurrency( params, null );
115 }
116
117 @Test
118 public void unknownThreadCountClasses()
119 throws TestSetFailedException
120 {
121 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "classes" ) );
122 assertFalse( params.isParallelSuites() );
123 assertTrue( params.isParallelClasses() );
124 assertFalse( params.isParallelMethods() );
125 exception.expect( TestSetFailedException.class );
126 resolveConcurrency( params, null );
127 }
128
129 @Test
130 public void unknownThreadCountMethods()
131 throws TestSetFailedException
132 {
133 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "methods" ) );
134 assertFalse( params.isParallelSuites() );
135 assertFalse( params.isParallelClasses() );
136 assertTrue( params.isParallelMethods() );
137 exception.expect( TestSetFailedException.class );
138 resolveConcurrency( params, null );
139 }
140
141 @Test
142 public void unknownThreadCountBoth()
143 throws TestSetFailedException
144 {
145 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "both" ) );
146 assertFalse( params.isParallelSuites() );
147 assertTrue( params.isParallelClasses() );
148 assertTrue( params.isParallelMethods() );
149 exception.expect( TestSetFailedException.class );
150 resolveConcurrency( params, null );
151 }
152
153 @Test
154 public void unknownThreadCountAll()
155 throws TestSetFailedException
156 {
157 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "all" ) );
158 assertTrue( params.isParallelSuites() );
159 assertTrue( params.isParallelClasses() );
160 assertTrue( params.isParallelMethods() );
161 exception.expect( TestSetFailedException.class );
162 resolveConcurrency( params, null );
163 }
164
165 @Test
166 public void unknownThreadCountSuitesAndClasses()
167 throws TestSetFailedException
168 {
169 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suitesAndClasses" ) );
170 assertTrue( params.isParallelSuites() );
171 assertTrue( params.isParallelClasses() );
172 assertFalse( params.isParallelMethods() );
173 exception.expect( TestSetFailedException.class );
174 resolveConcurrency( params, null );
175 }
176
177 @Test
178 public void unknownThreadCountSuitesAndMethods()
179 throws TestSetFailedException
180 {
181 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suitesAndMethods" ) );
182 assertTrue( params.isParallelSuites() );
183 assertFalse( params.isParallelClasses() );
184 assertTrue( params.isParallelMethods() );
185 exception.expect( TestSetFailedException.class );
186 resolveConcurrency( params, null );
187 }
188
189 @Test
190 public void unknownThreadCountClassesAndMethods()
191 throws TestSetFailedException
192 {
193 JUnitCoreParameters params = new JUnitCoreParameters( parallel( "classesAndMethods" ) );
194 assertFalse( params.isParallelSuites() );
195 assertTrue( params.isParallelClasses() );
196 assertTrue( params.isParallelMethods() );
197 exception.expect( TestSetFailedException.class );
198 resolveConcurrency( params, null );
199 }
200
201 @Theory
202 public void useUnlimitedThreadsSuites( int cpu )
203 throws TestSetFailedException
204 {
205 ParallelComputerUtil.overrideAvailableProcessors( cpu );
206 Map<String, String> properties = new HashMap<String, String>();
207 properties.put(PARALLEL_KEY, "suites");
208 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
209 JUnitCoreParameters params = new JUnitCoreParameters( properties );
210 Concurrency concurrency = resolveConcurrency( params, null );
211 assertTrue( params.isParallelSuites() );
212 assertFalse( params.isParallelClasses() );
213 assertFalse( params.isParallelMethods() );
214 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
215 assertThat( concurrency.suites, is( Integer.MAX_VALUE ) );
216 assertThat( concurrency.classes, is( 0 ) );
217 assertThat( concurrency.methods, is( 0 ) );
218
219 properties.put(THREADCOUNTSUITES_KEY, "5");
220 params = new JUnitCoreParameters( properties );
221 concurrency = resolveConcurrency( params, null );
222 assertTrue( params.isParallelSuites() );
223 assertFalse( params.isParallelClasses() );
224 assertFalse( params.isParallelMethods() );
225 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
226 assertThat( concurrency.suites, is( 5 * cpu ) );
227 assertThat( concurrency.classes, is( 0 ) );
228 assertThat( concurrency.methods, is( 0 ) );
229 }
230
231 @Theory
232 public void useUnlimitedThreadsClasses( int cpu )
233 throws TestSetFailedException
234 {
235 ParallelComputerUtil.overrideAvailableProcessors( cpu );
236 Map<String, String> properties = new HashMap<String, String>();
237 properties.put(PARALLEL_KEY, "classes");
238 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
239 JUnitCoreParameters params = new JUnitCoreParameters( properties );
240 Concurrency concurrency = resolveConcurrency( params, null );
241 assertFalse( params.isParallelSuites() );
242 assertTrue( params.isParallelClasses() );
243 assertFalse( params.isParallelMethods() );
244 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
245 assertThat( concurrency.suites, is( 0 ) );
246 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
247 assertThat( concurrency.methods, is( 0 ) );
248
249 properties.put(THREADCOUNTCLASSES_KEY, "5");
250 params = new JUnitCoreParameters( properties );
251 concurrency = resolveConcurrency( params, null );
252 assertFalse( params.isParallelSuites() );
253 assertTrue( params.isParallelClasses() );
254 assertFalse( params.isParallelMethods() );
255 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
256 assertThat( concurrency.suites, is( 0 ) );
257 assertThat( concurrency.classes, is( 5 * cpu ) );
258 assertThat( concurrency.methods, is( 0 ) );
259 }
260
261 @Theory
262 public void unlimitedThreadsMethods( int cpu )
263 throws TestSetFailedException
264 {
265 ParallelComputerUtil.overrideAvailableProcessors( cpu );
266 Map<String, String> properties = new HashMap<String, String>();
267 properties.put(PARALLEL_KEY, "methods");
268 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
269 JUnitCoreParameters params = new JUnitCoreParameters( properties );
270 Concurrency concurrency = resolveConcurrency( params, null );
271 assertFalse( params.isParallelSuites() );
272 assertFalse( params.isParallelClasses() );
273 assertTrue( params.isParallelMethods() );
274 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
275 assertThat( concurrency.suites, is( 0 ) );
276 assertThat( concurrency.classes, is( 0 ) );
277 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
278
279 properties.put(THREADCOUNTMETHODS_KEY, "5");
280 params = new JUnitCoreParameters( properties );
281 concurrency = resolveConcurrency( params, null );
282 assertFalse( params.isParallelSuites() );
283 assertFalse( params.isParallelClasses() );
284 assertTrue( params.isParallelMethods() );
285 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
286 assertThat( concurrency.suites, is( 0 ) );
287 assertThat( concurrency.classes, is( 0 ) );
288 assertThat( concurrency.methods, is( 5 * cpu ) );
289 }
290
291 @Theory
292 public void unlimitedThreadsSuitesAndClasses( int cpu )
293 throws TestSetFailedException
294 {
295 ParallelComputerUtil.overrideAvailableProcessors( cpu );
296 Map<String, String> properties = new HashMap<String, String>();
297 properties.put(PARALLEL_KEY, "suitesAndClasses");
298 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
299 JUnitCoreParameters params = new JUnitCoreParameters( properties );
300 Concurrency concurrency = resolveConcurrency( params, null );
301 assertTrue( params.isParallelSuites() );
302 assertTrue( params.isParallelClasses() );
303 assertFalse( params.isParallelMethods() );
304 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
305 assertThat( concurrency.suites, is( Integer.MAX_VALUE ) );
306 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
307 assertThat( concurrency.methods, is( 0 ) );
308
309 properties.put(THREADCOUNTSUITES_KEY, "5");
310 properties.put(THREADCOUNTCLASSES_KEY, "15");
311 params = new JUnitCoreParameters( properties );
312 concurrency = resolveConcurrency( params, null );
313 assertTrue( params.isParallelSuites() );
314 assertTrue( params.isParallelClasses() );
315 assertFalse( params.isParallelMethods() );
316 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
317 assertThat( concurrency.suites, is( 5 * cpu ) );
318 assertThat( concurrency.classes, is( 15 * cpu ) );
319 assertThat( concurrency.methods, is( 0 ) );
320 }
321
322 @Theory
323 public void unlimitedThreadsSuitesAndMethods( int cpu )
324 throws TestSetFailedException
325 {
326 ParallelComputerUtil.overrideAvailableProcessors( cpu );
327 Map<String, String> properties = new HashMap<String, String>();
328 properties.put(PARALLEL_KEY, "suitesAndMethods");
329 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
330 JUnitCoreParameters params = new JUnitCoreParameters( properties );
331 Concurrency concurrency = resolveConcurrency( params, null );
332 assertTrue( params.isParallelSuites() );
333 assertFalse( params.isParallelClasses() );
334 assertTrue( params.isParallelMethods() );
335 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
336 assertThat( concurrency.suites, is( Integer.MAX_VALUE ) );
337 assertThat( concurrency.classes, is( 0 ) );
338 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
339
340 properties.put(THREADCOUNTSUITES_KEY, "5");
341 properties.put(THREADCOUNTMETHODS_KEY, "15");
342 params = new JUnitCoreParameters( properties );
343 concurrency = resolveConcurrency( params, null );
344 assertTrue( params.isParallelSuites() );
345 assertFalse( params.isParallelClasses() );
346 assertTrue( params.isParallelMethods() );
347 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
348 assertThat( concurrency.suites, is( 5 * cpu ) );
349 assertThat( concurrency.classes, is( 0 ) );
350 assertThat( concurrency.methods, is( 15 * cpu ) );
351 }
352
353 @Theory
354 public void unlimitedThreadsClassesAndMethods( int cpu )
355 throws TestSetFailedException
356 {
357 ParallelComputerUtil.overrideAvailableProcessors( cpu );
358 Map<String, String> properties = new HashMap<String, String>();
359 properties.put(PARALLEL_KEY, "classesAndMethods");
360 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
361 JUnitCoreParameters params = new JUnitCoreParameters( properties );
362 Concurrency concurrency = resolveConcurrency( params, null );
363 assertFalse( params.isParallelSuites() );
364 assertTrue( params.isParallelClasses() );
365 assertTrue( params.isParallelMethods() );
366 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
367 assertThat( concurrency.suites, is( 0 ) );
368 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
369 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
370
371 properties.put(THREADCOUNTCLASSES_KEY, "5");
372 properties.put(THREADCOUNTMETHODS_KEY, "15");
373 params = new JUnitCoreParameters( properties );
374 concurrency = resolveConcurrency( params, null );
375 assertFalse( params.isParallelSuites() );
376 assertTrue( params.isParallelClasses() );
377 assertTrue( params.isParallelMethods() );
378 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
379 assertThat( concurrency.suites, is( 0 ) );
380 assertThat( concurrency.classes, is( 5 * cpu ) );
381 assertThat( concurrency.methods, is( 15 * cpu ) );
382 }
383
384 @Theory
385 public void unlimitedThreadsAll( int cpu )
386 throws TestSetFailedException
387 {
388 ParallelComputerUtil.overrideAvailableProcessors( cpu );
389 Map<String, String> properties = new HashMap<String, String>();
390 properties.put(PARALLEL_KEY, "all");
391 properties.put(USEUNLIMITEDTHREADS_KEY, "true");
392 JUnitCoreParameters params = new JUnitCoreParameters( properties );
393 Concurrency concurrency = resolveConcurrency( params, null );
394 assertTrue( params.isParallelSuites() );
395 assertTrue( params.isParallelClasses() );
396 assertTrue( params.isParallelMethods() );
397 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
398 assertThat( concurrency.suites, is( Integer.MAX_VALUE ) );
399 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
400 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
401
402 properties.put(THREADCOUNTSUITES_KEY, "5");
403 properties.put(THREADCOUNTCLASSES_KEY, "15");
404 properties.put(THREADCOUNTMETHODS_KEY, "30");
405 params = new JUnitCoreParameters( properties );
406 concurrency = resolveConcurrency( params, null );
407 assertTrue( params.isParallelSuites() );
408 assertTrue( params.isParallelClasses() );
409 assertTrue( params.isParallelMethods() );
410 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
411 assertThat( concurrency.suites, is( 5 * cpu ) );
412 assertThat( concurrency.classes, is( 15 * cpu ) );
413 assertThat( concurrency.methods, is( 30 * cpu ) );
414 }
415
416 @Theory
417 public void threadCountSuites( int cpu )
418 throws TestSetFailedException
419 {
420 ParallelComputerUtil.overrideAvailableProcessors( cpu );
421 Map<String, String> properties = new HashMap<String, String>();
422 properties.put(PARALLEL_KEY, "suites");
423 properties.put(THREADCOUNT_KEY, "3");
424 JUnitCoreParameters params = new JUnitCoreParameters( properties );
425 Concurrency concurrency = resolveConcurrency( params, null );
426 assertTrue( params.isParallelSuites() );
427 assertFalse( params.isParallelClasses() );
428 assertFalse( params.isParallelMethods() );
429 assertThat( concurrency.capacity, is( 0 ) );
430 assertThat( concurrency.suites, is( 3 * cpu ) );
431 assertThat( concurrency.classes, is( 0 ) );
432 assertThat( concurrency.methods, is( 0 ) );
433 }
434
435 @Theory
436 public void threadCountClasses( int cpu )
437 throws TestSetFailedException
438 {
439 ParallelComputerUtil.overrideAvailableProcessors( cpu );
440 Map<String, String> properties = new HashMap<String, String>();
441 properties.put(PARALLEL_KEY, "classes");
442 properties.put(THREADCOUNT_KEY, "3");
443 JUnitCoreParameters params = new JUnitCoreParameters( properties );
444 Concurrency concurrency = resolveConcurrency( params, null );
445 assertFalse( params.isParallelSuites() );
446 assertTrue( params.isParallelClasses() );
447 assertFalse( params.isParallelMethods() );
448 assertThat( concurrency.capacity, is( 0 ) );
449 assertThat( concurrency.suites, is( 0 ) );
450 assertThat( concurrency.classes, is( 3 * cpu ) );
451 assertThat( concurrency.methods, is( 0 ) );
452 }
453
454 @Theory
455 public void threadCountMethods( int cpu )
456 throws TestSetFailedException
457 {
458 ParallelComputerUtil.overrideAvailableProcessors( cpu );
459 Map<String, String> properties = new HashMap<String, String>();
460 properties.put(PARALLEL_KEY, "methods");
461 properties.put(THREADCOUNT_KEY, "3");
462 JUnitCoreParameters params = new JUnitCoreParameters( properties );
463 Concurrency concurrency = resolveConcurrency( params, null );
464 assertFalse( params.isParallelSuites() );
465 assertFalse( params.isParallelClasses() );
466 assertTrue( params.isParallelMethods() );
467 assertThat( concurrency.capacity, is( 0 ) );
468 assertThat( concurrency.suites, is( 0 ) );
469 assertThat( concurrency.classes, is( 0 ) );
470 assertThat( concurrency.methods, is( 3 * cpu ) );
471 }
472
473 @Theory
474 public void threadCountBoth( int cpu )
475 throws TestSetFailedException
476 {
477 ParallelComputerUtil.overrideAvailableProcessors( cpu );
478 Map<String, String> properties = new HashMap<String, String>();
479 properties.put(PARALLEL_KEY, "both");
480 properties.put(THREADCOUNT_KEY, "3");
481 JUnitCoreParameters params = new JUnitCoreParameters( properties );
482 Concurrency concurrency = resolveConcurrency( params, null );
483 assertFalse( params.isParallelSuites() );
484 assertTrue( params.isParallelClasses() );
485 assertTrue( params.isParallelMethods() );
486 assertThat( concurrency.capacity, is( 3 * cpu ) );
487 assertThat( concurrency.suites, is( 0 ) );
488 assertThat( concurrency.classes, is( (int) ( ( 3d / 2 ) * cpu ) ) );
489 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
490 }
491
492 @Theory
493 public void threadCountClassesAndMethods( int cpu )
494 throws TestSetFailedException
495 {
496 ParallelComputerUtil.overrideAvailableProcessors( cpu );
497 Map<String, String> properties = new HashMap<String, String>();
498 properties.put(PARALLEL_KEY, "classesAndMethods");
499 properties.put(THREADCOUNT_KEY, "3");
500 JUnitCoreParameters params = new JUnitCoreParameters( properties );
501 Concurrency concurrency = resolveConcurrency( params, null );
502 assertFalse( params.isParallelSuites() );
503 assertTrue( params.isParallelClasses() );
504 assertTrue( params.isParallelMethods() );
505 assertThat( concurrency.capacity, is( 3 * cpu ) );
506 assertThat( concurrency.suites, is( 0 ) );
507 assertThat( concurrency.classes, is( (int) ( ( 3d / 2 ) * cpu ) ) );
508 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
509 }
510
511 @Theory
512 public void threadCountSuitesAndMethods( int cpu )
513 throws TestSetFailedException
514 {
515 ParallelComputerUtil.overrideAvailableProcessors( cpu );
516 Map<String, String> properties = new HashMap<String, String>();
517 properties.put(PARALLEL_KEY, "suitesAndMethods");
518 properties.put(THREADCOUNT_KEY, "3");
519 JUnitCoreParameters params = new JUnitCoreParameters( properties );
520 Concurrency concurrency = resolveConcurrency( params, null );
521 assertTrue( params.isParallelSuites() );
522 assertFalse( params.isParallelClasses() );
523 assertTrue( params.isParallelMethods() );
524 assertThat( concurrency.capacity, is( 3 * cpu ) );
525 assertThat( concurrency.suites, is( (int) ( ( 3d / 2 ) * cpu ) ) );
526 assertThat( concurrency.classes, is( 0 ) );
527 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
528 }
529
530 @Theory
531 public void threadCountSuitesAndClasses( int cpu )
532 throws TestSetFailedException
533 {
534 ParallelComputerUtil.overrideAvailableProcessors( cpu );
535 Map<String, String> properties = new HashMap<String, String>();
536 properties.put(PARALLEL_KEY, "suitesAndClasses");
537 properties.put(THREADCOUNT_KEY, "3");
538 JUnitCoreParameters params = new JUnitCoreParameters( properties );
539 Concurrency concurrency = resolveConcurrency( params, null );
540 assertTrue( params.isParallelSuites() );
541 assertTrue( params.isParallelClasses() );
542 assertFalse( params.isParallelMethods() );
543 assertThat( concurrency.capacity, is( 3 * cpu ) );
544 assertThat( concurrency.suites, is( (int) ( ( 3d / 2 ) * cpu ) ) );
545 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
546 assertThat( concurrency.methods, is( 0 ) );
547 }
548
549 @Theory
550 public void threadCountAll( int cpu )
551 throws TestSetFailedException
552 {
553 ParallelComputerUtil.overrideAvailableProcessors( cpu );
554 Map<String, String> properties = new HashMap<String, String>();
555 properties.put(PARALLEL_KEY, "all");
556 properties.put(THREADCOUNT_KEY, "3");
557 JUnitCoreParameters params = new JUnitCoreParameters( properties );
558 Concurrency concurrency = resolveConcurrency( params, null );
559 assertTrue( params.isParallelSuites() );
560 assertTrue( params.isParallelClasses() );
561 assertTrue( params.isParallelMethods() );
562 assertThat( concurrency.capacity, is( 3 * cpu ) );
563 assertThat( concurrency.suites, is( cpu ) );
564 assertThat( concurrency.classes, is( cpu ) );
565 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
566 }
567
568 @Theory
569 public void everyThreadCountSuitesAndClasses( int cpu )
570 throws TestSetFailedException
571 {
572 ParallelComputerUtil.overrideAvailableProcessors( cpu );
573 Map<String, String> properties = new HashMap<String, String>();
574 properties.put(PARALLEL_KEY, "suitesAndClasses");
575 properties.put(THREADCOUNT_KEY, "3");
576
577 properties.put(THREADCOUNTSUITES_KEY, "34");
578 properties.put(THREADCOUNTCLASSES_KEY, "66");
579 JUnitCoreParameters params = new JUnitCoreParameters( properties );
580 Concurrency concurrency = resolveConcurrency( params, null );
581 assertTrue( params.isParallelSuites() );
582 assertTrue( params.isParallelClasses() );
583 assertFalse( params.isParallelMethods() );
584 assertThat( concurrency.capacity, is( 3 * cpu ) );
585 int concurrentSuites = (int) ( 0.34d * concurrency.capacity );
586 assertThat( concurrency.suites, is( concurrentSuites ) );
587 assertThat( concurrency.classes, is( concurrency.capacity - concurrentSuites ) );
588 assertThat( concurrency.methods, is( 0 ) );
589 }
590
591 @Theory
592 public void everyThreadCountSuitesAndMethods( int cpu )
593 throws TestSetFailedException
594 {
595 ParallelComputerUtil.overrideAvailableProcessors( cpu );
596 Map<String, String> properties = new HashMap<String, String>();
597 properties.put(PARALLEL_KEY, "suitesAndMethods");
598 properties.put(THREADCOUNT_KEY, "3");
599
600 properties.put(THREADCOUNTSUITES_KEY, "34");
601 properties.put(THREADCOUNTMETHODS_KEY, "66");
602 JUnitCoreParameters params = new JUnitCoreParameters( properties );
603 Concurrency concurrency = resolveConcurrency( params, null );
604 assertTrue( params.isParallelSuites() );
605 assertFalse( params.isParallelClasses() );
606 assertTrue( params.isParallelMethods() );
607 assertThat( concurrency.capacity, is( 3 * cpu ) );
608 int concurrentSuites = (int) ( 0.34d * concurrency.capacity );
609 assertThat( concurrency.suites, is( concurrentSuites ) );
610 assertThat( concurrency.classes, is( 0 ) );
611 assertThat( concurrency.methods, is( concurrency.capacity - concurrentSuites ) );
612 }
613
614 @Theory
615 public void everyThreadCountClassesAndMethods( int cpu )
616 throws TestSetFailedException
617 {
618 ParallelComputerUtil.overrideAvailableProcessors( cpu );
619 Map<String, String> properties = new HashMap<String, String>();
620 properties.put(PARALLEL_KEY, "classesAndMethods");
621 properties.put(THREADCOUNT_KEY, "3");
622
623 properties.put(THREADCOUNTCLASSES_KEY, "34");
624 properties.put(THREADCOUNTMETHODS_KEY, "66");
625 JUnitCoreParameters params = new JUnitCoreParameters( properties );
626 Concurrency concurrency = resolveConcurrency( params, null );
627 assertFalse( params.isParallelSuites() );
628 assertTrue( params.isParallelClasses() );
629 assertTrue( params.isParallelMethods() );
630 assertThat( concurrency.capacity, is( 3 * cpu ) );
631 assertThat( concurrency.suites, is( 0 ) );
632 int concurrentClasses = (int) ( 0.34d * concurrency.capacity );
633 assertThat( concurrency.classes, is( concurrentClasses ) );
634 assertThat( concurrency.methods, is( concurrency.capacity - concurrentClasses ) );
635 }
636
637 @Theory
638 public void everyThreadCountAll( int cpu )
639 throws TestSetFailedException
640 {
641 ParallelComputerUtil.overrideAvailableProcessors( cpu );
642 Map<String, String> properties = new HashMap<String, String>();
643 properties.put(PARALLEL_KEY, "all");
644 properties.put(THREADCOUNT_KEY, "3");
645
646 properties.put(THREADCOUNTSUITES_KEY, "17");
647 properties.put(THREADCOUNTCLASSES_KEY, "34");
648 properties.put(THREADCOUNTMETHODS_KEY, "49");
649 JUnitCoreParameters params = new JUnitCoreParameters( properties );
650 Concurrency concurrency = resolveConcurrency( params, null );
651 assertTrue( params.isParallelSuites() );
652 assertTrue( params.isParallelClasses() );
653 assertTrue( params.isParallelMethods() );
654 assertThat( concurrency.capacity, is( 3 * cpu ) );
655 int concurrentSuites = (int) ( 0.17d * concurrency.capacity );
656 int concurrentClasses = (int) ( 0.34d * concurrency.capacity );
657 assertThat( concurrency.suites, is( concurrentSuites ) );
658 assertThat( concurrency.classes, is( concurrentClasses ) );
659 assertThat( concurrency.methods, is( concurrency.capacity - concurrentSuites - concurrentClasses ) );
660 }
661
662 @Theory
663 public void reusableThreadCountSuitesAndClasses( int cpu )
664 throws TestSetFailedException
665 {
666
667 ParallelComputerUtil.overrideAvailableProcessors( cpu );
668 Map<String, String> properties = new HashMap<String, String>();
669 properties.put(PARALLEL_KEY, "suitesAndClasses");
670 properties.put(THREADCOUNT_KEY, "6");
671 properties.put(THREADCOUNTSUITES_KEY, "2");
672 JUnitCoreParameters params = new JUnitCoreParameters( properties );
673 Concurrency concurrency = resolveConcurrency( params, null );
674 assertTrue( params.isParallelSuites() );
675 assertTrue( params.isParallelClasses() );
676 assertFalse( params.isParallelMethods() );
677 assertThat( concurrency.capacity, is( 6 * cpu ) );
678 assertThat( concurrency.suites, is( 2 * cpu ) );
679 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
680 assertThat( concurrency.methods, is( 0 ) );
681 }
682
683 @Theory
684 public void reusableThreadCountSuitesAndMethods( int cpu )
685 throws TestSetFailedException
686 {
687
688 ParallelComputerUtil.overrideAvailableProcessors( cpu );
689 Map<String, String> properties = new HashMap<String, String>();
690 properties.put(PARALLEL_KEY, "suitesAndMethods");
691 properties.put(THREADCOUNT_KEY, "6");
692 properties.put(THREADCOUNTSUITES_KEY, "2");
693 JUnitCoreParameters params = new JUnitCoreParameters( properties );
694 Concurrency concurrency = resolveConcurrency( params, null );
695 assertTrue( params.isParallelSuites() );
696 assertFalse( params.isParallelClasses() );
697 assertTrue( params.isParallelMethods() );
698 assertThat( concurrency.capacity, is( 6 * cpu ) );
699 assertThat( concurrency.suites, is( 2 * cpu ) );
700 assertThat( concurrency.classes, is( 0 ) );
701 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
702 }
703
704 @Theory
705 public void reusableThreadCountClassesAndMethods( int cpu )
706 throws TestSetFailedException
707 {
708
709 ParallelComputerUtil.overrideAvailableProcessors( cpu );
710 Map<String, String> properties = new HashMap<String, String>();
711 properties.put(PARALLEL_KEY, "classesAndMethods");
712 properties.put(THREADCOUNT_KEY, "6");
713 properties.put(THREADCOUNTCLASSES_KEY, "2");
714 JUnitCoreParameters params = new JUnitCoreParameters( properties );
715 Concurrency concurrency = resolveConcurrency( params, null );
716 assertFalse( params.isParallelSuites() );
717 assertTrue( params.isParallelClasses() );
718 assertTrue( params.isParallelMethods() );
719 assertThat( concurrency.capacity, is( 6 * cpu ) );
720 assertThat( concurrency.suites, is( 0 ) );
721 assertThat( concurrency.classes, is( 2 * cpu ) );
722 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
723 }
724
725 @Theory
726 public void reusableThreadCountAll( int cpu )
727 throws TestSetFailedException
728 {
729
730 ParallelComputerUtil.overrideAvailableProcessors( cpu );
731 Map<String, String> properties = new HashMap<String, String>();
732 properties.put(PARALLEL_KEY, "all");
733 properties.put(THREADCOUNT_KEY, "14");
734 properties.put(THREADCOUNTSUITES_KEY, "2");
735 properties.put(THREADCOUNTCLASSES_KEY, "4");
736 JUnitCoreParameters params = new JUnitCoreParameters( properties );
737 Concurrency concurrency = resolveConcurrency( params, null );
738 assertTrue( params.isParallelSuites() );
739 assertTrue( params.isParallelClasses() );
740 assertTrue( params.isParallelMethods() );
741 assertThat( concurrency.capacity, is( 14 * cpu ) );
742 assertThat( concurrency.suites, is( 2 * cpu ) );
743 assertThat( concurrency.classes, is( 4 * cpu ) );
744 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
745 }
746
747 @Theory
748 public void suites( int cpu )
749 throws TestSetFailedException
750 {
751 ParallelComputerUtil.overrideAvailableProcessors( cpu );
752 Map<String, String> properties = new HashMap<String, String>();
753 properties.put(PARALLEL_KEY, "suites");
754 properties.put(THREADCOUNTSUITES_KEY, "5");
755 JUnitCoreParameters params = new JUnitCoreParameters( properties );
756 Concurrency concurrency = resolveConcurrency( params, null );
757 assertTrue( params.isParallelSuites() );
758 assertFalse( params.isParallelClasses() );
759 assertFalse( params.isParallelMethods() );
760 assertThat( concurrency.capacity, is( 5 * cpu ) );
761 assertThat( concurrency.suites, is( 5 * cpu ) );
762 assertThat( concurrency.classes, is( 0 ) );
763 assertThat( concurrency.methods, is( 0 ) );
764 }
765
766 @Theory
767 public void classes( int cpu )
768 throws TestSetFailedException
769 {
770 ParallelComputerUtil.overrideAvailableProcessors( cpu );
771 Map<String, String> properties = new HashMap<String, String>();
772 properties.put(PARALLEL_KEY, "classes");
773 properties.put(THREADCOUNTCLASSES_KEY, "5");
774 JUnitCoreParameters params = new JUnitCoreParameters( properties );
775 Concurrency concurrency = resolveConcurrency( params, null );
776 assertFalse( params.isParallelSuites() );
777 assertTrue( params.isParallelClasses() );
778 assertFalse( params.isParallelMethods() );
779 assertThat( concurrency.capacity, is( 5 * cpu ) );
780 assertThat( concurrency.suites, is( 0 ) );
781 assertThat( concurrency.classes, is( 5 * cpu ) );
782 assertThat( concurrency.methods, is( 0 ) );
783 }
784
785 @Theory
786 public void methods( int cpu )
787 throws TestSetFailedException
788 {
789 ParallelComputerUtil.overrideAvailableProcessors( cpu );
790 Map<String, String> properties = new HashMap<String, String>();
791 properties.put(PARALLEL_KEY, "methods");
792 properties.put(THREADCOUNTMETHODS_KEY, "5");
793 JUnitCoreParameters params = new JUnitCoreParameters( properties );
794 Concurrency concurrency = resolveConcurrency( params, null );
795 assertFalse( params.isParallelSuites() );
796 assertFalse( params.isParallelClasses() );
797 assertTrue( params.isParallelMethods() );
798 assertThat( concurrency.capacity, is( 5 * cpu ) );
799 assertThat( concurrency.suites, is( 0 ) );
800 assertThat( concurrency.classes, is( 0 ) );
801 assertThat( concurrency.methods, is( 5 * cpu ) );
802 }
803
804 @Theory
805 public void suitesAndClasses( int cpu )
806 throws TestSetFailedException
807 {
808 ParallelComputerUtil.overrideAvailableProcessors( cpu );
809 Map<String, String> properties = new HashMap<String, String>();
810
811 properties.put(PARALLEL_KEY, "suitesAndClasses");
812 properties.put(THREADCOUNTSUITES_KEY, "5");
813 properties.put(THREADCOUNTCLASSES_KEY, "15");
814 JUnitCoreParameters params = new JUnitCoreParameters( properties );
815 Concurrency concurrency = resolveConcurrency( params, null );
816 assertTrue( params.isParallelSuites() );
817 assertTrue( params.isParallelClasses() );
818 assertFalse( params.isParallelMethods() );
819 assertThat( concurrency.capacity, is( 20 * cpu ) );
820 assertThat( concurrency.suites, is( 5 * cpu ) );
821 assertThat( concurrency.classes, is( 15 * cpu ) );
822 assertThat( concurrency.methods, is( 0 ) );
823
824
825
826 properties = new HashMap<String, String>();
827 properties.put(PARALLEL_KEY, "suitesAndClasses");
828 properties.put(THREADCOUNTSUITES_KEY, "5");
829 params = new JUnitCoreParameters( properties );
830 concurrency = resolveConcurrency( params, null );
831 assertTrue( params.isParallelSuites() );
832 assertTrue( params.isParallelClasses() );
833 assertFalse( params.isParallelMethods() );
834 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
835 assertThat( concurrency.suites, is( 5 * cpu ) );
836 assertThat( concurrency.classes, is( Integer.MAX_VALUE ) );
837 assertThat( concurrency.methods, is( 0 ) );
838 }
839
840 @Theory
841 public void suitesAndMethods( int cpu )
842 throws TestSetFailedException
843 {
844 ParallelComputerUtil.overrideAvailableProcessors( cpu );
845 Map<String, String> properties = new HashMap<String, String>();
846
847 properties.put(PARALLEL_KEY, "suitesAndMethods");
848 properties.put(THREADCOUNTSUITES_KEY, "5");
849 properties.put(THREADCOUNTMETHODS_KEY, "15");
850 JUnitCoreParameters params = new JUnitCoreParameters( properties );
851 Concurrency concurrency = resolveConcurrency( params, null );
852 assertTrue( params.isParallelSuites() );
853 assertFalse( params.isParallelClasses() );
854 assertTrue( params.isParallelMethods() );
855 assertThat( concurrency.capacity, is( 20 * cpu ) );
856 assertThat( concurrency.suites, is( 5 * cpu ) );
857 assertThat( concurrency.classes, is( 0 ) );
858 assertThat( concurrency.methods, is( 15 * cpu ) );
859
860
861
862 properties = new HashMap<String, String>();
863 properties.put(PARALLEL_KEY, "suitesAndMethods");
864 properties.put(THREADCOUNTSUITES_KEY, "5");
865 params = new JUnitCoreParameters( properties );
866 concurrency = resolveConcurrency( params, null );
867 assertTrue( params.isParallelSuites() );
868 assertFalse( params.isParallelClasses() );
869 assertTrue( params.isParallelMethods() );
870 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
871 assertThat( concurrency.suites, is( 5 * cpu ) );
872 assertThat( concurrency.classes, is( 0 ) );
873 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
874 }
875
876 @Theory
877 public void classesAndMethods( int cpu )
878 throws TestSetFailedException
879 {
880 ParallelComputerUtil.overrideAvailableProcessors( cpu );
881 Map<String, String> properties = new HashMap<String, String>();
882
883 properties.put(PARALLEL_KEY, "classesAndMethods");
884 properties.put(THREADCOUNTCLASSES_KEY, "5");
885 properties.put(THREADCOUNTMETHODS_KEY, "15");
886 JUnitCoreParameters params = new JUnitCoreParameters( properties );
887 Concurrency concurrency = resolveConcurrency( params, null );
888 assertFalse( params.isParallelSuites() );
889 assertTrue( params.isParallelClasses() );
890 assertTrue( params.isParallelMethods() );
891 assertThat( concurrency.capacity, is( 20 * cpu ) );
892 assertThat( concurrency.suites, is( 0 ) );
893 assertThat( concurrency.classes, is( 5 * cpu ) );
894 assertThat( concurrency.methods, is( 15 * cpu ) );
895
896
897
898 properties = new HashMap<String, String>();
899 properties.put(PARALLEL_KEY, "classesAndMethods");
900 properties.put(THREADCOUNTCLASSES_KEY, "5");
901 params = new JUnitCoreParameters( properties );
902 concurrency = resolveConcurrency( params, null );
903 assertFalse( params.isParallelSuites() );
904 assertTrue( params.isParallelClasses() );
905 assertTrue( params.isParallelMethods() );
906 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
907 assertThat( concurrency.suites, is( 0 ) );
908 assertThat( concurrency.classes, is( 5 * cpu ) );
909 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
910 }
911
912 @Theory
913 public void all( int cpu )
914 throws TestSetFailedException
915 {
916 ParallelComputerUtil.overrideAvailableProcessors( cpu );
917 Map<String, String> properties = new HashMap<String, String>();
918
919 properties.put(PARALLEL_KEY, "all");
920 properties.put(THREADCOUNTSUITES_KEY, "5");
921 properties.put(THREADCOUNTCLASSES_KEY, "15");
922 properties.put(THREADCOUNTMETHODS_KEY, "30");
923 JUnitCoreParameters params = new JUnitCoreParameters( properties );
924 Concurrency concurrency = resolveConcurrency( params, null );
925 assertTrue( params.isParallelSuites() );
926 assertTrue( params.isParallelClasses() );
927 assertTrue( params.isParallelMethods() );
928 assertThat( concurrency.capacity, is( 50 * cpu ) );
929 assertThat( concurrency.suites, is( 5 * cpu ) );
930 assertThat( concurrency.classes, is( 15 * cpu ) );
931 assertThat( concurrency.methods, is( 30 * cpu ) );
932
933
934
935 properties = new HashMap<String, String>();
936 properties.put(PARALLEL_KEY, "all");
937 properties.put(THREADCOUNTSUITES_KEY, "5");
938 properties.put(THREADCOUNTCLASSES_KEY, "15");
939 params = new JUnitCoreParameters( properties );
940 concurrency = resolveConcurrency( params, null );
941 assertTrue( params.isParallelSuites() );
942 assertTrue( params.isParallelClasses() );
943 assertTrue( params.isParallelMethods() );
944 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
945 assertThat( concurrency.suites, is( 5 * cpu ) );
946 assertThat( concurrency.classes, is( 15 * cpu ) );
947 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
948
949 properties = new HashMap<String, String>();
950 properties.put(PARALLEL_KEY, "all");
951 properties.put(THREADCOUNTCLASSES_KEY, "15");
952 params = new JUnitCoreParameters( properties );
953 concurrency = resolveConcurrency( params, null );
954 assertTrue( params.isParallelSuites() );
955 assertTrue( params.isParallelClasses() );
956 assertTrue( params.isParallelMethods() );
957 assertThat( concurrency.capacity, is( Integer.MAX_VALUE ) );
958 assertThat( concurrency.suites, is( Integer.MAX_VALUE ) );
959 assertThat( concurrency.classes, is( 15 * cpu ) );
960 assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
961 }
962
963 @Test
964 public void withoutShutdown()
965 throws TestSetFailedException, ExecutionException, InterruptedException
966 {
967 Map<String, String> properties = new HashMap<String, String>();
968 properties.put(PARALLEL_KEY, "methods");
969 properties.put(THREADCOUNTMETHODS_KEY, "2");
970 JUnitCoreParameters params = new JUnitCoreParameters( properties );
971 ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
972 ParallelComputer pc = pcBuilder.buildComputer();
973 Result result = new JUnitCore().run( pc, TestClass.class );
974 long timeSpent = stopwatch.runtime( MILLISECONDS );
975 long deltaTime = 500L;
976
977 assertTrue( result.wasSuccessful() );
978 assertThat( result.getRunCount(), is( 3 ) );
979 assertThat( result.getFailureCount(), is( 0 ) );
980 assertThat( result.getIgnoreCount(), is( 0 ) );
981 assertEquals( 10000L, timeSpent, deltaTime );
982 }
983
984 @Test
985 public void shutdown()
986 throws TestSetFailedException, ExecutionException, InterruptedException
987 {
988
989
990 Map<String, String> properties = new HashMap<String, String>();
991 properties.put(PARALLEL_KEY, "methods");
992 properties.put(THREADCOUNTMETHODS_KEY, "2");
993 properties.put(PARALLEL_TIMEOUT_KEY, Double.toString(2.5d));
994 JUnitCoreParameters params = new JUnitCoreParameters( properties );
995 ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
996 ParallelComputer pc = pcBuilder.buildComputer();
997 new JUnitCore().run( pc, TestClass.class );
998 long timeSpent = stopwatch.runtime( MILLISECONDS );
999 long deltaTime = 500L;
1000
1001 assertEquals( 5000L, timeSpent, deltaTime );
1002 String description = pc.describeElapsedTimeout();
1003 assertTrue( description.contains( "The test run has finished abruptly after timeout of 2.5 seconds.") );
1004 assertTrue( description.contains( "These tests were executed in prior to the shutdown operation:\n"
1005 + TestClass.class.getName() ) );
1006 }
1007
1008 @Test
1009 public void forcedShutdown()
1010 throws TestSetFailedException, ExecutionException, InterruptedException
1011 {
1012
1013 Map<String, String> properties = new HashMap<String, String>();
1014 properties.put(PARALLEL_KEY, "methods");
1015 properties.put(THREADCOUNTMETHODS_KEY, "2");
1016 properties.put(PARALLEL_TIMEOUTFORCED_KEY, Double.toString(2.5d));
1017 JUnitCoreParameters params = new JUnitCoreParameters( properties );
1018 ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
1019 ParallelComputer pc = pcBuilder.buildComputer();
1020 new JUnitCore().run( pc, TestClass.class );
1021 long timeSpent = stopwatch.runtime( MILLISECONDS );
1022 long deltaTime = 500L;
1023
1024 assertEquals( 2500L, timeSpent, deltaTime );
1025 String description = pc.describeElapsedTimeout();
1026 assertTrue( description.contains( "The test run has finished abruptly after timeout of 2.5 seconds.") );
1027 assertTrue( description.contains( "These tests were executed in prior to the shutdown operation:\n"
1028 + TestClass.class.getName() ) );
1029 }
1030
1031 @Test
1032 public void timeoutAndForcedShutdown()
1033 throws TestSetFailedException, ExecutionException, InterruptedException
1034 {
1035
1036
1037
1038 Map<String, String> properties = new HashMap<String, String>();
1039 properties.put(PARALLEL_KEY, "methods");
1040 properties.put(THREADCOUNTMETHODS_KEY, "2");
1041 properties.put(PARALLEL_TIMEOUT_KEY, Double.toString(2.5d));
1042 properties.put(PARALLEL_TIMEOUTFORCED_KEY, Double.toString(3.5d));
1043 JUnitCoreParameters params = new JUnitCoreParameters( properties );
1044 ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
1045 ParallelComputer pc = pcBuilder.buildComputer();
1046 new JUnitCore().run( pc, TestClass.class );
1047 long timeSpent = stopwatch.runtime( MILLISECONDS );
1048 long deltaTime = 500L;
1049
1050 assertEquals( 3500L, timeSpent, deltaTime );
1051 String description = pc.describeElapsedTimeout();
1052 assertTrue( description.contains( "The test run has finished abruptly after timeout of 2.5 seconds.") );
1053 assertTrue( description.contains( "These tests were executed in prior to the shutdown operation:\n"
1054 + TestClass.class.getName() ) );
1055 }
1056
1057 @Test
1058 public void forcedTimeoutAndShutdown()
1059 throws TestSetFailedException, ExecutionException, InterruptedException
1060 {
1061
1062 Map<String, String> properties = new HashMap<String, String>();
1063 properties.put(PARALLEL_KEY, "methods");
1064 properties.put(THREADCOUNTMETHODS_KEY, "2");
1065 properties.put(PARALLEL_TIMEOUTFORCED_KEY, Double.toString(3.5d));
1066 properties.put(PARALLEL_TIMEOUT_KEY, Double.toString(4.0d));
1067 JUnitCoreParameters params = new JUnitCoreParameters( properties );
1068 ParallelComputerBuilder pcBuilder = new ParallelComputerBuilder( new Logger(), params );
1069 ParallelComputer pc = pcBuilder.buildComputer();
1070 new JUnitCore().run( pc, TestClass.class );
1071 long timeSpent = stopwatch.runtime( MILLISECONDS );
1072 long deltaTime = 500L;
1073
1074 assertEquals( 3500L, timeSpent, deltaTime );
1075 String description = pc.describeElapsedTimeout();
1076 assertTrue( description.contains( "The test run has finished abruptly after timeout of 3.5 seconds.") );
1077 assertTrue( description.contains( "These tests were executed in prior to the shutdown operation:\n"
1078 + TestClass.class.getName() ) );
1079 }
1080
1081 public static class TestClass
1082 {
1083 @Test
1084 public void a()
1085 throws InterruptedException
1086 {
1087 long t1 = System.currentTimeMillis();
1088 try
1089 {
1090 Thread.sleep( 5000L );
1091 }
1092 finally
1093 {
1094 System.out.println( getClass().getSimpleName() + "#a() spent " + ( System.currentTimeMillis() - t1 ) );
1095 }
1096 }
1097
1098 @Test
1099 public void b()
1100 throws InterruptedException
1101 {
1102 long t1 = System.currentTimeMillis();
1103 try
1104 {
1105 Thread.sleep( 5000L );
1106 }
1107 finally
1108 {
1109 System.out.println( getClass().getSimpleName() + "#b() spent " + ( System.currentTimeMillis() - t1 ) );
1110 }
1111 }
1112
1113 @Test
1114 public void c()
1115 throws InterruptedException
1116 {
1117 long t1 = System.currentTimeMillis();
1118 try
1119 {
1120 Thread.sleep( 5000L );
1121 }
1122 finally
1123 {
1124 System.out.println( getClass().getSimpleName() + "#c() spent " + ( System.currentTimeMillis() - t1 ) );
1125 }
1126 }
1127 }
1128 }