[MNG-7095] Support for parallel builds when resuming

Resolves #98
This commit is contained in:
Guillaume Nodet 2021-02-12 16:43:07 +01:00 committed by Martin Kanters
parent 6ff4e40e4a
commit d4f7ebaa1e
10 changed files with 514 additions and 0 deletions

View File

@ -43,6 +43,7 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
private final File parentDependentTestDir;
private final File parentIndependentTestDir;
private final File noProjectTestDir;
private final File fourModulesTestDir;
public MavenITmng5760ResumeFeatureTest() throws IOException {
super( "[4.0.0-alpha-1,)" );
@ -52,6 +53,8 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
"/mng-5760-resume-feature/parent-independent" );
this.noProjectTestDir = ResourceExtractor.simpleExtractResources( getClass(),
"/mng-5760-resume-feature/no-project" );
this.fourModulesTestDir = ResourceExtractor.simpleExtractResources( getClass(),
"/mng-5760-resume-feature/four-modules" );
}
/**
@ -175,6 +178,109 @@ public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTes
}
}
public void testFailureWithParallelBuild() throws Exception
{
// four modules: a, b, c, d
// c depends on b, d depends on a
// Let's do a first pass with a and c failing. The build is parallel,
// so we have a first thread with a and d, and the second one with b and c
// The result should be:
// a : failure (slow, so b and c will be built in the mean time)
// b : success
// c : failure
// d : skipped
Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
verifier.addCliOption( "-T2" );
verifier.addCliOption( "-Dmodule-a.delay=1000" );
verifier.addCliOption( "-Dmodule-a.fail=true" );
verifier.addCliOption( "-Dmodule-c.fail=true" );
try
{
verifier.executeGoal( "verify" );
fail( "Expected this invocation to fail" );
}
catch ( final VerificationException ve )
{
// Expected to fail.
}
finally
{
verifier.resetStreams();
}
// Let module-b fail, if it would have been built...
verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
verifier.addCliOption( "-T2" );
verifier.addCliOption( "-Dmodule-b.fail=true" );
// ... but adding -r should exclude it from the build because the previous Maven invocation
// marked it as successfully built.
verifier.addCliOption( "-r" );
// The result should be:
// a : success
// c : success
// d : success
try
{
verifier.executeGoal( "verify" );
}
finally
{
verifier.resetStreams();
}
}
public void testFailureAfterSkipWithParallelBuild() throws Exception
{
// four modules: a, b, c, d
// c depends on b, d depends on a
// Let's do a first pass with a and c failing. The build is parallel,
// so we have a first thread with a and d, and the second one with b and c
// The result should be:
// a : success
// b : success, slow
// c : skipped
// d : failure
Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
verifier.addCliOption( "-T2" );
verifier.addCliOption( "-Dmodule-b.delay=2000" );
verifier.addCliOption( "-Dmodule-d.fail=true" );
try
{
verifier.executeGoal( "verify" );
fail( "Expected this invocation to fail" );
}
catch ( final VerificationException ve )
{
// Expected to fail.
}
finally
{
verifier.resetStreams();
}
// Let module-a and module-b fail, if they would have been built...
verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
verifier.addCliOption( "-T2" );
verifier.addCliOption( "-Dmodule-a.fail=true" );
verifier.addCliOption( "-Dmodule-b.fail=true" );
// ... but adding -r should exclude those two from the build because the previous Maven invocation
// marked them as successfully built.
verifier.addCliOption( "-r" );
try
{
// The result should be:
// c : success
// d : success
verifier.executeGoal( "verify" );
}
finally
{
verifier.resetStreams();
}
}
/**
* Throws an exception if the text <strong>is</strong> present in the log.
*

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module-a</artifactId>
<parent>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.junit.Test;
import static org.junit.Assert.fail;
public class TestCase
{
@Test
public void testCase() throws Exception
{
Thread.sleep( Integer.getInteger( "module-a.delay", 0 ) );
if ( Boolean.getBoolean("module-a.fail") )
{
fail("Deliberately fail test case in module A");
}
}
}

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module-b</artifactId>
<parent>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.junit.Test;
import static org.junit.Assert.fail;
public class TestCase
{
@Test
public void testCase() throws Exception
{
Thread.sleep( Integer.getInteger( "module-b.delay", 0 ) );
if ( Boolean.getBoolean("module-b.fail") )
{
fail("Deliberately fail test case in module B");
}
}
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module-c</artifactId>
<parent>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>module-b</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.junit.Test;
import static org.junit.Assert.fail;
public class TestCase
{
@Test
public void testCase() throws Exception
{
Thread.sleep( Integer.getInteger( "module-c.delay", 0 ) );
if ( Boolean.getBoolean("module-c.fail") )
{
fail("Deliberately fail test case in module C");
}
}
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>module-d</artifactId>
<parent>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>module-a</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.junit.Test;
import static org.junit.Assert.fail;
public class TestCase
{
@Test
public void testCase() throws Exception
{
Thread.sleep( Integer.getInteger( "module-d.delay", 0 ) );
if ( Boolean.getBoolean("module-d.fail") )
{
fail("Deliberately fail test case in module D");
}
}
}

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng5760</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-5760</name>
<description>
Tests for the --resume flag.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>module-a</module>
<module>module-b</module>
<module>module-c</module>
<module>module-d</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>