]> source.dussan.org Git - sonarqube.git/commitdiff
Fix startup when no rule registered
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:02:29 +0000 (16:02 +0100)
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistry.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java

index 773e2d5025c3b55b93b36fe60688ec2652d9ecae..cd639f1beb7fcf217dd2bd0a659e5a683e5a816c 100644 (file)
@@ -170,9 +170,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 6689af02771bf4e31521f9901f6d88109064c690..66ee278bf1a6ef26e1a9facebeb3fbe3c1e01fe9 100644 (file)
@@ -24,6 +24,7 @@ import com.github.tlrx.elasticsearch.test.EsSetup;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import org.apache.commons.io.IOUtils;
+import org.elasticsearch.common.collect.Lists;
 import org.elasticsearch.search.SearchHit;
 import org.junit.After;
 import org.junit.Before;
@@ -149,6 +150,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;