]> source.dussan.org Git - sonarqube.git/commitdiff
Allow parallel execution of tests using ServerTester
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 7 Apr 2015 20:11:08 +0000 (22:11 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 7 Apr 2015 20:19:42 +0000 (22:19 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java
server/sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java
server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/ServerTester.java

index 624ad9854b69eb1b546cb565defe724e9c43e076..b98a7c9f09d451bbc2323440ba37222834656fbb 100644 (file)
@@ -46,18 +46,20 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable {
   private static final Logger LOGGER = Loggers.get(DefaultServerFileSystem.class);
 
   private final Server server;
-  private File homeDir;
+  private final File homeDir, tempDir;
 
   public DefaultServerFileSystem(Settings settings, Server server) {
     this.server = server;
     this.homeDir = new File(settings.getString(ProcessProperties.PATH_HOME));
+    this.tempDir = new File(settings.getString(ProcessProperties.PATH_TEMP));
   }
 
   /**
    * for unit tests
    */
-  public DefaultServerFileSystem(File homeDir, Server server) {
+  public DefaultServerFileSystem(File homeDir, File tempDir, Server server) {
     this.homeDir = homeDir;
+    this.tempDir = tempDir;
     this.server = server;
   }
 
@@ -99,8 +101,7 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable {
 
   @Override
   public File getTempDir() {
-    // Tomcat is started by app process with correct java.io.tmpdir
-    return FileUtils.getTempDirectory();
+    return tempDir;
   }
 
   public File getDeployDir() {
index c352047a81e74f68b4e0ab222b8bc0b1e8f2257b..c06a788702238a212d5ca2a107d87f67604a5a1e 100644 (file)
@@ -20,7 +20,9 @@
 package org.sonar.server.platform;
 
 import com.google.common.io.Resources;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.sonar.api.platform.ServerFileSystem;
 
 import java.io.File;
@@ -32,21 +34,27 @@ public class DefaultServerFileSystemTest {
 
   private static final String PATH = "org/sonar/server/platform/DefaultServerFileSystemTest/";
 
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
   @Test
   public void find_plugins() throws Exception {
-    List<File> plugins = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), null).getUserPlugins();
+    List<File> plugins = new DefaultServerFileSystem(
+      new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), temp.newFolder(), null).getUserPlugins();
     assertThat(plugins).hasSize(2);
   }
 
   @Test
   public void not_fail_if_no_plugins() throws Exception {
-    List<File> plugins = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), null).getUserPlugins();
+    List<File> plugins = new DefaultServerFileSystem(
+      new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), temp.newFolder(), null).getUserPlugins();
     assertThat(plugins).isEmpty();
   }
 
   @Test
   public void find_checkstyle_extensions() throws Exception {
-    ServerFileSystem fs = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), null);
+    ServerFileSystem fs = new DefaultServerFileSystem(
+      new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), temp.newFolder(), null);
 
     List<File> xmls = fs.getExtensions("checkstyle", "xml");
     assertThat(xmls).hasSize(1);
@@ -57,7 +65,8 @@ public class DefaultServerFileSystemTest {
 
   @Test
   public void not_fail_if_no_checkstyle_extensions() throws Exception {
-    ServerFileSystem fs = new DefaultServerFileSystem(new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), null);
+    ServerFileSystem fs = new DefaultServerFileSystem(
+      new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), temp.newFolder(), null);
     List<File> xmls = fs.getExtensions("checkstyle", "xml");
     assertThat(xmls).isEmpty();
 
index fea094c3b9afad19ea8d38005cc721a20ec02519..d90b0bc0c765c57cad2f89ca3dd8451969318792 100644 (file)
@@ -68,7 +68,7 @@ public class ServerPluginJarsInstallerTest {
     coreDir = new File(homeDir, "lib/core-plugins");
     FileUtils.forceMkdir(bundledDir);
 
-    fileSystem = new DefaultServerFileSystem(homeDir, server);
+    fileSystem = new DefaultServerFileSystem(homeDir, temp.newFolder(), server);
     jarInstaller = new ServerPluginJarInstaller();
     jarsInstaller = new ServerPluginJarsInstaller(server, upgradeStatus, fileSystem, jarInstaller);
   }
index b6c3d6fd85650685e4d7580944b1403db6ada797..93891e4b178501aeed74db7f5612ee7ef6162c96 100644 (file)
@@ -39,6 +39,7 @@ import org.sonar.test.TestUtils;
 import javax.annotation.Nullable;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -87,6 +88,7 @@ public class ServerTester extends ExternalResource {
       properties.setProperty(ProcessProperties.SEARCH_HOST, String.valueOf(esServerHolder.getHostName()));
       properties.setProperty(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath());
       properties.setProperty(ProcessProperties.PATH_DATA, new File(homeDir, "data").getAbsolutePath());
+      properties.setProperty(ProcessProperties.PATH_TEMP, createTemporaryFolderIn().getAbsolutePath());
       properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:" + homeDir.getAbsolutePath() + "/h2");
       for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
         String key = entry.getKey().toString();
@@ -108,6 +110,13 @@ public class ServerTester extends ExternalResource {
     }
   }
 
+  private File createTemporaryFolderIn() throws IOException {
+    File createdFolder = File.createTempFile("ServerTester", "");
+    createdFolder.delete();
+    createdFolder.mkdir();
+    return createdFolder;
+  }
+
   /**
    * Called only when JUnit @Rule or @ClassRule is used.
    */