diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-02 14:10:44 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-03 09:27:58 +0100 |
commit | 287fbc9aa4a5f78db7dbb42adf422a632b74fa1e (patch) | |
tree | 4e7e31098796af43e86ed552a5a2c2f6087d5b39 /sonar-batch | |
parent | 45c9896c61d28f064952573dff0e30bee5e08d2f (diff) | |
download | sonarqube-287fbc9aa4a5f78db7dbb42adf422a632b74fa1e.tar.gz sonarqube-287fbc9aa4a5f78db7dbb42adf422a632b74fa1e.zip |
SONAR-7100 Disable WS cache by default in issues mode
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java | 9 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java | 19 |
2 files changed, 23 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java index 7ca47ae787a..fc3482a2006 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java @@ -27,19 +27,20 @@ import org.sonar.batch.cache.WSLoader.LoadStrategy; import org.sonar.home.cache.PersistentCache; public class AnalysisWSLoaderProvider extends ProviderAdapter { + static final String SONAR_USE_WS_CACHE = "sonar.useWsCache"; private WSLoader wsLoader; - public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client) { + public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client, AnalysisProperties props) { if (wsLoader == null) { // recreate cache directory if needed for this analysis cache.reconfigure(); - wsLoader = new WSLoader(getStrategy(mode), cache, client); + wsLoader = new WSLoader(getStrategy(mode, props), cache, client); } return wsLoader; } - private static LoadStrategy getStrategy(AnalysisMode mode) { - if (mode.isIssues()) { + private static LoadStrategy getStrategy(AnalysisMode mode, AnalysisProperties props) { + if (mode.isIssues() && "true".equals(props.property(SONAR_USE_WS_CACHE))) { return LoadStrategy.CACHE_ONLY; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java index b175faa6bc6..5aa31bd64d5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.analysis; +import com.google.common.collect.ImmutableMap; +import org.assertj.core.util.Maps; import org.junit.Test; import org.sonar.api.batch.AnalysisMode; import org.sonar.batch.bootstrap.BatchWsClient; @@ -28,6 +30,7 @@ import org.sonar.home.cache.PersistentCache; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class AnalysisWSLoaderProviderTest { @@ -39,7 +42,21 @@ public class AnalysisWSLoaderProviderTest { @Test public void testDefault() { - WSLoader loader = underTest.provide(mode, cache, wsClient); + WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap())); assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY); } + + @Test + public void no_cache_by_default_in_issues_mode() { + when(mode.isIssues()).thenReturn(true); + WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap())); + assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY); + } + + @Test + public void enable_cache_in_issues_mode() { + when(mode.isIssues()).thenReturn(true); + WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(ImmutableMap.of(AnalysisWSLoaderProvider.SONAR_USE_WS_CACHE, "true"))); + assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_ONLY); + } } |