AckTests: more assertAcked and added common method to retrieve local cluster state

This commit is contained in:
Luca Cavanna 2013-11-21 22:59:48 +01:00
parent 5cd780846b
commit 22852d8040

View File

@ -31,7 +31,6 @@ import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRespon
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse; import org.elasticsearch.action.admin.indices.settings.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse;
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse;
import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse; import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -69,13 +68,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
public void testUpdateSettingsAcknowledgement() { public void testUpdateSettingsAcknowledgement() {
createIndex("test"); createIndex("test");
UpdateSettingsResponse updateSettingsResponse = client().admin().indices().prepareUpdateSettings("test") assertAcked(client().admin().indices().prepareUpdateSettings("test")
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)).get(); .setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)));
assertThat(updateSettingsResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).get(); String refreshInterval = getLocalClusterState(client).metaData().index("test").settings().get("index.refresh_interval");
String refreshInterval = clusterStateResponse.getState().metaData().index("test").settings().get("index.refresh_interval");
assertThat(refreshInterval, equalTo("9999")); assertThat(refreshInterval, equalTo("9999"));
} }
} }
@ -94,10 +91,8 @@ public class AckTests extends ElasticsearchIntegrationTest {
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
PutWarmerResponse putWarmerResponse = client().admin().indices().preparePutWarmer("custom_warmer") assertAcked(client().admin().indices().preparePutWarmer("custom_warmer")
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())) .setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())));
.get();
assertThat(putWarmerResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get(); GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get();
@ -125,13 +120,10 @@ public class AckTests extends ElasticsearchIntegrationTest {
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
PutWarmerResponse putWarmerResponse = client().admin().indices().preparePutWarmer("custom_warmer") assertAcked(client().admin().indices().preparePutWarmer("custom_warmer")
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())) .setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())));
.get();
assertThat(putWarmerResponse.isAcknowledged(), equalTo(true));
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer").get(); assertAcked(client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer"));
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get(); GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get();
@ -161,8 +153,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").addTypes("type1").get(); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").addTypes("type1").get();
assertThat(getMappingsResponse.mappings().get("test").get("type1"), notNullValue()); assertThat(getMappingsResponse.mappings().get("test").get("type1"), notNullValue());
DeleteMappingResponse deleteMappingResponse = client().admin().indices().prepareDeleteMapping("test").setType("type1").get(); assertAcked(client().admin().indices().prepareDeleteMapping("test").setType("type1"));
assertThat(deleteMappingResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
getMappingsResponse = client.admin().indices().prepareGetMappings("test").addTypes("type1").setLocal(true).get(); getMappingsResponse = client.admin().indices().prepareGetMappings("test").addTypes("type1").setLocal(true).get();
@ -193,12 +184,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
MoveAllocationCommand moveAllocationCommand = getAllocationCommand(); MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
ClusterRerouteResponse clusterRerouteResponse = client().admin().cluster().prepareReroute().add(moveAllocationCommand).get(); assertAcked(client().admin().cluster().prepareReroute().add(moveAllocationCommand));
assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).get(); ClusterState clusterState = getLocalClusterState(client);
RoutingNode routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.fromNode()); RoutingNode routingNode = clusterState.routingNodes().nodesToShards().get(moveAllocationCommand.fromNode());
for (MutableShardRouting mutableShardRouting : routingNode) { for (MutableShardRouting mutableShardRouting : routingNode) {
//if the shard that we wanted to move is still on the same node, it must be relocating //if the shard that we wanted to move is still on the same node, it must be relocating
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) { if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
@ -207,7 +197,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
} }
routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.toNode()); routingNode = clusterState.routingNodes().nodesToShards().get(moveAllocationCommand.toNode());
boolean found = false; boolean found = false;
for (MutableShardRouting mutableShardRouting : routingNode) { for (MutableShardRouting mutableShardRouting : routingNode) {
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) { if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
@ -246,8 +236,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
MoveAllocationCommand moveAllocationCommand = getAllocationCommand(); MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
ClusterRerouteResponse clusterRerouteResponse = client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand).get(); assertAcked(client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand));
assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
//testing only on master with the latest cluster state as we didn't make any change thus we cannot guarantee that //testing only on master with the latest cluster state as we didn't make any change thus we cannot guarantee that
//all nodes hold the same cluster state version. We only know there was no need to change anything, thus no need for ack on this update. //all nodes hold the same cluster state version. We only know there was no need to change anything, thus no need for ack on this update.
@ -335,11 +324,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
ClusterUpdateSettingsResponse clusterUpdateSettingsResponse = client().admin().cluster().prepareUpdateSettings() ClusterUpdateSettingsResponse clusterUpdateSettingsResponse = client().admin().cluster().prepareUpdateSettings()
.setTransientSettings(settingsBuilder().put("cluster.routing.allocation.exclude._id", excludedNodeId)).get(); .setTransientSettings(settingsBuilder().put("cluster.routing.allocation.exclude._id", excludedNodeId)).get();
assertThat(clusterUpdateSettingsResponse.isAcknowledged(), equalTo(true)); assertAcked(clusterUpdateSettingsResponse);
assertThat(clusterUpdateSettingsResponse.getTransientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId)); assertThat(clusterUpdateSettingsResponse.getTransientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId));
for (Client client : clients()) { for (Client client : clients()) {
ClusterState clusterState = client.admin().cluster().prepareState().setLocal(true).get().getState(); ClusterState clusterState = getLocalClusterState(client);
assertThat(clusterState.routingNodes().metaData().transientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId)); assertThat(clusterState.routingNodes().metaData().transientSettings().get("cluster.routing.allocation.exclude._id"), equalTo(excludedNodeId));
for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) { for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
@ -401,8 +390,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
assertAcked(client().admin().indices().prepareAliases().addAlias("test", "alias")); assertAcked(client().admin().indices().prepareAliases().addAlias("test", "alias"));
for (Client client : clients()) { for (Client client : clients()) {
ClusterState clusterState = client.admin().cluster().prepareState().setLocal(true).get().getState(); AliasMetaData aliasMetaData = getLocalClusterState(client).metaData().aliases().get("alias").get("test");
AliasMetaData aliasMetaData = clusterState.metaData().aliases().get("alias").get("test");
assertThat(aliasMetaData.alias(), equalTo("alias")); assertThat(aliasMetaData.alias(), equalTo("alias"));
} }
} }
@ -420,12 +408,10 @@ public class AckTests extends ElasticsearchIntegrationTest {
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet(); assertAcked(client().admin().indices().prepareClose("test"));
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).execute().actionGet(); IndexMetaData indexMetaData = getLocalClusterState(client).metaData().indices().get("test");
IndexMetaData indexMetaData = clusterStateResponse.getState().metaData().indices().get("test");
assertThat(indexMetaData.getState(), equalTo(IndexMetaData.State.CLOSE)); assertThat(indexMetaData.getState(), equalTo(IndexMetaData.State.CLOSE));
} }
} }
@ -444,15 +430,12 @@ public class AckTests extends ElasticsearchIntegrationTest {
createIndex("test"); createIndex("test");
ensureGreen(); ensureGreen();
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet(); assertAcked(client().admin().indices().prepareClose("test"));
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
OpenIndexResponse openIndexResponse= client().admin().indices().prepareOpen("test").execute().actionGet(); assertAcked(client().admin().indices().prepareOpen("test"));
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) { for (Client client : clients()) {
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).execute().actionGet(); IndexMetaData indexMetaData = getLocalClusterState(client).metaData().indices().get("test");
IndexMetaData indexMetaData = clusterStateResponse.getState().metaData().indices().get("test");
assertThat(indexMetaData.getState(), equalTo(IndexMetaData.State.OPEN)); assertThat(indexMetaData.getState(), equalTo(IndexMetaData.State.OPEN));
} }
} }
@ -468,4 +451,8 @@ public class AckTests extends ElasticsearchIntegrationTest {
OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").setTimeout("0s").get(); OpenIndexResponse openIndexResponse = client().admin().indices().prepareOpen("test").setTimeout("0s").get();
assertThat(openIndexResponse.isAcknowledged(), equalTo(false)); assertThat(openIndexResponse.isAcknowledged(), equalTo(false));
} }
private static ClusterState getLocalClusterState(Client client) {
return client.admin().cluster().prepareState().setLocal(true).get().getState();
}
} }