aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-home
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-29 09:05:19 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-30 16:28:08 +0200
commitf5aa4163eb68aa987923d62bda08a8c49450cb1c (patch)
treee9260e7b6fff8c061032398fe9b11a03bf9bfc72 /sonar-home
parenta23a7ec4f48244c193b48aec84127701618a31cc (diff)
downloadsonarqube-f5aa4163eb68aa987923d62bda08a8c49450cb1c.tar.gz
sonarqube-f5aa4163eb68aa987923d62bda08a8c49450cb1c.zip
SONAR-6818 Split batch/project WS in several simpler WS
Diffstat (limited to 'sonar-home')
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java3
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java13
2 files changed, 16 insertions, 0 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
index dfc94827d0b..991fadf8cdc 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
@@ -90,6 +90,9 @@ public class PersistentCache {
try {
lock();
Path path = getCacheCopy(key);
+ if (path == null) {
+ return null;
+ }
return new DeleteFileOnCloseInputStream(new FileInputStream(path.toFile()), path);
} finally {
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
index 77ee30908e1..5063fbdb22f 100644
--- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
+++ b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
@@ -19,7 +19,11 @@
*/
package org.sonar.home.cache;
+import org.apache.commons.io.IOUtils;
+
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -72,6 +76,15 @@ public class PersistentCacheTest {
}
@Test
+ public void testStream() throws IOException {
+ cache.put("id", "test".getBytes());
+ InputStream stream = cache.getStream("id");
+ assertThat(IOUtils.toString(stream)).isEqualTo("test");
+
+ assertThat(cache.getStream("non existing")).isNull();
+ }
+
+ @Test
public void testClear() throws Exception {
Path lockFile = cache.getDirectory().resolve("lock");
cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));