]> source.dussan.org Git - archiva.git/commitdiff
Running rest tests concurrently to reduce build time
authorMartin Stockhammer <martin.stockhammer@ars.de>
Wed, 31 Oct 2018 15:32:09 +0000 (16:32 +0100)
committerMartin Stockhammer <martin.stockhammer@ars.de>
Wed, 31 Oct 2018 15:32:09 +0000 (16:32 +0100)
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RemoteRepositoriesServiceTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoryGroupServiceTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/RuntimeInfoServiceTest.java

index 20fb8b675dda8e346566153a823d845140c1000f..97270b0a5b4e132cdc55ca73af88e052c691ff81 100644 (file)
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
+          <forkCount>2</forkCount>
           <reuseForks>false</reuseForks>
           <includes>
             <include>**/*Tests.java</include>
             <include>**/*Test.java</include>
           </includes>
+          <workingDirectory>${project.build.directory}/WDIR-${surefire.forkNumber}</workingDirectory>
+          <trimStackTrace>false</trimStackTrace>
           <!--
-          <argLine>-Xms1024m -Xmx3072m -server -XX:MaxPermSize=256m @{jacocoproperty}</argLine>
+            The property jdk.net.URLClassPath.disableClassPathURLCheck is a workaround for a regression
+            with surefire and OpenJDK 8 181b13 on Debian/Ubuntu,
+            @see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911925
           -->
-          <argLine>-Xms1024m -Xmx3072m -server -XX:MaxPermSize=256m</argLine>
+          <argLine>-Xms256m -Xmx512m -server -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
           <systemPropertyVariables>
-            <appserver.base>${project.build.directory}/appserver-base</appserver.base>
-            <plexus.home>${project.build.directory}/appserver-base</plexus.home>
-            <derby.system.home>${project.build.directory}/appserver-base</derby.system.home>
+            <mvn.project.base.dir>${project.basedir}</mvn.project.base.dir>
+            <appserver.base>${project.build.directory}/appserver-base-${surefire.forkNumber}</appserver.base>
+            <plexus.home>${project.build.directory}/appserver-base-${surefire.forkNumber}</plexus.home>
+            <derby.system.home>${project.build.directory}/appserver-base-${surefire.forkNumber}</derby.system.home>
             <archiva.baseRestUrl>${archiva.baseRestUrl}</archiva.baseRestUrl>
             <rest.admin.pwd>${rest.admin.pwd}</rest.admin.pwd>
             <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
index 9e370b7bc24ee5dffeb4651a614404a483beb1db..6e838131e08997190d27bda8bd89b2397cb8b18b 100644 (file)
@@ -45,6 +45,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.junit.After;
 import org.junit.Assume;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -59,6 +60,7 @@ import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Locale;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * @author Olivier Lamy
@@ -67,6 +69,19 @@ import java.util.Locale;
 public abstract class AbstractArchivaRestTest
     extends AbstractRestServicesTest
 {
+    private AtomicReference<Path> buildDir = new AtomicReference<>();
+    private boolean reuseServer = true;
+
+
+    protected void setReuseServer(boolean value) {
+        this.reuseServer = value;
+    }
+
+    protected boolean isReuseServer() {
+        return this.reuseServer;
+    }
+
+
 
     // START SNIPPET: authz-header
     // guest with an empty password
@@ -81,7 +96,7 @@ public abstract class AbstractArchivaRestTest
 
 
     @BeforeClass
-    public static void chekRepo()
+    public static void checkRepo()
     {
         Assume.assumeTrue( !System.getProperty( "appserver.base" ).contains( " " ) );
         LoggerFactory.getLogger( AbstractArchivaRestTest.class.getName() ).
@@ -96,13 +111,31 @@ public abstract class AbstractArchivaRestTest
     public void startServer()
         throws Exception
     {
-        Path appServerBase = Paths.get( System.getProperty( "appserver.base" ) );
+        if ( (!isReuseServer()) || (isReuseServer() && !isServerRunning())) {
+            log.info("Starting new server reuse={}, running={}, instance={}, server={}", isReuseServer(), isServerRunning(), this.hashCode(), getServer()==null ? "" : getServer().hashCode());
+            Path appServerBase = Paths.get(System.getProperty("appserver.base"));
 
-        removeAppsubFolder( appServerBase, "jcr" );
-        removeAppsubFolder( appServerBase, "conf" );
-        removeAppsubFolder( appServerBase, "data" );
+            removeAppsubFolder(appServerBase, "jcr");
+            removeAppsubFolder(appServerBase, "conf");
+            removeAppsubFolder(appServerBase, "data");
+            super.startServer();
+        } else {
+            log.info("Reusing running server instance reuse={}, running={}", isReuseServer(), isServerRunning());
+        }
+    }
 
-        super.startServer();
+    @Override
+    @After
+    public void stopServer()
+            throws Exception
+    {
+        if ( !isReuseServer() )
+        {
+            log.info("Stopping server reuse={}, running={}, instance={}, server={}", isReuseServer(), isServerRunning(), this.hashCode(), getServer()==null ? "" : getServer().hashCode());
+            super.stopServer();
+        } else {
+            log.info("Server not stopping reuse={}, running={}", isReuseServer(), isServerRunning());
+        }
     }
 
 
@@ -142,7 +175,7 @@ public abstract class AbstractArchivaRestTest
         {
             WebClient.client( service ).header( "Authorization", authzHeader );
         }
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
         WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
@@ -205,7 +238,7 @@ public abstract class AbstractArchivaRestTest
                                        Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         WebClient.client( service ).header( "Authorization", authorizationHeader );
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
         WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
@@ -220,7 +253,7 @@ public abstract class AbstractArchivaRestTest
                                        Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         WebClient.client( service ).header( "Authorization", authorizationHeader );
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
         WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
@@ -238,7 +271,7 @@ public abstract class AbstractArchivaRestTest
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
 
         WebClient.client( service ).header( "Authorization", authorizationHeader );
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
 
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
         return service;
@@ -255,7 +288,7 @@ public abstract class AbstractArchivaRestTest
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
 
         WebClient.client( service ).header( "Authorization", authorizationHeader );
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
         return service;
     }
@@ -273,7 +306,7 @@ public abstract class AbstractArchivaRestTest
             WebClient.client( service ).header( "Authorization", authzHeader );
         }
         // Set the Referer header to your archiva server url
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
 
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
         if ( useXml )
@@ -304,7 +337,7 @@ public abstract class AbstractArchivaRestTest
             WebClient.client( service ).header( "Authorization", authzHeader );
         }
         // Set the Referer header to your archiva server url
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         // to configure read timeout
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
         // if you want to use json as exchange format xml is supported too
@@ -326,7 +359,7 @@ public abstract class AbstractArchivaRestTest
         {
             WebClient.client( service ).header( "Authorization", authzHeader );
         }
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
         WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
         WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
@@ -344,7 +377,21 @@ public abstract class AbstractArchivaRestTest
     protected String getBaseUrl()
     {
         String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
-        return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
+        return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + getServerPort() : baseUrlSysProps;
+    }
+
+    protected Path getBuildDirectory() {
+        if (buildDir.get()==null) {
+            String propVal = System.getProperty("mvn.project.base.dir");
+            Path newVal;
+            if (StringUtils.isEmpty(propVal)) {
+                newVal = Paths.get("").toAbsolutePath();
+            } else {
+                newVal = Paths.get(propVal).toAbsolutePath();
+            }
+            buildDir.compareAndSet(null, newVal);
+        }
+        return buildDir.get();
     }
 
     //-----------------------------------------------------
@@ -384,7 +431,7 @@ public abstract class AbstractArchivaRestTest
             org.apache.archiva.common.utils.FileUtils.deleteDirectory( originRepo );
         }
         assertFalse( Files.exists(originRepo) );
