From 17cba798e636d9a9d5117b513d71bb29fea1107f Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 11 Nov 2010 14:08:58 +0200 Subject: [PATCH] add double restart test for local gateway --- .../SimpleRecoveryLocalGatewayTests.java | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java index ee997414bb5..d46a95ad0dc 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java @@ -51,7 +51,60 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests { closeAllNodes(); } - @Test public void testSingleNode() throws Exception { + @Test public void testSingleNodeNoFlush() throws Exception { + buildNode("node1", settingsBuilder().put("gateway.type", "local").build()); + cleanAndCloseNodes(); + + Node node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").put("index.number_of_shards", 1).build()); + node1.client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").field("num", 1).endObject()).execute().actionGet(); + node1.client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field", "value2").field("num", 2).endObject()).execute().actionGet(); + + node1.client().admin().indices().prepareRefresh().execute().actionGet(); + for (int i = 0; i < 10; i++) { + assertThat(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(2l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value1")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value2")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 1)).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 2)).execute().actionGet().count(), equalTo(1l)); + } + + closeNode("node1"); + node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build()); + + 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)); + + for (int i = 0; i < 10; i++) { + assertThat(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(2l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value1")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value2")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 1)).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 2)).execute().actionGet().count(), equalTo(1l)); + } + + closeNode("node1"); + node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build()); + + logger.info("Running Cluster Health (wait for the shards to startup)"); + 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)); + + for (int i = 0; i < 10; i++) { + assertThat(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(2l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value1")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("field", "value2")).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 1)).execute().actionGet().count(), equalTo(1l)); + assertThat(node1.client().prepareCount().setQuery(termQuery("num", 2)).execute().actionGet().count(), equalTo(1l)); + } + } + + + @Test public void testSingleNodeWithFlush() throws Exception { buildNode("node1", settingsBuilder().put("gateway.type", "local").build()); cleanAndCloseNodes(); @@ -75,6 +128,19 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests { for (int i = 0; i < 10; i++) { assertThat(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(2l)); } + + closeNode("node1"); + node1 = startNode("node1", settingsBuilder().put("gateway.type", "local").build()); + + logger.info("Running Cluster Health (wait for the shards to startup)"); + 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)); + + for (int i = 0; i < 10; i++) { + assertThat(node1.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().count(), equalTo(2l)); + } } @Test public void testTwoNodeFirstNodeCleared() throws Exception {