View Javadoc

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