|
8 | 8 | import org.elasticsearch.action.ActionListener;
|
9 | 9 | import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
10 | 10 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
| 11 | +import org.elasticsearch.action.delete.DeleteResponse; |
11 | 12 | import org.elasticsearch.action.search.SearchResponse;
|
12 | 13 | import org.elasticsearch.action.search.SearchType;
|
13 | 14 | import org.elasticsearch.action.support.IndicesOptions;
|
|
26 | 27 | import org.elasticsearch.index.shard.IndexShardTestCase;
|
27 | 28 | import org.elasticsearch.indices.IndicesService;
|
28 | 29 | import org.elasticsearch.plugins.Plugin;
|
| 30 | +import org.elasticsearch.rest.RestStatus; |
29 | 31 | import org.elasticsearch.search.SearchService;
|
30 | 32 | import org.elasticsearch.search.builder.SearchSourceBuilder;
|
31 | 33 | import org.elasticsearch.search.internal.AliasFilter;
|
|
46 | 48 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
47 | 49 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
48 | 50 | import static org.hamcrest.Matchers.equalTo;
|
| 51 | +import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 52 | +import static org.hamcrest.Matchers.is; |
49 | 53 |
|
50 | 54 | public class FrozenIndexTests extends ESSingleNodeTestCase {
|
51 | 55 |
|
@@ -340,4 +344,30 @@ public void testFreezeIndexIncreasesIndexSettingsVersion() throws ExecutionExcep
|
340 | 344 | assertThat(client().admin().cluster().prepareState().get().getState().metaData().index(index).getSettingsVersion(),
|
341 | 345 | equalTo(settingsVersion + 1));
|
342 | 346 | }
|
| 347 | + |
| 348 | + public void testFreezeEmptyIndexWithTranslogOps() throws Exception { |
| 349 | + final String indexName = "empty"; |
| 350 | + createIndex(indexName, Settings.builder() |
| 351 | + .put("index.number_of_shards", 1) |
| 352 | + .put("index.number_of_replicas", 0) |
| 353 | + .put("index.refresh_interval", TimeValue.MINUS_ONE) |
| 354 | + .build()); |
| 355 | + |
| 356 | + final long nbNoOps = randomIntBetween(1, 10); |
| 357 | + for (long i = 0; i < nbNoOps; i++) { |
| 358 | + final DeleteResponse deleteResponse = client().prepareDelete(indexName, "_doc", Long.toString(i)).get(); |
| 359 | + assertThat(deleteResponse.status(), is(RestStatus.NOT_FOUND)); |
| 360 | + } |
| 361 | + |
| 362 | + final IndicesService indicesService = getInstanceFromNode(IndicesService.class); |
| 363 | + assertBusy(() -> { |
| 364 | + final Index index = client().admin().cluster().prepareState().get().getState().metaData().index(indexName).getIndex(); |
| 365 | + final IndexService indexService = indicesService.indexService(index); |
| 366 | + assertThat(indexService.hasShard(0), is(true)); |
| 367 | + assertThat(indexService.getShard(0).getGlobalCheckpoint(), greaterThanOrEqualTo(nbNoOps - 1L)); |
| 368 | + }); |
| 369 | + |
| 370 | + assertAcked(new XPackClient(client()).freeze(new TransportFreezeIndexAction.FreezeRequest(indexName))); |
| 371 | + assertIndexFrozen(indexName); |
| 372 | + } |
343 | 373 | }
|
0 commit comments