Test deleting the percolate type differently. Instead of checking the types exist api, register a DocumentTypeListener that notifies when percolate queries have been cleared.
This commit is contained in:
parent
83c26eb74a
commit
2ed3dbbf67
|
@ -33,11 +33,13 @@ import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.google.common.collect.Maps.newHashMap;
|
import static com.google.common.collect.Maps.newHashMap;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
|
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||||
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@ -123,6 +125,12 @@ public abstract class AbstractNodesTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Node> nodes() {
|
||||||
|
synchronized (AbstractNodesTests.class) {
|
||||||
|
return new ArrayList<Node>(nodes.values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Node node(String id) {
|
public Node node(String id) {
|
||||||
synchronized (AbstractNodesTests.class) {
|
synchronized (AbstractNodesTests.class) {
|
||||||
return nodes.get(id);
|
return nodes.get(id);
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.elasticsearch.test.integration.percolator;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||||
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||||
|
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
|
||||||
|
import org.elasticsearch.action.percolate.PercolateResponse;
|
||||||
|
import org.elasticsearch.client.Requests;
|
||||||
|
import org.elasticsearch.common.Priority;
|
||||||
|
import org.elasticsearch.index.mapper.DocumentTypeListener;
|
||||||
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
import org.elasticsearch.indices.IndicesService;
|
||||||
|
import org.elasticsearch.node.Node;
|
||||||
|
import org.elasticsearch.node.internal.InternalNode;
|
||||||
|
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder;
|
||||||
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class DeletePercolatorTypeTests extends AbstractNodesTests {
|
||||||
|
|
||||||
|
public void beforeClass() throws Exception {
|
||||||
|
startNode("node1");
|
||||||
|
startNode("node2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeletePercolatorType() throws Exception {
|
||||||
|
DeleteIndexResponse deleteIndexResponse = client().admin().indices().prepareDelete().execute().actionGet();
|
||||||
|
assertThat("Delete Index failed - not acked", deleteIndexResponse.isAcknowledged(), equalTo(true));
|
||||||
|
ensureGreen();
|
||||||
|
|
||||||
|
client().admin().indices().prepareCreate("test1").execute().actionGet();
|
||||||
|
client().admin().indices().prepareCreate("test2").execute().actionGet();
|
||||||
|
ensureGreen();
|
||||||
|
|
||||||
|
client().prepareIndex("test1", "_percolator", "1")
|
||||||
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
client().prepareIndex("test2", "_percolator", "1")
|
||||||
|
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
||||||
|
.execute().actionGet();
|
||||||
|
|
||||||
|
PercolateResponse response = client().preparePercolate()
|
||||||
|
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
||||||
|
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertThat(response.getCount(), equalTo(2l));
|
||||||
|
|
||||||
|
CountDownLatch test1Latch = createCountDownLatch("test1");
|
||||||
|
CountDownLatch test2Latch =createCountDownLatch("test2");
|
||||||
|
|
||||||
|
client().admin().indices().prepareDeleteMapping("test1").setType("_percolator").execute().actionGet();
|
||||||
|
test1Latch.await();
|
||||||
|
|
||||||
|
response = client().preparePercolate()
|
||||||
|
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
||||||
|
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertThat(response.getCount(), equalTo(1l));
|
||||||
|
|
||||||
|
client().admin().indices().prepareDeleteMapping("test2").setType("_percolator").execute().actionGet();
|
||||||
|
test2Latch.await();
|
||||||
|
|
||||||
|
// Percolate api should return 0 matches, because all _percolate types have been removed.
|
||||||
|
response = client().preparePercolate()
|
||||||
|
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
||||||
|
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(response);
|
||||||
|
assertThat(response.getCount(), equalTo(0l));
|
||||||
|
}
|
||||||
|
|
||||||
|
private CountDownLatch createCountDownLatch(String index) {
|
||||||
|
List<Node> nodes = nodes();
|
||||||
|
final CountDownLatch latch = new CountDownLatch(nodes.size());
|
||||||
|
for (Node node : nodes) {
|
||||||
|
IndicesService indexServices = ((InternalNode) node).injector().getInstance(IndicesService.class);
|
||||||
|
MapperService mapperService = indexServices.indexService(index).mapperService();
|
||||||
|
mapperService.addTypeListener(new DocumentTypeListener() {
|
||||||
|
@Override
|
||||||
|
public void created(String type) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(String type) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return latch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClusterHealthStatus ensureGreen() {
|
||||||
|
ClusterHealthResponse actionGet = client().admin().cluster()
|
||||||
|
.health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
|
||||||
|
assertThat(actionGet.isTimedOut(), equalTo(false));
|
||||||
|
assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||||
|
return actionGet.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,14 +22,12 @@ package org.elasticsearch.test.integration.percolator;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||||
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse;
|
|
||||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||||
import org.elasticsearch.action.count.CountResponse;
|
import org.elasticsearch.action.count.CountResponse;
|
||||||
import org.elasticsearch.action.percolate.PercolateResponse;
|
import org.elasticsearch.action.percolate.PercolateResponse;
|
||||||
import org.elasticsearch.action.percolate.PercolateSourceBuilder;
|
import org.elasticsearch.action.percolate.PercolateSourceBuilder;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.action.support.IgnoreIndices;
|
import org.elasticsearch.action.support.IgnoreIndices;
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.Requests;
|
import org.elasticsearch.client.Requests;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
|
@ -1028,59 +1026,6 @@ public class SimplePercolatorTests extends AbstractSharedClusterTest {
|
||||||
assertThat(response.getMatches(), emptyArray());
|
assertThat(response.getMatches(), emptyArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeletePercolatorType() throws Exception {
|
|
||||||
client().admin().indices().prepareCreate("test1").execute().actionGet();
|
|
||||||
client().admin().indices().prepareCreate("test2").execute().actionGet();
|
|
||||||
ensureGreen();
|
|
||||||
|
|
||||||
client().prepareIndex("test1", "_percolator", "1")
|
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
|
||||||
.execute().actionGet();
|
|
||||||
client().prepareIndex("test2", "_percolator", "1")
|
|
||||||
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
|
|
||||||
.execute().actionGet();
|
|
||||||
|
|
||||||
PercolateResponse response = client().preparePercolate()
|
|
||||||
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
|
||||||
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
|
||||||
.execute().actionGet();
|
|
||||||
assertThat(response.getCount(), equalTo(2l));
|
|
||||||
|
|
||||||
client().admin().indices().prepareDeleteMapping("test1").setType("_percolator").execute().actionGet();
|
|
||||||
percolatorTypeRemoved("test1");
|
|
||||||
response = client().preparePercolate()
|
|
||||||
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
|
||||||
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
|
||||||
.execute().actionGet();
|
|
||||||
assertNoFailures(response);
|
|
||||||
assertThat(response.getCount(), equalTo(1l));
|
|
||||||
|
|
||||||
client().admin().indices().prepareDeleteMapping("test2").setType("_percolator").execute().actionGet();
|
|
||||||
percolatorTypeRemoved("test2");
|
|
||||||
|
|
||||||
// Percolate api should return 0 matches, because all _percolate types have been removed.
|
|
||||||
response = client().preparePercolate()
|
|
||||||
.setIndices("test1", "test2").setDocumentType("type").setOnlyCount(true)
|
|
||||||
.setPercolateDoc(docBuilder().setDoc(jsonBuilder().startObject().field("field1", "b").endObject()))
|
|
||||||
.execute().actionGet();
|
|
||||||
assertNoFailures(response);
|
|
||||||
assertThat(response.getCount(), equalTo(0l));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void percolatorTypeRemoved(String index) {
|
|
||||||
my_goto: while (true) {
|
|
||||||
for (Client client : clients()) {
|
|
||||||
TypesExistsResponse existsResponse =
|
|
||||||
client.admin().indices().prepareTypesExists(index).setTypes("_percolator").execute().actionGet();
|
|
||||||
if (existsResponse.isExists()) {
|
|
||||||
continue my_goto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPercolateSizingWithQueryAndFilter() throws Exception {
|
public void testPercolateSizingWithQueryAndFilter() throws Exception {
|
||||||
client().admin().indices().prepareCreate("test").execute().actionGet();
|
client().admin().indices().prepareCreate("test").execute().actionGet();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
Loading…
Reference in New Issue