|
9 | 9 | import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; |
10 | 10 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; |
11 | 11 | import org.elasticsearch.action.delete.DeleteResponse; |
| 12 | +import org.elasticsearch.action.index.IndexResponse; |
12 | 13 | import org.elasticsearch.action.search.SearchRequest; |
13 | 14 | import org.elasticsearch.action.search.SearchResponse; |
14 | 15 | import org.elasticsearch.action.search.SearchType; |
15 | 16 | import org.elasticsearch.action.support.IndicesOptions; |
16 | 17 | import org.elasticsearch.cluster.block.ClusterBlockException; |
17 | 18 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
| 19 | +import org.elasticsearch.cluster.routing.RecoverySource; |
18 | 20 | import org.elasticsearch.common.Strings; |
19 | 21 | import org.elasticsearch.common.settings.Settings; |
20 | 22 | import org.elasticsearch.common.unit.TimeValue; |
|
27 | 29 | import org.elasticsearch.index.shard.IndexShard; |
28 | 30 | import org.elasticsearch.index.shard.IndexShardTestCase; |
29 | 31 | import org.elasticsearch.indices.IndicesService; |
| 32 | +import org.elasticsearch.indices.recovery.RecoveryState; |
30 | 33 | import org.elasticsearch.plugins.Plugin; |
31 | 34 | import org.elasticsearch.rest.RestStatus; |
32 | 35 | import org.elasticsearch.search.SearchService; |
|
49 | 52 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
50 | 53 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
51 | 54 | import static org.hamcrest.Matchers.equalTo; |
| 55 | +import static org.hamcrest.Matchers.greaterThan; |
52 | 56 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
53 | 57 | import static org.hamcrest.Matchers.is; |
| 58 | +import static org.hamcrest.Matchers.notNullValue; |
54 | 59 |
|
55 | 60 | public class FrozenIndexTests extends ESSingleNodeTestCase { |
56 | 61 |
|
@@ -372,4 +377,36 @@ public void testFreezeEmptyIndexWithTranslogOps() throws Exception { |
372 | 377 | assertAcked(new XPackClient(client()).freeze(new TransportFreezeIndexAction.FreezeRequest(indexName))); |
373 | 378 | assertIndexFrozen(indexName); |
374 | 379 | } |
| 380 | + |
| 381 | + public void testRecoveryState() throws ExecutionException, InterruptedException { |
| 382 | + final String indexName = "index_recovery_state"; |
| 383 | + createIndex(indexName, Settings.builder() |
| 384 | + .put("index.number_of_replicas", 0) |
| 385 | + .build()); |
| 386 | + |
| 387 | + final long nbDocs = randomIntBetween(0, 50); |
| 388 | + for (long i = 0; i < nbDocs; i++) { |
| 389 | + final IndexResponse indexResponse = client().prepareIndex(indexName, "_doc", Long.toString(i)).setSource("field", i).get(); |
| 390 | + assertThat(indexResponse.status(), is(RestStatus.CREATED)); |
| 391 | + } |
| 392 | + |
| 393 | + assertAcked(new XPackClient(client()).freeze(new TransportFreezeIndexAction.FreezeRequest(indexName))); |
| 394 | + assertIndexFrozen(indexName); |
| 395 | + |
| 396 | + final IndexMetaData indexMetaData = client().admin().cluster().prepareState().get().getState().metaData().index(indexName); |
| 397 | + final IndexService indexService = getInstanceFromNode(IndicesService.class).indexService(indexMetaData.getIndex()); |
| 398 | + for (int i = 0; i < indexMetaData.getNumberOfShards(); i++) { |
| 399 | + final IndexShard indexShard = indexService.getShardOrNull(i); |
| 400 | + assertThat("Shard [" + i + "] is missing for index " + indexMetaData.getIndex(), indexShard, notNullValue()); |
| 401 | + final RecoveryState recoveryState = indexShard.recoveryState(); |
| 402 | + assertThat(recoveryState.getRecoverySource(), is(RecoverySource.ExistingStoreRecoverySource.INSTANCE)); |
| 403 | + assertThat(recoveryState.getStage(), is(RecoveryState.Stage.DONE)); |
| 404 | + assertThat(recoveryState.getTargetNode(), notNullValue()); |
| 405 | + assertThat(recoveryState.getIndex().totalFileCount(), greaterThan(0)); |
| 406 | + assertThat(recoveryState.getIndex().reusedFileCount(), greaterThan(0)); |
| 407 | + assertThat(recoveryState.getTranslog().recoveredOperations(), equalTo(0)); |
| 408 | + assertThat(recoveryState.getTranslog().totalOperations(), equalTo(0)); |
| 409 | + assertThat(recoveryState.getTranslog().recoveredPercent(), equalTo(100.0f)); |
| 410 | + } |
| 411 | + } |
375 | 412 | } |
0 commit comments