Moved SimpleIndexStateTests to AbstractIntegrationTest
This commit is contained in:
parent
c6eebf0515
commit
2ca1d79530
|
@ -19,24 +19,23 @@
|
|||
|
||||
package org.elasticsearch.indices.state;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.SettingsException;
|
||||
import org.elasticsearch.indices.IndexMissingException;
|
||||
import org.elasticsearch.indices.IndexPrimaryShardNotAllocatedException;
|
||||
import org.elasticsearch.test.AbstractNodesTests;
|
||||
import org.junit.After;
|
||||
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
|
@ -46,131 +45,116 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class SimpleIndexStateTests extends AbstractNodesTests {
|
||||
public class SimpleIndexStateTests extends AbstractIntegrationTest {
|
||||
|
||||
private final ESLogger logger = Loggers.getLogger(SimpleIndexStateTests.class);
|
||||
|
||||
@After
|
||||
public void closeNodes() {
|
||||
closeAllNodes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleOpenClose() {
|
||||
logger.info("--> starting two nodes....");
|
||||
startNode("node1");
|
||||
startNode("node2");
|
||||
|
||||
logger.info("--> creating test index");
|
||||
client("node1").admin().indices().prepareCreate("test").execute().actionGet();
|
||||
createIndex("test");
|
||||
|
||||
logger.info("--> waiting for green status");
|
||||
ClusterHealthResponse health = client("node1").admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
ensureGreen();
|
||||
|
||||
ClusterStateResponse stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
|
||||
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
|
||||
assertThat(stateResponse.getState().metaData().index("test").state(), equalTo(IndexMetaData.State.OPEN));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(5));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
logger.info("--> indexing a simple document");
|
||||
client("node1").prepareIndex("test", "type1", "1").setSource("field1", "value1").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
|
||||
|
||||
logger.info("--> closing test index...");
|
||||
client("node1").admin().indices().prepareClose("test").execute().actionGet();
|
||||
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").get();
|
||||
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
|
||||
stateResponse = client().admin().cluster().prepareState().get();
|
||||
assertThat(stateResponse.getState().metaData().index("test").state(), equalTo(IndexMetaData.State.CLOSE));
|
||||
assertThat(stateResponse.getState().routingTable().index("test"), nullValue());
|
||||
|
||||
logger.info("--> testing indices status api...");
|
||||
IndicesStatusResponse indicesStatusResponse = client("node1").admin().indices().prepareStatus().execute().actionGet();
|
||||
IndicesStatusResponse indicesStatusResponse = client().admin().indices().prepareStatus().get();
|
||||
assertThat(indicesStatusResponse.getIndices().size(), equalTo(0));
|
||||
|
||||
logger.info("--> trying to index into a closed index ...");
|
||||
try {
|
||||
client("node1").prepareIndex("test", "type1", "1").setSource("field1", "value1").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
|
||||
assert false;
|
||||
} catch (ClusterBlockException e) {
|
||||
// all is well
|
||||
}
|
||||
|
||||
logger.info("--> opening index...");
|
||||
client("node1").admin().indices().prepareOpen("test").execute().actionGet();
|
||||
OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").get();
|
||||
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
logger.info("--> waiting for green status");
|
||||
health = client("node1").admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
ensureGreen();
|
||||
|
||||
stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
|
||||
stateResponse = client().admin().cluster().prepareState().get();
|
||||
assertThat(stateResponse.getState().metaData().index("test").state(), equalTo(IndexMetaData.State.OPEN));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(5));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
logger.info("--> indexing a simple document");
|
||||
client("node1").prepareIndex("test", "type1", "1").setSource("field1", "value1").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFastCloseAfterCreateDoesNotClose() {
|
||||
logger.info("--> starting two nodes....");
|
||||
startNode("node1");
|
||||
startNode("node2");
|
||||
|
||||
logger.info("--> creating test index that cannot be allocated");
|
||||
client("node1").admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()
|
||||
.put("index.routing.allocation.include.tag", "no_such_node")
|
||||
.put("index.number_of_replicas", 1).build()).execute().actionGet();
|
||||
.put("index.number_of_replicas", 1).build()).get();
|
||||
|
||||
ClusterHealthResponse health = client("node1").admin().cluster().prepareHealth("test").setWaitForNodes("2").execute().actionGet();
|
||||
ClusterHealthResponse health = client().admin().cluster().prepareHealth("test").setWaitForNodes(">=2").get();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
assertThat(health.getStatus(), equalTo(ClusterHealthStatus.RED));
|
||||
|
||||
try {
|
||||
client().admin().indices().prepareClose("test").execute().actionGet();
|
||||
Assert.fail("Exception should have been thrown");
|
||||
client().admin().indices().prepareClose("test").get();
|
||||
fail("Exception should have been thrown");
|
||||
} catch(IndexPrimaryShardNotAllocatedException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
logger.info("--> updating test index settings to allow allocation");
|
||||
client("node1").admin().indices().prepareUpdateSettings("test").setSettings(ImmutableSettings.settingsBuilder()
|
||||
.put("index.routing.allocation.include.tag", "").build()).execute().actionGet();
|
||||
client().admin().indices().prepareUpdateSettings("test").setSettings(ImmutableSettings.settingsBuilder()
|
||||
.put("index.routing.allocation.include.tag", "").build()).get();
|
||||
|
||||
logger.info("--> waiting for green status");
|
||||
health = client("node1").admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
ensureGreen();
|
||||
|
||||
ClusterStateResponse stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
|
||||
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
|
||||
assertThat(stateResponse.getState().metaData().index("test").state(), equalTo(IndexMetaData.State.OPEN));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shards().size(), equalTo(5));
|
||||
assertThat(stateResponse.getState().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
|
||||
|
||||
logger.info("--> indexing a simple document");
|
||||
client("node1").prepareIndex("test", "type1", "1").setSource("field1", "value1").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsistencyAfterIndexCreationFailure() {
|
||||
logger.info("--> starting one node....");
|
||||
startNode("node1");
|
||||
|
||||
logger.info("--> deleting test index....");
|
||||
try {
|
||||
client("node1").admin().indices().prepareDelete("test").execute().actionGet();
|
||||
client().admin().indices().prepareDelete("test").get();
|
||||
} catch (IndexMissingException ex) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
logger.info("--> creating test index with invalid settings ");
|
||||
try {
|
||||
client("node1").admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", "bad")).execute().actionGet();
|
||||
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", "bad")).get();
|
||||
assert false;
|
||||
} catch (SettingsException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
logger.info("--> creating test index with valid settings ");
|
||||
CreateIndexResponse response = client("node1").admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", 1)).execute().actionGet();
|
||||
CreateIndexResponse response = client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("number_of_shards", 1)).get();
|
||||
assertThat(response.isAcknowledged(), equalTo(true));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue