diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-03-24 11:30:22 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-03-24 11:30:22 +0100 |
commit | 47ab2873f318ebc3cdf0ee44903ee6f4ea6a23f5 (patch) | |
tree | b10218d3c65d67e1078b8dc41c9c071f3e5e4eaa /sonar-home/src/test | |
parent | c95f41167a3d2e30855e4d41a2bde8154ba754be (diff) | |
download | sonarqube-47ab2873f318ebc3cdf0ee44903ee6f4ea6a23f5.tar.gz sonarqube-47ab2873f318ebc3cdf0ee44903ee6f4ea6a23f5.zip |
SONAR-5062 Add test
Diffstat (limited to 'sonar-home/src/test')
-rw-r--r-- | sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java index c4276c38857..5a3e16f0701 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java @@ -29,6 +29,13 @@ import org.sonar.home.log.Slf4jLog; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -121,10 +128,10 @@ public class FileCacheTest { } @Test - public void unzip_from_cache() throws IOException, URISyntaxException { + public void unzip_from_cache() throws IOException, URISyntaxException, InterruptedException, ExecutionException { final File samplePlugin = new File(this.getClass().getResource("/sonar-checkstyle-plugin-2.8.jar").toURI()); FileHashes hashes = mock(FileHashes.class); - FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes); + final FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes); when(hashes.of(any(File.class))).thenReturn("ABCDE"); FileCache.Downloader downloader = new FileCache.Downloader() { @@ -132,11 +139,26 @@ public class FileCacheTest { FileUtils.copyFile(samplePlugin, toFile); } }; - File cachedFile = cache.get("sonar-checkstyle-plugin-2.8.jar", "ABCDE", downloader); + final File cachedFile = cache.get("sonar-checkstyle-plugin-2.8.jar", "ABCDE", downloader); assertThat(cachedFile).isNotNull().exists().isFile(); assertThat(cachedFile.getName()).isEqualTo("sonar-checkstyle-plugin-2.8.jar"); - File pluginDepsDir = cache.unzip(cachedFile); + final int nThreads = 5; + ExecutorService executorService = Executors.newFixedThreadPool(nThreads); + List<Callable<File>> tasks = new ArrayList<Callable<File>>(); + for (int i = 0; i < nThreads; i++) { + tasks.add(new Callable<File>() { + + public File call() throws Exception { + return cache.unzip(cachedFile); + } + }); + } + + File pluginDepsDir = null; + for (Future<File> result : executorService.invokeAll(tasks)) { + pluginDepsDir = result.get(); + } assertThat(pluginDepsDir.listFiles()).hasSize(1); File metaDir = new File(pluginDepsDir, "META-INF"); assertThat(metaDir.listFiles()).hasSize(1); |