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));
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;
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;