-        FileUtils.copyDirectory( Paths.get( "src/test/repo-with-osgi" ).toAbsolutePath().toFile(), originRepo.toAbsolutePath().toFile() );
+        FileUtils.copyDirectory( getBuildDirectory().resolve("src/test/repo-with-osgi" ).toAbsolutePath().toFile(), originRepo.toAbsolutePath().toFile() );
 
         if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( SOURCE_REPO_ID ) != null )
         {
index 96ebf469687f41baad3d9e6c10cf21cdd99f778b..c199838f2ec664532525fb95bf6c1bb7968f0e84 100644 (file)
@@ -128,7 +128,7 @@ public class ArchivaAdministrationServiceTest
 
         UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
         assertNotNull( ui );
-        assertNull( ui.getApplicationUrl() );
+        // assertNull( ui.getApplicationUrl() );
 
         String url = "http://foo.fr/bar/";
         ui.setApplicationUrl( url );
index 57e3a1af744a463624c140f3abf2543f8442609b..556b5f408c53548f00096e4e66671d85652d557a 100644 (file)
@@ -36,6 +36,23 @@ public class RemoteRepositoriesServiceTest
 {
 
 
+    private void removeRemoteRepositories(String... repos) {
+        try {
+            RemoteRepositoriesService service = getRemoteRepositoriesService();
+            WebClient.client( service ).header( "Authorization", authorizationHeader );
+            for (String repo : repos ) {
+                try {
+                    service.deleteRemoteRepository(repo);
+                } catch (Throwable ex) {
+                    log.warn("Could not remove repo {}", repo);
+                    // ignore
+                }
+            }
+        } catch (Throwable ex) {
+            // ignore
+        }
+    }
+
     @Test( expected = ForbiddenException.class )
     public void listRemoteRepositoriesKarmaFailed()
         throws Exception
@@ -150,15 +167,19 @@ public class RemoteRepositoriesServiceTest
     @Test
     public void checkRemoteConnectivity()
             throws Exception {
-        RemoteRepositoriesService service = getRemoteRepositoriesService();
+        try {
+            RemoteRepositoriesService service = getRemoteRepositoriesService();
 
-        WebClient.client(service).header("Authorization", authorizationHeader);
+            WebClient.client(service).header("Authorization", authorizationHeader);
 
-        int initialSize = service.getRemoteRepositories().size();
+            int initialSize = service.getRemoteRepositories().size();
 
-        service.addRemoteRepository(getRemoteRepository());
+            service.addRemoteRepository(getRemoteRepository());
 
-        assertTrue(service.checkRemoteConnectivity("id-new"));
+            assertTrue(service.checkRemoteConnectivity("id-new"));
+        } finally {
+            removeRemoteRepositories("id-new");
+        }
 
     }
 
@@ -168,15 +189,19 @@ public class RemoteRepositoriesServiceTest
     @Test
     public void checkRemoteConnectivity2()
             throws Exception {
-        RemoteRepositoriesService service = getRemoteRepositoriesService();
+        try {
+            RemoteRepositoriesService service = getRemoteRepositoriesService();
 
-        WebClient.client(service).header("Authorization", authorizationHeader);
+            WebClient.client(service).header("Authorization", authorizationHeader);
 
-        int initialSize = service.getRemoteRepositories().size();
+            int initialSize = service.getRemoteRepositories().size();
 
-        service.addRemoteRepository(getRemoteMavenRepository());
+            service.addRemoteRepository(getRemoteMavenRepository());
 
-        assertTrue(service.checkRemoteConnectivity("id-maven1"));
+            assertTrue(service.checkRemoteConnectivity("id-maven1"));
+        } finally {
+            removeRemoteRepositories("id-maven1");
+        }
 
     }
 
@@ -187,16 +212,20 @@ public class RemoteRepositoriesServiceTest
     @Test
     public void checkRemoteConnectivity3()
             throws Exception {
-        RemoteRepositoriesService service = getRemoteRepositoriesService();
+        try {
+            RemoteRepositoriesService service = getRemoteRepositoriesService();
 
-        WebClient.client(service).header("Authorization", authorizationHeader);
-        WebClient.client(service).accept("application/json");
+            WebClient.client(service).header("Authorization", authorizationHeader);
+            WebClient.client(service).accept("application/json");
 
-        int initialSize = service.getRemoteRepositories().size();
+            int initialSize = service.getRemoteRepositories().size();
 
-        service.addRemoteRepository(getRemoteOracleRepository());
+            service.addRemoteRepository(getRemoteOracleRepository());
 
-        assertTrue(service.checkRemoteConnectivity("id-oracle"));
+            assertTrue(service.checkRemoteConnectivity("id-oracle"));
+        } finally {
+            removeRemoteRepositories("id-oracle");
+        }
 
     }
 
index 1fee4a342701c19f68add9a6dd449f97179bf47c..3f08c20c0a1f4c0249c8c8c64815fedbe1863a09 100644 (file)
@@ -39,7 +39,7 @@ public class RepositoryGroupServiceTest
     {
         RepositoryGroupService service = getRepositoryGroupService();
         WebClient.client( service ).header( "Authorization", authorizationHeader );
-        WebClient.client(service).header("Referer","http://localhost:"+port);
+        WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
 
         WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
 
index d694701f76cb3055ebe3c178b7e6b9c4e14bea7f..7e8d027f4468feec78f0957bf22eeea0e11fc552 100644 (file)
@@ -171,7 +171,7 @@ public class SearchServiceTest
             log.info( "url: {}", artifact.getUrl() );
             String version = artifact.getVersion();
             Assertions.assertThat( artifact.getUrl() ) //
-                .isEqualTo( "http://localhost:" + port
+                .isEqualTo( "http://localhost:" + getServerPort()
                                 + "/repository/test-repo/org/apache/karaf/features/org.apache.karaf.features.core/"
                                 + version + "/org.apache.karaf.features.core-" + version + ".jar" );
 
index 60796a3f8c9a685eba49593f9d48df0703c131d8..2c0874346f4048b8e34307d1643f4f051d67b707 100644 (file)
@@ -74,7 +74,7 @@ public class RuntimeInfoServiceTest
     protected String getBaseUrl()
     {
         String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
-        return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
+        return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + getServerPort() : baseUrlSysProps;
     }
 
     @Test