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