aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-02-08 15:33:50 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2018-02-08 17:00:47 +0100
commit198f987a5e79d2816a9d7172112aff1dfc669bfd (patch)
treeb5135cf19b1f15ad036462c57a5aba9a8ce67dc9 /server/sonar-server/src/test
parentb55d57a11579a2e20938f35a3090e64e0eaa1f80 (diff)
downloadsonarqube-198f987a5e79d2816a9d7172112aff1dfc669bfd.tar.gz
sonarqube-198f987a5e79d2816a9d7172112aff1dfc669bfd.zip
SONAR-10395 Improve time compressing plugins in SonarCloud
Diffstat (limited to 'server/sonar-server/src/test')
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/PluginCompressionTest.java35
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarExploderTest.java2
2 files changed, 30 insertions, 7 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginCompressionTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginCompressionTest.java
index 8939cb2d156..99e0d81410f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginCompressionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/PluginCompressionTest.java
@@ -35,21 +35,26 @@ public class PluginCompressionTest {
public TemporaryFolder temp = new TemporaryFolder();
private MapSettings settings = new MapSettings();
- private Path jarPath;
+ private Path targetJarPath;
+ private Path targetFolder;
+ private Path sourceFolder;
private PluginCompression underTest;
@Before
public void setUp() throws IOException {
- jarPath = temp.newFile("test.jar").toPath();
+ sourceFolder = temp.newFolder("source").toPath();
+ targetFolder = temp.newFolder("target").toPath();
+ targetJarPath = targetFolder.resolve("test.jar");
+ Files.createFile(targetJarPath);
}
@Test
public void disable_if_proparty_not_set() throws IOException {
underTest = new PluginCompression(settings.asConfig());
- underTest.compressJar("key", jarPath);
+ underTest.compressJar("key", sourceFolder, targetJarPath);
- assertThat(Files.list(jarPath.getParent())).containsOnly(jarPath);
+ assertThat(Files.list(targetFolder)).containsOnly(targetJarPath);
assertThat(underTest.getPlugins()).isEmpty();
}
@@ -57,10 +62,28 @@ public class PluginCompressionTest {
public void should_compress_plugin() throws IOException {
settings.setProperty(PluginCompression.PROPERTY_PLUGIN_COMPRESSION_ENABLE, true);
underTest = new PluginCompression(settings.asConfig());
- underTest.compressJar("key", jarPath);
+ underTest.compressJar("key", targetFolder, targetJarPath);
- assertThat(Files.list(jarPath.getParent())).containsOnly(jarPath, jarPath.getParent().resolve("test.pack.gz"));
+ assertThat(Files.list(targetFolder)).containsOnly(targetJarPath, targetFolder.resolve("test.pack.gz"));
assertThat(underTest.getPlugins()).hasSize(1);
assertThat(underTest.getPlugins().get("key").getFilename()).isEqualTo("test.pack.gz");
}
+
+ @Test
+ public void should_use_deployed_packed_file() throws IOException {
+ Path packedPath = sourceFolder.resolve("test.pack.gz");
+ Files.write(packedPath, new byte[] {1, 2, 3});
+
+ settings.setProperty(PluginCompression.PROPERTY_PLUGIN_COMPRESSION_ENABLE, true);
+ underTest = new PluginCompression(settings.asConfig());
+ underTest.compressJar("key", sourceFolder, targetJarPath);
+
+ assertThat(Files.list(targetFolder)).containsOnly(targetJarPath, targetFolder.resolve("test.pack.gz"));
+ assertThat(underTest.getPlugins()).hasSize(1);
+ assertThat(underTest.getPlugins().get("key").getFilename()).isEqualTo("test.pack.gz");
+
+ // check that the file was copied, not generated
+ assertThat(targetFolder.resolve("test.pack.gz")).hasSameContentAs(packedPath);
+ }
+
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarExploderTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarExploderTest.java
index fff4600e1bf..92ab9ff73fd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarExploderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarExploderTest.java
@@ -61,6 +61,6 @@ public class ServerPluginJarExploderTest {
assertThat(lib).exists().isFile();
assertThat(lib.getCanonicalPath()).startsWith(pluginDeployDir.getCanonicalPath());
}
- verify(pluginCompression).compressJar(info.getKey(), exploded.getMain().toPath());
+ verify(pluginCompression).compressJar(info.getKey(), jar.toPath().getParent(), exploded.getMain().toPath());
}
}