Add restart node enrich tests. (#43579)

This test verifies that enrich policies still exist after a full
cluster restart. If EnrichPolicy is not registered as named xcontent
in EnrichPlugin class then this test fails.
This commit is contained in:
Martijn van Groningen 2019-07-01 17:29:38 +02:00
parent 8f3387e7cb
commit 785aedebad
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 76 additions and 4 deletions

View File

@ -46,11 +46,11 @@ import static org.hamcrest.Matchers.notNullValue;
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
public class EnrichMultiNodeIT extends ESIntegTestCase { public class EnrichMultiNodeIT extends ESIntegTestCase {
private static final String POLICY_NAME = "my-policy"; static final String POLICY_NAME = "my-policy";
private static final String PIPELINE_NAME = "my-pipeline"; private static final String PIPELINE_NAME = "my-pipeline";
private static final String SOURCE_INDEX_NAME = "users"; static final String SOURCE_INDEX_NAME = "users";
private static final String KEY_FIELD = "email"; static final String KEY_FIELD = "email";
private static final String[] DECORATE_FIELDS = new String[]{"address", "city", "country"}; static final String[] DECORATE_FIELDS = new String[]{"address", "city", "country"};
@Override @Override
protected Collection<Class<? extends Plugin>> nodePlugins() { protected Collection<Class<? extends Plugin>> nodePlugins() {

View File

@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.enrich;
import org.elasticsearch.index.reindex.ReindexPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
import org.elasticsearch.xpack.core.enrich.action.ListEnrichPolicyAction;
import org.elasticsearch.xpack.core.enrich.action.PutEnrichPolicyAction;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import static org.elasticsearch.xpack.enrich.EnrichMultiNodeIT.DECORATE_FIELDS;
import static org.elasticsearch.xpack.enrich.EnrichMultiNodeIT.KEY_FIELD;
import static org.elasticsearch.xpack.enrich.EnrichMultiNodeIT.POLICY_NAME;
import static org.elasticsearch.xpack.enrich.EnrichMultiNodeIT.SOURCE_INDEX_NAME;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
public class EnrichRestartIT extends ESIntegTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(EnrichPlugin.class, ReindexPlugin.class);
}
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return nodePlugins();
}
public void testRestart() throws Exception {
final int numPolicies = randomIntBetween(2, 4);
internalCluster().startNode();
EnrichPolicy enrichPolicy = new EnrichPolicy(EnrichPolicy.EXACT_MATCH_TYPE, null,
Collections.singletonList(SOURCE_INDEX_NAME), KEY_FIELD, Arrays.asList(DECORATE_FIELDS));
for (int i = 0; i < numPolicies; i++) {
String policyName = POLICY_NAME + i;
PutEnrichPolicyAction.Request request = new PutEnrichPolicyAction.Request(policyName, enrichPolicy);
client().execute(PutEnrichPolicyAction.INSTANCE, request).actionGet();
}
verifyPolicies(numPolicies, enrichPolicy);
// After full restart the policies should still exist:
internalCluster().fullRestart();
verifyPolicies(numPolicies, enrichPolicy);
}
private static void verifyPolicies(int numPolicies, EnrichPolicy enrichPolicy) {
ListEnrichPolicyAction.Response response =
client().execute(ListEnrichPolicyAction.INSTANCE, new ListEnrichPolicyAction.Request()).actionGet();
assertThat(response.getPolicies().size(), equalTo(numPolicies));
for (int i = 0; i < numPolicies; i++) {
String policyName = POLICY_NAME + i;
Optional<EnrichPolicy.NamedPolicy> result = response.getPolicies().stream()
.filter(namedPolicy -> namedPolicy.getName().equals(policyName))
.findFirst();
assertThat(result.isPresent(), is(true));
assertThat(result.get().getPolicy(), equalTo(enrichPolicy));
}
}
}