Improve shardsCleanup test
When startNode exits there is no guarantee that shard cleanup is finished because the cleanup operation is performed on another thread and startNode doesn't wait for it to complete. Therefore we might need to wait for the shard to disappear.
This commit is contained in:
parent
e32efba3d8
commit
6a01e7882c
|
@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.indices.store;
|
|||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.NodeEnvironment;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.node.internal.InternalNode;
|
||||
|
@ -64,7 +65,7 @@ public class IndicesStoreTests extends AbstractNodesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shardsCleanup() {
|
||||
public void shardsCleanup() throws Exception {
|
||||
try {
|
||||
client1.admin().indices().prepareDelete("test").execute().actionGet();
|
||||
} catch (Exception ex) {
|
||||
|
@ -88,7 +89,7 @@ public class IndicesStoreTests extends AbstractNodesTests {
|
|||
startNode("server3");
|
||||
|
||||
logger.info("--> making sure that shard is not allocated on server3");
|
||||
assertThat(shardDirectory("server3", "test", 0).exists(), equalTo(false));
|
||||
assertThat(waitForShardDeletion(TimeValue.timeValueSeconds(1), "server3", "test", 0), equalTo(false));
|
||||
|
||||
File server2Shard = shardDirectory("server2", "test", 0);
|
||||
logger.info("--> stopping node server2");
|
||||
|
@ -113,8 +114,8 @@ public class IndicesStoreTests extends AbstractNodesTests {
|
|||
|
||||
logger.info("--> making sure that shard and it's replica are allocated on server1 and server3 but not on server2");
|
||||
assertThat(shardDirectory("server1", "test", 0).exists(), equalTo(true));
|
||||
assertThat(shardDirectory("server2", "test", 0).exists(), equalTo(false));
|
||||
assertThat(shardDirectory("server3", "test", 0).exists(), equalTo(true));
|
||||
assertThat(waitForShardDeletion(TimeValue.timeValueSeconds(1), "server2", "test", 0), equalTo(false));
|
||||
}
|
||||
|
||||
private File shardDirectory(String server, String index, int shard) {
|
||||
|
@ -123,5 +124,15 @@ public class IndicesStoreTests extends AbstractNodesTests {
|
|||
return env.shardLocations(new ShardId(index, shard))[0];
|
||||
}
|
||||
|
||||
private boolean waitForShardDeletion(TimeValue timeout, String server, String index, int shard) throws InterruptedException {
|
||||
long start = System.currentTimeMillis();
|
||||
boolean shardExists;
|
||||
do {
|
||||
shardExists = shardDirectory(server, index, shard).exists();
|
||||
}
|
||||
while (shardExists && (System.currentTimeMillis() - start) < timeout.millis());
|
||||
return shardExists;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue