View Javadoc
1   package org.apache.maven.surefire.its;
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.its.fixture.SurefireJUnit4IntegrationTestCase;
23  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
24  import org.junit.Test;
25  
26  /**
27   * Testing JUnitCoreWrapper with ParallelComputerBuilder.
28   *
29   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30   * @since 2.16
31   */
32  public class JUnit47ParallelIT
33      extends SurefireJUnit4IntegrationTestCase
34  {
35  
36      @Test
37      public void unknownThreadCountSuites()
38      {
39          unpack().parallelSuites().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
40              "Use threadCount or threadCountSuites > 0 or useUnlimitedThreads=true for parallel='suites'" );
41      }
42  
43      @Test
44      public void unknownThreadCountClasses()
45      {
46          unpack().parallelClasses().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
47              "Use threadCount or threadCountClasses > 0 or useUnlimitedThreads=true for parallel='classes'" );
48      }
49  
50      @Test
51      public void unknownThreadCountMethods()
52      {
53          unpack().parallelMethods().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
54              "Use threadCount or threadCountMethods > 0 or useUnlimitedThreads=true for parallel='methods'" );
55  
56      }
57  
58      @Test
59      public void unknownThreadCountBoth()
60      {
61          unpack().parallelBoth().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
62              "Use useUnlimitedThreads=true, " +
63                  "or only threadCount > 0, " +
64                  "or (threadCountClasses > 0 and threadCountMethods > 0), " +
65                  "or (threadCount > 0 and threadCountClasses > 0 and threadCountMethods > 0), " +
66                  "or (threadCount > 0 and threadCountClasses > 0 and threadCount > threadCountClasses) " +
67                  "for parallel='both' or parallel='classesAndMethods'" );
68      }
69  
70      @Test
71      public void unknownThreadCountAll()
72      {
73          unpack().parallelAll().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
74              "Use useUnlimitedThreads=true, " +
75                  "or only threadCount > 0, " +
76                  "or (threadCountSuites > 0 and threadCountClasses > 0 and threadCountMethods > 0), " +
77                  "or every thread-count is specified, " +
78                  "or (threadCount > 0 and threadCountSuites > 0 and threadCountClasses > 0 " +
79                  "and threadCount > threadCountSuites + threadCountClasses) " +
80                  "for parallel='all'" );
81      }
82  
83      @Test
84      public void unknownThreadCountSuitesAndClasses()
85      {
86          unpack().parallelSuitesAndClasses().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
87              "Use useUnlimitedThreads=true, " +
88                  "or only threadCount > 0, " +
89                  "or (threadCountSuites > 0 and threadCountClasses > 0), " +
90                  "or (threadCount > 0 and threadCountSuites > 0 and threadCountClasses > 0) " +
91                  "or (threadCount > 0 and threadCountSuites > 0 and threadCount > threadCountSuites) " +
92                  "for parallel='suitesAndClasses' or 'both'" );
93      }
94  
95      @Test
96      public void unknownThreadCountSuitesAndMethods()
97      {
98          unpack().parallelSuitesAndMethods().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
99              "Use useUnlimitedThreads=true, " +
100                 "or only threadCount > 0, " +
101                 "or (threadCountSuites > 0 and threadCountMethods > 0), " +
102                 "or (threadCount > 0 and threadCountSuites > 0 and threadCountMethods > 0), " +
103                 "or (threadCount > 0 and threadCountSuites > 0 and threadCount > threadCountSuites) " +
104                 "for parallel='suitesAndMethods'" );
105     }
106 
107     @Test
108     public void unknownThreadCountClassesAndMethods()
109     {
110         unpack().parallelClassesAndMethods().setTestToRun( "TestClass" ).failNever().executeTest().verifyTextInLog(
111             "Use useUnlimitedThreads=true, " +
112                 "or only threadCount > 0, " +
113                 "or (threadCountClasses > 0 and threadCountMethods > 0), " +
114                 "or (threadCount > 0 and threadCountClasses > 0 and threadCountMethods > 0), " +
115                 "or (threadCount > 0 and threadCountClasses > 0 and threadCount > threadCountClasses) " +
116                 "for parallel='both' or parallel='classesAndMethods'" );
117     }
118 
119     @Test
120     public void serial()
121     {
122         // takes 7.2 sec
123         unpack().setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
124     }
125 
126     @Test
127     public void unlimitedThreadsSuites1()
128     {
129         // takes 3.6 sec
130         unpack().parallelSuites().useUnlimitedThreads().setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
131             24 );
132     }
133 
134     @Test
135     public void unlimitedThreadsSuites2()
136     {
137         // takes 3.6 sec
138         unpack().parallelSuites().useUnlimitedThreads().threadCountSuites( 5 ).setTestToRun(
139             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
140     }
141 
142     @Test
143     public void unlimitedThreadsClasses1()
144     {
145         // takes 1.8 sec
146         unpack().parallelClasses().useUnlimitedThreads().setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
147             24 );
148     }
149 
150     @Test
151     public void unlimitedThreadsClasses2()
152     {
153         // takes 1.8 sec
154         unpack().parallelClasses().useUnlimitedThreads().threadCountClasses( 5 ).setTestToRun(
155             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
156     }
157 
158     @Test
159     public void unlimitedThreadsMethods1()
160     {
161         // takes 2.4 sec
162         unpack().parallelMethods().useUnlimitedThreads().setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
163             24 );
164     }
165 
166     @Test
167     public void unlimitedThreadsMethods2()
168     {
169         // takes 2.4 sec
170         unpack().parallelMethods().useUnlimitedThreads().threadCountMethods( 5 ).setTestToRun(
171             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
172     }
173 
174     @Test
175     public void unlimitedThreadsSuitesAndClasses1()
176     {
177         // takes 0.9 sec
178         unpack().parallelSuitesAndClasses().useUnlimitedThreads().setTestToRun(
179             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
180     }
181 
182     @Test
183     public void unlimitedThreadsSuitesAndClasses2()
184     {
185         // takes 0.9 sec
186         // 1.8 sec with 4 parallel classes
187         unpack().parallelSuitesAndClasses().useUnlimitedThreads().threadCountSuites( 5 ).threadCountClasses(
188             15 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
189     }
190 
191     @Test
192     public void unlimitedThreadsSuitesAndMethods1()
193     {
194         // takes 1.2 sec
195         unpack().parallelSuitesAndMethods().useUnlimitedThreads().setTestToRun(
196             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
197     }
198 
199     @Test
200     public void unlimitedThreadsSuitesAndMethods2()
201     {
202         // takes 1.2 sec
203         unpack().parallelSuitesAndMethods().useUnlimitedThreads().threadCountSuites( 5 ).threadCountMethods(
204             15 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
205     }
206 
207     @Test
208     public void unlimitedThreadsClassesAndMethods1()
209     {
210         // takes 0.6 sec
211         unpack().parallelClassesAndMethods().useUnlimitedThreads().setTestToRun(
212             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
213     }
214 
215     @Test
216     public void unlimitedThreadsClassesAndMethods2()
217     {
218         // takes 0.6 sec
219         unpack().parallelClassesAndMethods().useUnlimitedThreads().threadCountClasses( 5 ).threadCountMethods(
220             15 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
221     }
222 
223     @Test
224     public void unlimitedThreadsAll1()
225     {
226         // takes 0.3 sec
227         unpack().parallelAll().useUnlimitedThreads().setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
228     }
229 
230     @Test
231     public void unlimitedThreadsAll2()
232     {
233         // takes 0.3 sec
234         unpack().parallelAll().useUnlimitedThreads().threadCountSuites( 5 ).threadCountClasses( 15 ).threadCountMethods(
235             30 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
236     }
237 
238     @Test
239     public void threadCountSuites()
240     {
241         // takes 3.6 sec
242         unpack().parallelSuites().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
243     }
244 
245     @Test
246     public void threadCountClasses()
247     {
248         // takes 3.6 sec for single core
249         // takes 1.8 sec for double core
250         unpack().parallelClasses().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
251     }
252 
253     @Test
254     public void threadCountMethods()
255     {
256         // takes 2.4 sec
257         unpack().parallelMethods().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
258     }
259 
260     @Test
261     public void threadCountClassesAndMethodsOneCore()
262     {
263         // takes 4.8 sec
264         unpack().disablePerCoreThreadCount().disableParallelOptimization().parallelClassesAndMethods().threadCount(
265             3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
266     }
267 
268     @Test
269     public void threadCountClassesAndMethodsOneCoreOptimized()
270     {
271         // the number of reused threads in leafs depends on the number of runners and CPU
272         unpack().disablePerCoreThreadCount().parallelClassesAndMethods().threadCount( 3 ).setTestToRun(
273             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
274     }
275 
276     @Test
277     public void threadCountClassesAndMethods()
278     {
279         // takes 2.4 sec for double core CPU
280         unpack().disableParallelOptimization().parallelClassesAndMethods().threadCount( 3 ).setTestToRun(
281             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
282     }
283 
284     @Test
285     public void threadCountClassesAndMethodsOptimized()
286     {
287         // the number of reused threads in leafs depends on the number of runners and CPU
288         unpack().parallelClassesAndMethods().threadCount( 3 ).setTestToRun(
289             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
290     }
291 
292     @Test
293     public void threadCountSuitesAndMethods()
294     {
295         // usually 24 times 0.3 sec = 7.2 sec with one core CPU
296         // takes 1.8 sec for double core CPU
297         unpack().disableParallelOptimization().parallelSuitesAndMethods().threadCount( 3 ).setTestToRun(
298             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
299     }
300 
301     @Test
302     public void threadCountSuitesAndMethodsOptimized()
303     {
304         // the number of reused threads in leafs depends on the number of runners and CPU
305         unpack().parallelSuitesAndMethods().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
306             24 );
307     }
308 
309     @Test
310     public void threadCountSuitesAndClasses()
311     {
312         unpack().disableParallelOptimization().parallelSuitesAndClasses().threadCount( 3 ).setTestToRun(
313             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
314     }
315 
316     @Test
317     public void threadCountSuitesAndClassesOptimized()
318     {
319         // the number of reused threads in leafs depends on the number of runners and CPU
320         unpack().parallelSuitesAndClasses().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
321             24 );
322     }
323 
324     @Test
325     public void threadCountAll()
326     {
327         unpack().disableParallelOptimization().parallelAll().threadCount( 3 ).setTestToRun(
328             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
329     }
330 
331     @Test
332     public void threadCountAllOptimized()
333     {
334         // the number of reused threads in leafs depends on the number of runners and CPU
335         unpack().parallelAll().threadCount( 3 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
336     }
337 
338     @Test
339     public void everyThreadCountSuitesAndClasses()
340     {
341         // takes 1.8 sec for double core CPU
342         unpack().parallelSuitesAndClasses().threadCount( 3 ).threadCountSuites( 34 ).threadCountClasses(
343             66 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
344     }
345 
346     @Test
347     public void everyThreadCountSuitesAndMethods()
348     {
349         // takes 1.8 sec for double core CPU
350         unpack().parallelSuitesAndMethods().threadCount( 3 ).threadCountSuites( 34 ).threadCountMethods(
351             66 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
352     }
353 
354     @Test
355     public void everyThreadCountClassesAndMethods()
356     {
357         // takes 1.8 sec for double core CPU
358         unpack().parallelClassesAndMethods().threadCount( 3 ).threadCountClasses( 34 ).threadCountMethods(
359             66 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
360     }
361 
362     @Test
363     public void everyThreadCountAll()
364     {
365         // takes 2.4 sec for double core CPU
366         unpack().parallelAll().threadCount( 3 ).threadCountSuites( 17 ).threadCountClasses( 34 ).threadCountMethods(
367             49 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
368     }
369 
370     @Test
371     public void reusableThreadCountSuitesAndClasses()
372     {
373         // 4 * cpu to 5 * cpu threads to run test classes
374         // takes cca 1.8 sec
375         unpack().disableParallelOptimization().parallelSuitesAndClasses().disablePerCoreThreadCount().threadCount(
376             6 ).threadCountSuites( 2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
377     }
378 
379     @Test
380     public void reusableThreadCountSuitesAndClassesOptimized()
381     {
382         // the number of reused threads in leafs depends on the number of runners and CPU
383         unpack().parallelSuitesAndClasses().disablePerCoreThreadCount().threadCount( 6 ).threadCountSuites(
384             2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
385     }
386 
387     @Test
388     public void reusableThreadCountSuitesAndMethods()
389     {
390         // 4 * cpu to 5 * cpu threads to run test methods
391         // takes cca 1.8 sec
392         unpack().disableParallelOptimization().parallelSuitesAndMethods().disablePerCoreThreadCount().threadCount(
393             6 ).threadCountSuites( 2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
394     }
395 
396     @Test
397     public void reusableThreadCountSuitesAndMethodsOptimized()
398     {
399         // the number of reused threads in leafs depends on the number of runners and CPU
400         unpack().parallelSuitesAndMethods().disablePerCoreThreadCount().threadCount( 6 ).threadCountSuites(
401             2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
402     }
403 
404     @Test
405     public void reusableThreadCountClassesAndMethods()
406     {
407         // 4 * cpu to 5 * cpu threads to run test methods
408         // takes cca 1.8 sec
409         unpack().disableParallelOptimization().parallelClassesAndMethods().disablePerCoreThreadCount().threadCount(
410             6 ).threadCountClasses( 2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
411     }
412 
413     @Test
414     public void reusableThreadCountClassesAndMethodsOptimized()
415     {
416         // the number of reused threads in leafs depends on the number of runners and CPU
417         unpack().parallelClassesAndMethods().disablePerCoreThreadCount().threadCount( 6 ).threadCountClasses(
418             2 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
419     }
420 
421     @Test
422     public void reusableThreadCountAll()
423     {
424         // 8 * cpu to 13 * cpu threads to run test methods
425         // takes 0.9 sec
426         unpack().disableParallelOptimization().parallelAll().disablePerCoreThreadCount().threadCount(
427             14 ).threadCountSuites( 2 ).threadCountClasses( 4 ).setTestToRun(
428             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
429     }
430 
431     @Test
432     public void reusableThreadCountAllOptimized()
433     {
434         // the number of reused threads in leafs depends on the number of runners and CPU
435         unpack().parallelAll().disablePerCoreThreadCount().threadCount( 14 ).threadCountSuites( 2 ).threadCountClasses(
436             4 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree( 24 );
437     }
438 
439     @Test
440     public void suites()
441     {
442         // takes 3.6 sec
443         unpack().parallelSuites().threadCountSuites( 5 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
444             24 );
445     }
446 
447     @Test
448     public void classes()
449     {
450         // takes 1.8 sec on any CPU because the suites are running in a sequence
451         unpack().parallelClasses().threadCountClasses( 5 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
452             24 );
453     }
454 
455     @Test
456     public void methods()
457     {
458         // takes 2.4 sec on any CPU because every class has only three methods
459         // and the suites and classes are running in a sequence
460         unpack().parallelMethods().threadCountMethods( 5 ).setTestToRun( "Suite*Test" ).executeTest().verifyErrorFree(
461             24 );
462     }
463 
464     @Test
465     public void suitesAndClasses()
466     {
467         // takes 0.9 sec
468         unpack().parallelSuitesAndClasses().threadCountSuites( 5 ).threadCountClasses( 15 ).setTestToRun(
469             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
470     }
471 
472     @Test
473     public void suitesAndMethods()
474     {
475         // takes 1.2 sec on any CPU
476         unpack().parallelSuitesAndMethods().threadCountSuites( 5 ).threadCountMethods( 15 ).setTestToRun(
477             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
478     }
479 
480     @Test
481     public void classesAndMethods()
482     {
483         // takes 0.6 sec on any CPU
484         unpack().parallelClassesAndMethods().threadCountClasses( 5 ).threadCountMethods( 15 ).setTestToRun(
485             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
486     }
487 
488     @Test
489     public void all()
490     {
491         // takes 0.3 sec on any CPU
492         unpack().parallelAll().threadCountSuites( 5 ).threadCountClasses( 15 ).threadCountMethods( 30 ).setTestToRun(
493             "Suite*Test" ).executeTest().verifyErrorFree( 24 );
494     }
495 
496     @Test
497     public void shutdown()
498     {
499         // executes for 2.5 sec until timeout has elapsed
500         unpack().parallelMethods().threadCountMethods( 2 ).parallelTestsTimeoutInSeconds( 2.5d ).setTestToRun(
501             "TestClass" ).failNever().executeTest().verifyTextInLog(
502             "The test run has finished abruptly after timeout of 2.5 seconds." );
503     }
504 
505     @Test
506     public void forcedShutdown()
507     {
508         // executes for 2.5 sec until timeout has elapsed
509         unpack().parallelMethods().threadCountMethods( 2 ).parallelTestsTimeoutForcedInSeconds( 2.5d ).setTestToRun(
510             "TestClass" ).failNever().executeTest().verifyTextInLog(
511             "The test run has finished abruptly after timeout of 2.5 seconds." );
512     }
513 
514     @Test
515     public void timeoutAndForcedShutdown()
516     {
517         // executes for one sec until timeout has elapsed
518         unpack().parallelMethods().threadCountMethods( 2 ).parallelTestsTimeoutInSeconds(
519             1 ).parallelTestsTimeoutForcedInSeconds( 2.5d ).setTestToRun(
520             "TestClass" ).failNever().executeTest().verifyTextInLog(
521             "The test run has finished abruptly after timeout of 1.0 seconds." );
522     }
523 
524     @Test
525     public void forcedShutdownVerifyingLogs()
526     {
527         // attempts to run for 2.4 sec until timeout has elapsed
528         unpack().parallelMethods().threadCountMethods( 3 ).disablePerCoreThreadCount()
529             .parallelTestsTimeoutForcedInSeconds( 1.05d ).setTestToRun( "Waiting*Test" ).failNever().executeTest()
530             .verifyTextInLog( "The test run has finished abruptly after timeout of 1.05 seconds." )
531             .verifyTextInLog( "These tests were executed in prior to the shutdown operation:" )
532             .verifyTextInLog( "These tests are incomplete:" );
533     }
534 
535     private SurefireLauncher unpack()
536     {
537         return unpack( "junit47-parallel" )
538                 .showErrorStackTraces()
539                 .forkOnce()
540                 .redirectToFile( false );
541     }
542 }