Use a maven proxy for integration tests to speed them up

This commit is contained in:
Guillaume Nodet
2020-10-06 08:51:38 +02:00
parent 81f78a8860
commit ef2bd36214
7 changed files with 103 additions and 24 deletions

View File

@@ -82,10 +82,28 @@
<artifactId>maven-model</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mrm-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<phase>process-test-classes</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -93,6 +111,7 @@
<systemPropertyVariables>
<project.version>${project.version}</project.version>
<mvnd.home>${mvnd.home}</mvnd.home>
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
</systemPropertyVariables>
@@ -119,6 +138,7 @@
<systemPropertyVariables>
<project.version>${project.version}</project.version>
<mvnd.home>${mvnd.home}</mvnd.home>
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
</systemPropertyVariables>

View File

@@ -49,6 +49,7 @@ public class ModuleAndPluginNativeIT {
}
final Path localMavenRepo = layout.getLocalMavenRepository();
TestUtils.deleteDir(localMavenRepo);
final Path[] installedJars = {
localMavenRepo.resolve(
"org/jboss/fuse/mvnd/test/module-and-plugin/module-and-plugin-maven-plugin/0.0.1-SNAPSHOT/module-and-plugin-maven-plugin-0.0.1-SNAPSHOT.jar"),

View File

@@ -27,6 +27,7 @@ import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientLayout;
import org.jboss.fuse.mvnd.client.ClientOutput;
import org.jboss.fuse.mvnd.junit.MvndTest;
import org.jboss.fuse.mvnd.junit.TestUtils;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -55,6 +56,7 @@ public class MultiModuleTest {
});
final Path localMavenRepo = layout.getLocalMavenRepository();
TestUtils.deleteDir(localMavenRepo);
final Path[] installedJars = {
localMavenRepo.resolve(
"org/jboss/fuse/mvnd/test/multi-module/multi-module-api/0.0.1-SNAPSHOT/multi-module-api-0.0.1-SNAPSHOT.jar"),

View File

@@ -25,6 +25,7 @@ import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientLayout;
import org.jboss.fuse.mvnd.client.ClientOutput;
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
import org.jboss.fuse.mvnd.junit.TestUtils;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
@@ -45,7 +46,9 @@ public class SingleModuleNativeIT {
Files.delete(helloFilePath);
}
final Path installedJar = layout.getLocalMavenRepository().resolve(
final Path localMavenRepo = layout.getLocalMavenRepository();
TestUtils.deleteDir(localMavenRepo);
final Path installedJar = localMavenRepo.resolve(
"org/jboss/fuse/mvnd/test/single-module/single-module/0.0.1-SNAPSHOT/single-module-0.0.1-SNAPSHOT.jar");
Assertions.assertThat(installedJar).doesNotExist();

View File

@@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;
@@ -38,6 +37,8 @@ import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import static org.jboss.fuse.mvnd.junit.TestUtils.deleteDir;
public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback {
/** A placeholder to replace with a temporary directory outside of the current source tree */
@@ -204,29 +205,12 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
return new MvndResource(layout, registry, isNative, timeoutMs);
}
static Path deleteDir(Path dir) {
if (Files.exists(dir)) {
try (Stream<Path> files = Files.walk(dir)) {
files.sorted(Comparator.reverseOrder())
.forEach(f -> {
try {
Files.delete(f);
} catch (IOException e) {
throw new RuntimeException("Could not delete " + f);
}
});
} catch (IOException e1) {
throw new RuntimeException("Could not walk " + dir);
}
}
return dir;
}
static Path createSettings(Path settingsPath) {
final Path settingsTemplatePath = Paths.get("src/test/resources/settings-template.xml");
try {
final String template = new String(Files.readAllBytes(settingsTemplatePath), StandardCharsets.UTF_8);
final String content = template;
final String template = Files.readString(settingsTemplatePath);
final String content = template.replaceAll("@mrm.repository.url@",
Objects.requireNonNull(System.getProperty("mrm.repository.url")));
try {
Files.write(settingsPath, content.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {

View File

@@ -19,12 +19,14 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;
public class TestUtils {
public static void replace(Path path, String find, String replacement) {
try {
final String originalSrc = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
final String originalSrc = Files.readString(path);
final String newSrc = originalSrc.replace(find, replacement);
if (originalSrc.equals(newSrc)) {
throw new IllegalStateException("[" + find + "] not found in " + path);
@@ -34,4 +36,24 @@ public class TestUtils {
throw new RuntimeException("Could not read or write " + path, e);
}
}
public static Path deleteDir(Path dir) {
if (Files.exists(dir)) {
try (Stream<Path> files = Files.walk(dir)) {
files.sorted(Comparator.reverseOrder()).forEach(TestUtils::deleteFile);
} catch (Exception e) {
throw new RuntimeException("Could not walk " + dir, e);
}
}
return dir;
}
private static void deleteFile(Path f) {
try {
Files.delete(f);
} catch (Exception e) {
throw new RuntimeException("Could not delete " + f, e);
}
}
}

View File

@@ -17,5 +17,52 @@
-->
<settings>
<mirrors>
<mirror>
<id>mrm-maven-plugin</id>
<name>Mock Repository Manager</name>
<url>@mrm.repository.url@</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>it-repo</id>
<repositories>
<repository>
<id>snapshots</id>
<url>@mrm.repository.url@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<url>@mrm.repository.url@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>it-repo</activeProfile>
</activeProfiles>
</settings>