]> source.dussan.org Git - sonarqube.git/commitdiff
Fix startup when no rule registered - backport from master
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 13 Dec 2013 15:02:29 +0000 (16:02 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 13 Dec 2013 15:06:54 +0000 (16:06 +0100)
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java

index 5a20ad93b13eee23a1b8a38468f0893d5526ec10..d6388b8e715ef097b9fd3bb38362a0e43a74dae4 100644 (file)
@@ -150,9 +150,12 @@ public class RuleRegistry {
       index ++;
     }
     profiler.stop();
-    profiler.start("Index rules");
-    searchIndex.bulkIndex(INDEX_RULES, TYPE_RULE, ids, docs);
-    profiler.stop();
+
+    if (! rules.isEmpty()) {
+      profiler.start("Index rules");
+      searchIndex.bulkIndex(INDEX_RULES, TYPE_RULE, ids, docs);
+      profiler.stop();
+    }
 
     List<String> indexIds = searchIndex.findDocumentIds(SearchQuery.create().index(INDEX_RULES).type(TYPE_RULE));
     indexIds.removeAll(Arrays.asList(ids));
index 36308d9af0cc0f3a984108455d071f2e1639665b..524c20dad0ddb3efa6e479efb1352f6575ab42f2 100644 (file)
@@ -23,6 +23,7 @@ package org.sonar.server.rule;
 import com.github.tlrx.elasticsearch.test.EsSetup;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -137,6 +138,14 @@ public class RuleRegistryTest {
     registry.findIds(ImmutableMap.of("nameOrKey", "\"'"));
   }
 
+  @Test
+  public void should_remove_all_rules_when_ro_rule_registered() {
+    List<RuleDto> rules = Lists.newArrayList();
+    when(ruleDao.selectNonManual()).thenReturn(rules);
+    registry.bulkRegisterRules();
+    assertThat(registry.findIds(new HashMap<String, String>())).hasSize(0);
+  }
+
   @Test
   public void should_index_all_rules() {
     long ruleId1 = 3L;