use of org.elasticsearch.index.Index in project elasticsearch by elastic.
the class MetaDataDeleteIndexServiceTests method testDeleteMissing.
public void testDeleteMissing() {
Index index = new Index("missing", "doesn't matter");
ClusterState state = ClusterState.builder(ClusterName.DEFAULT).build();
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> service.deleteIndices(state, singleton(index)));
assertEquals(index, e.getIndex());
}
use of org.elasticsearch.index.Index in project elasticsearch by elastic.
the class AckIT method testClusterRerouteAcknowledgement.
public void testClusterRerouteAcknowledgement() throws InterruptedException {
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS)).put(SETTING_NUMBER_OF_REPLICAS, 0)));
ensureGreen();
MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
final ShardId commandShard = new ShardId(index, moveAllocationCommand.shardId());
assertAcked(client().admin().cluster().prepareReroute().add(moveAllocationCommand));
for (Client client : clients()) {
ClusterState clusterState = getLocalClusterState(client);
for (ShardRouting shardRouting : clusterState.getRoutingNodes().node(moveAllocationCommand.fromNode())) {
//if the shard that we wanted to move is still on the same node, it must be relocating
if (shardRouting.shardId().equals(commandShard)) {
assertThat(shardRouting.relocating(), equalTo(true));
}
}
boolean found = false;
for (ShardRouting shardRouting : clusterState.getRoutingNodes().node(moveAllocationCommand.toNode())) {
if (shardRouting.shardId().equals(commandShard)) {
assertThat(shardRouting.state(), anyOf(equalTo(ShardRoutingState.INITIALIZING), equalTo(ShardRoutingState.STARTED)));
found = true;
break;
}
}
assertThat(found, equalTo(true));
}
}
use of org.elasticsearch.index.Index in project elasticsearch by elastic.
the class AckIT method testClusterRerouteAcknowledgementDryRun.
public void testClusterRerouteAcknowledgementDryRun() throws InterruptedException {
client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, between(cluster().numDataNodes(), DEFAULT_MAX_NUM_SHARDS)).put(SETTING_NUMBER_OF_REPLICAS, 0)).get();
ensureGreen();
MoveAllocationCommand moveAllocationCommand = getAllocationCommand();
final Index index = client().admin().cluster().prepareState().get().getState().metaData().index("test").getIndex();
final ShardId commandShard = new ShardId(index, moveAllocationCommand.shardId());
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.
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
boolean found = false;
for (ShardRouting shardRouting : clusterStateResponse.getState().getRoutingNodes().node(moveAllocationCommand.fromNode())) {
//the shard that we wanted to move is still on the same node, as we had dryRun flag
if (shardRouting.shardId().equals(commandShard)) {
assertThat(shardRouting.started(), equalTo(true));
found = true;
break;
}
}
assertThat(found, equalTo(true));
for (ShardRouting shardRouting : clusterStateResponse.getState().getRoutingNodes().node(moveAllocationCommand.toNode())) {
if (shardRouting.shardId().equals(commandShard)) {
fail("shard [" + shardRouting + "] shouldn't be on node [" + moveAllocationCommand.toString() + "]");
}
}
}
use of org.elasticsearch.index.Index in project elasticsearch by elastic.
the class IndexGraveyardTests method testAddTombstones.
public void testAddTombstones() {
final IndexGraveyard graveyard1 = createRandom();
final IndexGraveyard.Builder graveyardBuidler = IndexGraveyard.builder(graveyard1);
final int numAdds = randomIntBetween(0, 4);
for (int j = 0; j < numAdds; j++) {
graveyardBuidler.addTombstone(new Index("nidx-" + j, UUIDs.randomBase64UUID()));
}
final IndexGraveyard graveyard2 = graveyardBuidler.build();
if (numAdds == 0) {
assertThat(graveyard2, equalTo(graveyard1));
} else {
assertThat(graveyard2, not(graveyard1));
assertThat(graveyard1.getTombstones().size(), lessThan(graveyard2.getTombstones().size()));
assertThat(Collections.indexOfSubList(graveyard2.getTombstones(), graveyard1.getTombstones()), equalTo(0));
}
}
use of org.elasticsearch.index.Index in project elasticsearch by elastic.
the class IndexGraveyardTests method createRandom.
public static IndexGraveyard createRandom() {
final IndexGraveyard.Builder graveyard = IndexGraveyard.builder();
final int numTombstones = randomIntBetween(0, 4);
for (int i = 0; i < numTombstones; i++) {
graveyard.addTombstone(new Index("idx-" + i, UUIDs.randomBase64UUID()));
}
return graveyard.build();
}
Aggregations