AckTests: more assertAcked and added common method to retrieve local cluster state
This commit is contained in:
parent
5cd780846b
commit
22852d8040
|
@ -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.open.OpenIndexResponse;
|
||||
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.put.PutWarmerResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
@ -69,13 +68,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
public void testUpdateSettingsAcknowledgement() {
|
||||
createIndex("test");
|
||||
|
||||
UpdateSettingsResponse updateSettingsResponse = client().admin().indices().prepareUpdateSettings("test")
|
||||
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)).get();
|
||||
assertThat(updateSettingsResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareUpdateSettings("test")
|
||||
.setSettings(ImmutableSettings.builder().put("refresh_interval", 9999)));
|
||||
|
||||
for (Client client : clients()) {
|
||||
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).get();
|
||||
String refreshInterval = clusterStateResponse.getState().metaData().index("test").settings().get("index.refresh_interval");
|
||||
String refreshInterval = getLocalClusterState(client).metaData().index("test").settings().get("index.refresh_interval");
|
||||
assertThat(refreshInterval, equalTo("9999"));
|
||||
}
|
||||
}
|
||||
|
@ -94,10 +91,8 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
PutWarmerResponse putWarmerResponse = client().admin().indices().preparePutWarmer("custom_warmer")
|
||||
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery()))
|
||||
.get();
|
||||
assertThat(putWarmerResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().preparePutWarmer("custom_warmer")
|
||||
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())));
|
||||
|
||||
for (Client client : clients()) {
|
||||
GetWarmersResponse getWarmersResponse = client.admin().indices().prepareGetWarmers().setLocal(true).get();
|
||||
|
@ -125,13 +120,10 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
PutWarmerResponse putWarmerResponse = client().admin().indices().preparePutWarmer("custom_warmer")
|
||||
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery()))
|
||||
.get();
|
||||
assertThat(putWarmerResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().preparePutWarmer("custom_warmer")
|
||||
.setSearchRequest(client().prepareSearch("test").setTypes("test").setQuery(QueryBuilders.matchAllQuery())));
|
||||
|
||||
DeleteWarmerResponse deleteWarmerResponse = client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer").get();
|
||||
assertThat(deleteWarmerResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareDeleteWarmer().setIndices("test").setName("custom_warmer"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
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();
|
||||
assertThat(getMappingsResponse.mappings().get("test").get("type1"), notNullValue());
|
||||
|
||||
DeleteMappingResponse deleteMappingResponse = client().admin().indices().prepareDeleteMapping("test").setType("type1").get();
|
||||
assertThat(deleteMappingResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareDeleteMapping("test").setType("type1"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
getMappingsResponse = client.admin().indices().prepareGetMappings("test").addTypes("type1").setLocal(true).get();
|
||||
|
@ -193,12 +184,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
|
||||
|
||||
ClusterRerouteResponse clusterRerouteResponse = client().admin().cluster().prepareReroute().add(moveAllocationCommand).get();
|
||||
assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().cluster().prepareReroute().add(moveAllocationCommand));
|
||||
|
||||
for (Client client : clients()) {
|
||||
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).get();
|
||||
RoutingNode routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.fromNode());
|
||||
ClusterState clusterState = getLocalClusterState(client);
|
||||
RoutingNode routingNode = clusterState.routingNodes().nodesToShards().get(moveAllocationCommand.fromNode());
|
||||
for (MutableShardRouting mutableShardRouting : routingNode) {
|
||||
//if the shard that we wanted to move is still on the same node, it must be relocating
|
||||
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;
|
||||
for (MutableShardRouting mutableShardRouting : routingNode) {
|
||||
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
|
||||
|
@ -246,8 +236,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
|
||||
|
||||
ClusterRerouteResponse clusterRerouteResponse = client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand).get();
|
||||
assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand));
|
||||
|
||||
//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.
|
||||
|
@ -335,11 +324,11 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
ClusterUpdateSettingsResponse clusterUpdateSettingsResponse = client().admin().cluster().prepareUpdateSettings()
|
||||
.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));
|
||||
|
||||
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));
|
||||
for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
|
||||
for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
|
||||
|
@ -401,8 +390,7 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
assertAcked(client().admin().indices().prepareAliases().addAlias("test", "alias"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().setLocal(true).get().getState();
|
||||
AliasMetaData aliasMetaData = clusterState.metaData().aliases().get("alias").get("test");
|
||||
AliasMetaData aliasMetaData = getLocalClusterState(client).metaData().aliases().get("alias").get("test");
|
||||
assertThat(aliasMetaData.alias(), equalTo("alias"));
|
||||
}
|
||||
}
|
||||
|
@ -420,12 +408,10 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet();
|
||||
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareClose("test"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).execute().actionGet();
|
||||
IndexMetaData indexMetaData = clusterStateResponse.getState().metaData().indices().get("test");
|
||||
IndexMetaData indexMetaData = getLocalClusterState(client).metaData().indices().get("test");
|
||||
assertThat(indexMetaData.getState(), equalTo(IndexMetaData.State.CLOSE));
|
||||
}
|
||||
}
|
||||
|
@ -444,15 +430,12 @@ public class AckTests extends ElasticsearchIntegrationTest {
|
|||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test").execute().actionGet();
|
||||
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareClose("test"));
|
||||
|
||||
OpenIndexResponse openIndexResponse= client().admin().indices().prepareOpen("test").execute().actionGet();
|
||||
assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
|
||||
assertAcked(client().admin().indices().prepareOpen("test"));
|
||||
|
||||
for (Client client : clients()) {
|
||||
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).execute().actionGet();
|
||||
IndexMetaData indexMetaData = clusterStateResponse.getState().metaData().indices().get("test");
|
||||
IndexMetaData indexMetaData = getLocalClusterState(client).metaData().indices().get("test");
|
||||
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();
|
||||
assertThat(openIndexResponse.isAcknowledged(), equalTo(false));
|
||||
}
|
||||
|
||||
private static ClusterState getLocalClusterState(Client client) {
|
||||
return client.admin().cluster().prepareState().setLocal(true).get().getState();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue