Test: testRelocationWithBusyClusterUpdateThread - use cluster state listener instead of assertBusy

This commit is contained in:
Boaz Leskes 2015-02-06 14:26:51 +01:00
parent 1b7920f202
commit 45ecb49a09
1 changed files with 12 additions and 11 deletions

View File

@ -462,9 +462,6 @@ public class RelocationTests extends ElasticsearchIntegrationTest {
assertThat(response.isTimedOut(), is(false)); assertThat(response.isTimedOut(), is(false));
ClusterService clusterService = internalCluster().getInstance(ClusterService.class, node1);
client().admin().indices().prepareCreate(indexName) client().admin().indices().prepareCreate(indexName)
.setSettings( .setSettings(
ImmutableSettings.builder() ImmutableSettings.builder()
@ -486,8 +483,9 @@ public class RelocationTests extends ElasticsearchIntegrationTest {
final CountDownLatch allReplicasAssigned = new CountDownLatch(1); final CountDownLatch allReplicasAssigned = new CountDownLatch(1);
final CountDownLatch releaseClusterState = new CountDownLatch(1); final CountDownLatch releaseClusterState = new CountDownLatch(1);
final CountDownLatch unassignedShardsAfterReplicasAssigned = new CountDownLatch(1);
try { try {
clusterService.addLast(new ClusterStateListener() { internalCluster().getInstance(ClusterService.class, node1).addLast(new ClusterStateListener() {
@Override @Override
public void clusterChanged(ClusterChangedEvent event) { public void clusterChanged(ClusterChangedEvent event) {
if (event.state().routingNodes().hasUnassignedShards() == false) { if (event.state().routingNodes().hasUnassignedShards() == false) {
@ -501,6 +499,15 @@ public class RelocationTests extends ElasticsearchIntegrationTest {
} }
}); });
internalCluster().getInstance(ClusterService.class, master).addLast(new ClusterStateListener() {
@Override
public void clusterChanged(ClusterChangedEvent event) {
if (event.state().routingNodes().hasUnassigned() && allReplicasAssigned.getCount() == 0) {
unassignedShardsAfterReplicasAssigned.countDown();
}
}
});
logger.info("--> starting replica recovery"); logger.info("--> starting replica recovery");
// we don't expect this to be acknowledge by node1 where we block the cluster state thread // we don't expect this to be acknowledge by node1 where we block the cluster state thread
assertFalse(client().admin().indices().prepareUpdateSettings(indexName) assertFalse(client().admin().indices().prepareUpdateSettings(indexName)
@ -514,13 +521,7 @@ public class RelocationTests extends ElasticsearchIntegrationTest {
logger.info("--> waiting for node1 to process replica existence"); logger.info("--> waiting for node1 to process replica existence");
allReplicasAssigned.await(); allReplicasAssigned.await();
logger.info("--> waiting for recovery to fail"); logger.info("--> waiting for recovery to fail");
assertBusy(new Runnable() { unassignedShardsAfterReplicasAssigned.countDown();
@Override
public void run() {
ClusterHealthResponse response = client().admin().cluster().prepareHealth().get();
assertThat(response.getUnassignedShards(), equalTo(1));
}
});
} finally { } finally {
logger.info("--> releasing cluster state update thread"); logger.info("--> releasing cluster state update thread");
releaseClusterState.countDown(); releaseClusterState.countDown();