View Javadoc
1   package org.apache.maven.it;
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.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3004">MNG-3004</a>.
28   *
29   * @author Dan Fabulich
30   *
31   */
32  public class MavenITmng3004ReactorFailureBehaviorMultithreadedTest
33      extends AbstractMavenIntegrationTestCase
34  {
35      public MavenITmng3004ReactorFailureBehaviorMultithreadedTest()
36      {
37          super( "(3.0-alpha-3,)" );
38      }
39  
40      /**
41       * Test fail-fast reactor behavior. Forces an exception to be thrown in
42       * the first module and checks that the second &amp; third module is not built and the overall build fails, too.
43       *
44       * @throws Exception in case of failure
45       */
46      public void testitFailFastSingleThread()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
50  
51          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
52          verifier.setAutoclean( false );
53          verifier.deleteDirectory( "target" );
54          verifier.deleteDirectory( "subproject1/target" );
55          verifier.deleteDirectory( "subproject2/target" );
56          verifier.deleteDirectory( "subproject3/target" );
57          verifier.addCliOption( "--fail-fast" );
58          verifier.setLogFileName( "log-ff-mt1.txt" );
59          verifier.setSystemProperty( "maven.threads.experimental", "1" );
60  
61          try
62          {
63              verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
64              verifier.verifyErrorFreeLog();
65          }
66          catch ( VerificationException e )
67          {
68              // expected
69          }
70          verifier.resetStreams();
71  
72          verifier.assertFilePresent( "target/touch.txt" );
73          verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
74          verifier.assertFileNotPresent( "subproject2/target/touch.txt" );
75          verifier.assertFileNotPresent( "subproject3/target/touch.txt" );
76      }
77  
78      /**
79       * Test fail-never reactor behavior. Forces an exception to be thrown in
80       * the first module, but checks that the second &amp; third module is built and the overall build succeeds.
81       *
82       * @throws Exception in case of failure
83       */
84      public void testitFailNeverSingleThread()
85          throws Exception
86      {
87          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
88  
89          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
90          verifier.setAutoclean( false );
91          verifier.deleteDirectory( "target" );
92          verifier.deleteDirectory( "subproject1/target" );
93          verifier.deleteDirectory( "subproject2/target" );
94          verifier.deleteDirectory( "subproject3/target" );
95          verifier.addCliOption( "--fail-never" );
96          verifier.setLogFileName( "log-fn-mt1.txt" );
97          verifier.setSystemProperty( "maven.threads.experimental", "1" );
98          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
99          verifier.resetStreams();
100 
101         verifier.assertFilePresent( "target/touch.txt" );
102         verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
103         verifier.assertFilePresent( "subproject2/target/touch.txt" );
104         verifier.assertFilePresent( "subproject3/target/touch.txt" );
105     }
106 
107     /**
108      * Test fail-at-end reactor behavior. Forces an exception to be thrown in
109      * the first module and checks that the second module is still built but the overall build finally fails
110      * and the third module (which depends on the failed module) is skipped.
111      *
112      * @throws Exception in case of failure
113      */
114     public void testitFailAtEndSingleThread()
115         throws Exception
116     {
117         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
118 
119         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
120         verifier.setAutoclean( false );
121         verifier.deleteDirectory( "target" );
122         verifier.deleteDirectory( "subproject1/target" );
123         verifier.deleteDirectory( "subproject2/target" );
124         verifier.deleteDirectory( "subproject3/target" );
125         verifier.addCliOption( "--fail-at-end" );
126         verifier.setLogFileName( "log-fae-mt1.txt" );
127         verifier.setSystemProperty( "maven.threads.experimental", "1" );
128         try
129         {
130             verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
131             verifier.verifyErrorFreeLog();
132         }
133         catch ( VerificationException e )
134         {
135             // expected
136         }
137         verifier.resetStreams();
138 
139         verifier.assertFilePresent( "target/touch.txt" );
140         verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
141         verifier.assertFilePresent( "subproject2/target/touch.txt" );
142         verifier.assertFileNotPresent( "subproject3/target/touch.txt" );
143     }
144 
145     /**
146      * Test fail-never reactor behavior. Forces an exception to be thrown in
147      * the first module, but checks that the second &amp; third module is built and the overall build succeeds.
148      *
149      * @throws Exception in case of failure
150      */
151     public void testitFailNeverTwoThreads()
152         throws Exception
153     {
154         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
155 
156         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
157         verifier.setAutoclean( false );
158         verifier.deleteDirectory( "target" );
159         verifier.deleteDirectory( "subproject1/target" );
160         verifier.deleteDirectory( "subproject2/target" );
161         verifier.deleteDirectory( "subproject3/target" );
162         verifier.addCliOption( "--fail-never" );
163         verifier.setLogFileName( "log-fn-mt2.txt" );
164         verifier.setSystemProperty( "maven.threads.experimental", "2" );
165         verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
166         verifier.resetStreams();
167 
168         verifier.assertFilePresent( "target/touch.txt" );
169         verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
170         verifier.assertFilePresent( "subproject2/target/touch.txt" );
171         verifier.assertFilePresent( "subproject3/target/touch.txt" );
172     }
173 
174     /**
175      * Test fail-at-end reactor behavior. Forces an exception to be thrown in
176      * the first module and checks that the second module is still built but the overall build finally fails
177      * and the third module (which depends on the failed module) is skipped.
178      *
179      * @throws Exception in case of failure
180      */
181     public void testitFailAtEndTwoThreads()
182         throws Exception
183     {
184         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
185 
186         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
187         verifier.setAutoclean( false );
188         verifier.deleteDirectory( "target" );
189         verifier.deleteDirectory( "subproject1/target" );
190         verifier.deleteDirectory( "subproject2/target" );
191         verifier.deleteDirectory( "subproject3/target" );
192         verifier.addCliOption( "--fail-at-end" );
193         verifier.setLogFileName( "log-fae-mt2.txt" );
194         verifier.setSystemProperty( "maven.threads.experimental", "2" );
195         try
196         {
197             verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
198             verifier.verifyErrorFreeLog();
199         }
200         catch ( VerificationException e )
201         {
202             // expected
203         }
204         verifier.resetStreams();
205 
206         verifier.assertFilePresent( "target/touch.txt" );
207         verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
208         verifier.assertFilePresent( "subproject2/target/touch.txt" );
209         verifier.assertFileNotPresent( "subproject3/target/touch.txt" );
210     }
211 
212     // DGF not testing fail fast with multiple real threads since that's a "best effort" attempt to halt the build
213     // The whole build could have finished by the time you try to halt.
214 
215 }