|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.elasticsearch.snapshots; |
| 20 | + |
| 21 | +import org.elasticsearch.Version; |
| 22 | +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; |
| 23 | +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; |
| 24 | +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; |
| 25 | +import org.elasticsearch.client.Client; |
| 26 | +import org.elasticsearch.common.settings.Settings; |
| 27 | + |
| 28 | +import java.util.List; |
| 29 | + |
| 30 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 31 | +import static org.hamcrest.Matchers.equalTo; |
| 32 | +import static org.hamcrest.Matchers.greaterThan; |
| 33 | + |
| 34 | +public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase { |
| 35 | + |
| 36 | + public void testStatusApiConsistency() { |
| 37 | + Client client = client(); |
| 38 | + |
| 39 | + logger.info("--> creating repository"); |
| 40 | + assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings( |
| 41 | + Settings.builder().put("location", randomRepoPath()).build())); |
| 42 | + |
| 43 | + createIndex("test-idx-1", "test-idx-2", "test-idx-3"); |
| 44 | + ensureGreen(); |
| 45 | + |
| 46 | + logger.info("--> indexing some data"); |
| 47 | + for (int i = 0; i < 100; i++) { |
| 48 | + index("test-idx-1", "_doc", Integer.toString(i), "foo", "bar" + i); |
| 49 | + index("test-idx-2", "_doc", Integer.toString(i), "foo", "baz" + i); |
| 50 | + index("test-idx-3", "_doc", Integer.toString(i), "foo", "baz" + i); |
| 51 | + } |
| 52 | + refresh(); |
| 53 | + |
| 54 | + logger.info("--> snapshot"); |
| 55 | + CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") |
| 56 | + .setWaitForCompletion(true).get(); |
| 57 | + assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
| 58 | + assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), |
| 59 | + equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); |
| 60 | + |
| 61 | + List<SnapshotInfo> snapshotInfos = |
| 62 | + client.admin().cluster().prepareGetSnapshots("test-repo").get().getSnapshots("test-repo"); |
| 63 | + assertThat(snapshotInfos.size(), equalTo(1)); |
| 64 | + SnapshotInfo snapshotInfo = snapshotInfos.get(0); |
| 65 | + assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); |
| 66 | + assertThat(snapshotInfo.version(), equalTo(Version.CURRENT)); |
| 67 | + |
| 68 | + final List<SnapshotStatus> snapshotStatus = client.admin().cluster().snapshotsStatus( |
| 69 | + new SnapshotsStatusRequest("test-repo", new String[]{"test-snap"})).actionGet().getSnapshots(); |
| 70 | + assertThat(snapshotStatus.size(), equalTo(1)); |
| 71 | + final SnapshotStatus snStatus = snapshotStatus.get(0); |
| 72 | + assertEquals(snStatus.getStats().getStartTime(), snapshotInfo.startTime()); |
| 73 | + assertEquals(snStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime()); |
| 74 | + } |
| 75 | +} |
0 commit comments