|
@@ -12,7 +12,6 @@ import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.delete.DeleteResponse;
|
|
|
import org.elasticsearch.action.index.IndexResponse;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
-import org.elasticsearch.index.engine.VersionConflictEngineException;
|
|
|
import org.elasticsearch.indices.SystemIndexDescriptor;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.plugins.SystemIndexPlugin;
|
|
@@ -59,31 +58,6 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
assertThat(listResults.totalResults(), equalTo(0L));
|
|
|
}
|
|
|
|
|
|
- public void testCreateQueryRuleset() throws Exception {
|
|
|
- final QueryRule myQueryRule1 = new QueryRule(
|
|
|
- "my_rule1",
|
|
|
- QueryRuleType.PINNED,
|
|
|
- List.of(new QueryRuleCriteria(CriteriaType.EXACT, "query_string", "foo")),
|
|
|
- Map.of("ids", List.of("id1", "id2"))
|
|
|
- );
|
|
|
- final QueryRule myQueryRule2 = new QueryRule(
|
|
|
- "my_rule2",
|
|
|
- QueryRuleType.PINNED,
|
|
|
- List.of(new QueryRuleCriteria(CriteriaType.EXACT, "query_string", "bar")),
|
|
|
- Map.of("ids", List.of("id3", "id4"))
|
|
|
- );
|
|
|
- final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
|
|
|
-
|
|
|
- IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, true);
|
|
|
- assertThat(resp.status(), equalTo(RestStatus.CREATED));
|
|
|
- assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
|
|
|
-
|
|
|
- QueryRuleset getQueryRuleset = awaitGetQueryRuleset(myQueryRuleset.id());
|
|
|
- assertThat(getQueryRuleset, equalTo(myQueryRuleset));
|
|
|
-
|
|
|
- expectThrows(VersionConflictEngineException.class, () -> awaitPutQueryRuleset(myQueryRuleset, true));
|
|
|
- }
|
|
|
-
|
|
|
public void testUpdateQueryRuleset() throws Exception {
|
|
|
{
|
|
|
final QueryRule myQueryRule1 = new QueryRule(
|
|
@@ -93,7 +67,7 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
Map.of("ids", List.of("id1", "id2"))
|
|
|
);
|
|
|
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", Collections.singletonList(myQueryRule1));
|
|
|
- IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
|
|
|
+ IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
|
|
|
assertThat(resp.status(), anyOf(equalTo(RestStatus.CREATED), equalTo(RestStatus.OK)));
|
|
|
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
|
|
|
|
|
@@ -114,7 +88,7 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
Map.of("docs", List.of(Map.of("_index", "my_index1", "_id", "id3"), Map.of("_index", "my_index2", "_id", "id4")))
|
|
|
);
|
|
|
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
|
|
|
- IndexResponse newResp = awaitPutQueryRuleset(myQueryRuleset, false);
|
|
|
+ IndexResponse newResp = awaitPutQueryRuleset(myQueryRuleset);
|
|
|
assertThat(newResp.status(), equalTo(RestStatus.OK));
|
|
|
assertThat(newResp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
|
|
|
QueryRuleset getQueryRuleset = awaitGetQueryRuleset(myQueryRuleset.id());
|
|
@@ -140,7 +114,7 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
);
|
|
|
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset_" + i, rules);
|
|
|
|
|
|
- IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
|
|
|
+ IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
|
|
|
assertThat(resp.status(), equalTo(RestStatus.CREATED));
|
|
|
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
|
|
|
}
|
|
@@ -188,7 +162,7 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
Map.of("ids", List.of("id3", "id4"))
|
|
|
);
|
|
|
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
|
|
|
- IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
|
|
|
+ IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
|
|
|
assertThat(resp.status(), anyOf(equalTo(RestStatus.CREATED), equalTo(RestStatus.OK)));
|
|
|
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
|
|
|
|
|
@@ -201,11 +175,11 @@ public class QueryRulesIndexServiceTests extends ESSingleNodeTestCase {
|
|
|
expectThrows(ResourceNotFoundException.class, () -> awaitGetQueryRuleset("my_ruleset"));
|
|
|
}
|
|
|
|
|
|
- private IndexResponse awaitPutQueryRuleset(QueryRuleset queryRuleset, boolean create) throws Exception {
|
|
|
+ private IndexResponse awaitPutQueryRuleset(QueryRuleset queryRuleset) throws Exception {
|
|
|
CountDownLatch latch = new CountDownLatch(1);
|
|
|
final AtomicReference<IndexResponse> resp = new AtomicReference<>(null);
|
|
|
final AtomicReference<Exception> exc = new AtomicReference<>(null);
|
|
|
- queryRulesIndexService.putQueryRuleset(queryRuleset, create, new ActionListener<>() {
|
|
|
+ queryRulesIndexService.putQueryRuleset(queryRuleset, new ActionListener<>() {
|
|
|
@Override
|
|
|
public void onResponse(IndexResponse indexResponse) {
|
|
|
resp.set(indexResponse);
|