Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Percolator doesn't work correctly after index recreation, closes #837.
- Loading branch information
Showing
2 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
.../src/test/java/org/elasticsearch/test/integration/percolator/RecoveryPercolatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Licensed to Elastic Search and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Elastic Search licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
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.percolate.PercolateResponse; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.gateway.Gateway; | ||
import org.elasticsearch.node.internal.InternalNode; | ||
import org.elasticsearch.test.integration.AbstractNodesTests; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.elasticsearch.client.Requests.*; | ||
import static org.elasticsearch.common.settings.ImmutableSettings.*; | ||
import static org.elasticsearch.common.xcontent.XContentFactory.*; | ||
import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; | ||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@Test | ||
public class RecoveryPercolatorTests extends AbstractNodesTests { | ||
|
||
@AfterMethod public void cleanAndCloseNodes() throws Exception { | ||
for (int i = 0; i < 10; i++) { | ||
if (node("node" + i) != null) { | ||
node("node" + i).stop(); | ||
// since we store (by default) the index snapshot under the gateway, resetting it will reset the index data as well | ||
if (((InternalNode) node("node" + i)).injector().getInstance(NodeEnvironment.class).hasNodeFile()) { | ||
((InternalNode) node("node" + i)).injector().getInstance(Gateway.class).reset(); | ||
} | ||
} | ||
} | ||
closeAllNodes(); | ||
} | ||
|
||
@Test public void testRestartNodePercolator1() throws Exception { | ||
logger.info("--> cleaning nodes"); | ||
buildNode("node1", settingsBuilder().put("gateway.type", "local")); | ||
cleanAndCloseNodes(); | ||
|
||
logger.info("--> starting 1 nodes"); | ||
startNode("node1", settingsBuilder().put("gateway.type", "local")); | ||
|
||
Client client = client("node1"); | ||
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); | ||
|
||
logger.info("--> register a query"); | ||
client.prepareIndex("_percolator", "test", "kuku") | ||
.setSource(jsonBuilder().startObject() | ||
.field("color", "blue") | ||
.field("query", termQuery("field1", "value1")) | ||
.endObject()) | ||
.setRefresh(true) | ||
.execute().actionGet(); | ||
|
||
PercolateResponse percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") | ||
.field("field1", "value1") | ||
.endObject().endObject()) | ||
.execute().actionGet(); | ||
assertThat(percolate.matches().size(), equalTo(1)); | ||
|
||
client.close(); | ||
closeNode("node1"); | ||
|
||
startNode("node1", settingsBuilder().put("gateway.type", "local").build()); | ||
client = client("node1"); | ||
|
||
logger.info("Running Cluster Health (wait for the shards to startup)"); | ||
ClusterHealthResponse clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); | ||
logger.info("Done Cluster Health, status " + clusterHealth.status()); | ||
assertThat(clusterHealth.timedOut(), equalTo(false)); | ||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); | ||
|
||
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") | ||
.field("field1", "value1") | ||
.endObject().endObject()) | ||
.execute().actionGet(); | ||
assertThat(percolate.matches().size(), equalTo(1)); | ||
} | ||
|
||
@Test public void testRestartNodePercolator2() throws Exception { | ||
logger.info("--> cleaning nodes"); | ||
buildNode("node1", settingsBuilder().put("gateway.type", "local")); | ||
cleanAndCloseNodes(); | ||
|
||
logger.info("--> starting 1 nodes"); | ||
startNode("node1", settingsBuilder().put("gateway.type", "local")); | ||
|
||
Client client = client("node1"); | ||
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); | ||
|
||
logger.info("--> register a query"); | ||
client.prepareIndex("_percolator", "test", "kuku") | ||
.setSource(jsonBuilder().startObject() | ||
.field("color", "blue") | ||
.field("query", termQuery("field1", "value1")) | ||
.endObject()) | ||
.setRefresh(true) | ||
.execute().actionGet(); | ||
|
||
assertThat(client.prepareCount("_percolator").setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(1l)); | ||
|
||
PercolateResponse percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") | ||
.field("field1", "value1") | ||
.endObject().endObject()) | ||
.execute().actionGet(); | ||
assertThat(percolate.matches().size(), equalTo(1)); | ||
|
||
client.close(); | ||
closeNode("node1"); | ||
|
||
startNode("node1", settingsBuilder().put("gateway.type", "local").build()); | ||
client = client("node1"); | ||
|
||
logger.info("Running Cluster Health (wait for the shards to startup)"); | ||
ClusterHealthResponse clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); | ||
logger.info("Done Cluster Health, status " + clusterHealth.status()); | ||
assertThat(clusterHealth.timedOut(), equalTo(false)); | ||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); | ||
|
||
assertThat(client.prepareCount("_percolator").setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(1l)); | ||
|
||
client.admin().indices().prepareDelete("test").execute().actionGet(); | ||
client.admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); | ||
clusterHealth = client("node1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet(); | ||
logger.info("Done Cluster Health, status " + clusterHealth.status()); | ||
assertThat(clusterHealth.timedOut(), equalTo(false)); | ||
assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW)); | ||
|
||
assertThat(client.prepareCount("_percolator").setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(0l)); | ||
|
||
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") | ||
.field("field1", "value1") | ||
.endObject().endObject()) | ||
.execute().actionGet(); | ||
assertThat(percolate.matches().size(), equalTo(0)); | ||
|
||
logger.info("--> register a query"); | ||
client.prepareIndex("_percolator", "test", "kuku") | ||
.setSource(jsonBuilder().startObject() | ||
.field("color", "blue") | ||
.field("query", termQuery("field1", "value1")) | ||
.endObject()) | ||
.setRefresh(true) | ||
.execute().actionGet(); | ||
|
||
assertThat(client.prepareCount("_percolator").setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(1l)); | ||
|
||
percolate = client.preparePercolate("test", "type1").setSource(jsonBuilder().startObject().startObject("doc") | ||
.field("field1", "value1") | ||
.endObject().endObject()) | ||
.execute().actionGet(); | ||
assertThat(percolate.matches().size(), equalTo(1)); | ||
} | ||
} |