Skip to content

Commit 56edeb2

Browse files
committed
Add integration test to reproduce concurrent writes to resolve status file
1 parent 2b142fd commit 56edeb2

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed

core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public static Test suite()
107107
// -------------------------------------------------------------------------------------------------------------
108108
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
109109

110+
suite.addTestSuite( MavenITmngXXXXConcurrentWritesToResolverStatusFile.class );
110111
suite.addTestSuite( MavenITmng7045DropUselessAndOutdatedCdiApiTest.class );
111112
suite.addTestSuite( MavenITmng6566ExecuteAnnotationShouldNotReExecuteGoalsTest.class );
112113
suite.addTestSuite( MavenITmng6754TimestampInMultimoduleProject.class );
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.apache.maven.it;
2+
3+
import org.apache.maven.it.util.ResourceExtractor;
4+
5+
import java.io.File;
6+
7+
public class MavenITmngXXXXConcurrentWritesToResolverStatusFile extends AbstractMavenIntegrationTestCase {
8+
9+
private static final String RESOURCE_NAME = "mng-xxxx-concurrent-writes-to-resolver-status-file";
10+
11+
public MavenITmngXXXXConcurrentWritesToResolverStatusFile() {
12+
super("[4.0.0-alpha-1,)");
13+
}
14+
15+
public void testConcurrentWritesToResolverStatusFile() throws Exception {
16+
final File testDir = ResourceExtractor.simpleExtractResources(getClass(), File.separator + RESOURCE_NAME);
17+
18+
// Install the plugin to the local repository
19+
Verifier verifier = new Verifier(new File(testDir.getAbsolutePath(), "plugin-project").getAbsolutePath());
20+
verifier.deleteDirectory("../repo");
21+
verifier.setLocalRepo(new File(testDir.getAbsolutePath(), "repo").getAbsolutePath());
22+
verifier.executeGoal("install");
23+
verifier.verifyErrorFreeLog();
24+
verifier.resetStreams();
25+
26+
// Run several times such that the resolver-status.properties file gets corrupted by concurrent writes
27+
for (int i = 0; i < 10; i++) {
28+
29+
verifier = new Verifier(new File(testDir.getAbsolutePath()).getAbsolutePath());
30+
verifier.setLocalRepo(new File(testDir.getAbsolutePath(), "repo").getAbsolutePath());
31+
verifier.addCliOption("--non-recursive");
32+
verifier.addCliOption("-U");
33+
34+
// Set settings.xml file and add debug output including thread names
35+
verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties());
36+
verifier.addCliOption("-s");
37+
verifier.addCliOption("settings.xml");
38+
verifier.addCliOption("-X");
39+
verifier.addCliOption("-Dorg.slf4j.simpleLogger.showThreadName=true");
40+
verifier.addCliOption( "-Daether.updateCheckManager.sessionState=false" );
41+
42+
// Execute the plugin mojo
43+
verifier.executeGoal("mng-xxxx-concurrent-writes-to-resolver-status-file:plugin:plugin-mojo");
44+
verifier.verifyErrorFreeLog();
45+
verifier.resetStreams();
46+
}
47+
}
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>mng-xxxx-concurrent-writes-to-resolver-status-file</groupId>
6+
<artifactId>plugin</artifactId>
7+
<packaging>maven-plugin</packaging>
8+
<version>1.0</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.build.reportEncoding>UTF-8</project.build.reportEncoding>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.maven</groupId>
20+
<artifactId>maven-plugin-api</artifactId>
21+
<version>2.0</version>
22+
<scope>compile</scope>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.apache.maven</groupId>
27+
<artifactId>maven-core</artifactId>
28+
<version>2.0</version>
29+
<scope>compile</scope>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.apache.maven.plugin-tools</groupId>
34+
<artifactId>maven-plugin-annotations</artifactId>
35+
<version>3.6.0</version>
36+
<scope>provided</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import org.apache.maven.plugin.AbstractMojo;
2+
import org.apache.maven.plugin.MojoExecutionException;
3+
4+
/**
5+
* @goal plugin-mojo
6+
* @threadSafe
7+
*/
8+
public class PluginMojo extends AbstractMojo {
9+
public void execute() throws MojoExecutionException {
10+
// noop
11+
}
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>mng-xxxx-concurrent-writes-to-resolver-status-file</groupId>
6+
<artifactId>plugin-project</artifactId>
7+
<packaging>pom</packaging>
8+
<version>1.0</version>
9+
10+
<name>Maven Integration Test :: MNG-XXXX</name>
11+
<description>Resolves locally installed plugin concurrently.</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<project.build.reportEncoding>UTF-8</project.build.reportEncoding>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
</properties>
19+
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>mng-xxxx-concurrent-writes-to-resolver-status-file</groupId>
24+
<artifactId>plugin</artifactId>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
29+
<modules>
30+
<module>plugin-project</module>
31+
</modules>
32+
33+
</project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
4+
5+
<mirrors>
6+
<mirror>
7+
<id>central-proxy</id>
8+
<url>https://repo.maven.apache.org/maven2/</url>
9+
<mirrorOf>central</mirrorOf>
10+
</mirror>
11+
<mirror>
12+
<id>apache.snapshots-proxy</id>
13+
<url>https://repo.maven.apache.org/maven2/</url>
14+
<mirrorOf>apache.snapshots</mirrorOf>
15+
</mirror>
16+
</mirrors>
17+
18+
<profiles>
19+
<profile>
20+
<id>custom-repo</id>
21+
<activation>
22+
<activeByDefault>true</activeByDefault>
23+
</activation>
24+
<pluginRepositories>
25+
<pluginRepository>
26+
<id>custom-repo</id>
27+
<url>https://repository.apache.org/snapshots/</url>
28+
<snapshots>
29+
<enabled>true</enabled>
30+
<updatePolicy>always</updatePolicy>
31+
</snapshots>
32+
</pluginRepository>
33+
</pluginRepositories>
34+
</profile>
35+
36+
<profile>
37+
<id>custom-repo2</id>
38+
<activation>
39+
<activeByDefault>true</activeByDefault>
40+
</activation>
41+
<pluginRepositories>
42+
<pluginRepository>
43+
<id>custom-repo2</id>
44+
<url>https://repo.maven.apache.org/maven2/</url>
45+
<snapshots>
46+
<enabled>true</enabled>
47+
<updatePolicy>always</updatePolicy>
48+
</snapshots>
49+
</pluginRepository>
50+
</pluginRepositories>
51+
</profile>
52+
53+
<profile>
54+
<id>custom-repo3</id>
55+
<activation>
56+
<activeByDefault>true</activeByDefault>
57+
</activation>
58+
<repositories>
59+
<repository>
60+
<id>custom-repo3</id>
61+
<url>https://repo.maven.apache.org/maven2/</url>
62+
<snapshots>
63+
<enabled>true</enabled>
64+
<updatePolicy>always</updatePolicy>
65+
</snapshots>
66+
</repository>
67+
</repositories>
68+
</profile>
69+
70+
<profile>
71+
<id>custom-repo4</id>
72+
<activation>
73+
<activeByDefault>true</activeByDefault>
74+
</activation>
75+
<repositories>
76+
<repository>
77+
<id>custom-repo4</id>
78+
<url>https://repo.maven.apache.org/maven2/</url>
79+
<snapshots>
80+
<enabled>true</enabled>
81+
<updatePolicy>always</updatePolicy>
82+
</snapshots>
83+
</repository>
84+
</repositories>
85+
</profile>
86+
87+
</profiles>
88+
</settings>

0 commit comments

Comments
 (0)