|
| 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 | + |
| 20 | +package org.elasticsearch.snapshots; |
| 21 | + |
| 22 | +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; |
| 23 | +import org.elasticsearch.common.settings.Settings; |
| 24 | +import org.elasticsearch.common.unit.ByteSizeUnit; |
| 25 | +import org.elasticsearch.common.unit.TimeValue; |
| 26 | +import org.elasticsearch.plugins.Plugin; |
| 27 | +import org.elasticsearch.snapshots.mockstore.MockRepository; |
| 28 | +import org.elasticsearch.test.ESIntegTestCase; |
| 29 | +import org.elasticsearch.test.disruption.NetworkDisruption; |
| 30 | +import org.elasticsearch.test.transport.MockTransportService; |
| 31 | + |
| 32 | +import java.util.Arrays; |
| 33 | +import java.util.Collection; |
| 34 | +import java.util.concurrent.TimeUnit; |
| 35 | + |
| 36 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 37 | +import static org.hamcrest.Matchers.equalTo; |
| 38 | + |
| 39 | +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, transportClientRatio = 0) |
| 40 | +public class SnapshotShardsServiceIT extends AbstractSnapshotIntegTestCase { |
| 41 | + |
| 42 | + @Override |
| 43 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 44 | + return Arrays.asList(MockRepository.Plugin.class, MockTransportService.TestPlugin.class); |
| 45 | + } |
| 46 | + |
| 47 | + public void testRetryPostingSnapshotStatusMessages() throws Exception { |
| 48 | + String masterNode = internalCluster().startMasterOnlyNode(); |
| 49 | + String dataNode = internalCluster().startDataOnlyNode(); |
| 50 | + |
| 51 | + logger.info("--> creating repository"); |
| 52 | + assertAcked(client().admin().cluster().preparePutRepository("test-repo") |
| 53 | + .setType("mock").setSettings(Settings.builder() |
| 54 | + .put("location", randomRepoPath()) |
| 55 | + .put("compress", randomBoolean()) |
| 56 | + .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES))); |
| 57 | + |
| 58 | + final int shards = between(1, 10); |
| 59 | + assertAcked(prepareCreate("test-index", 0, Settings.builder().put("number_of_shards", shards).put("number_of_replicas", 0))); |
| 60 | + ensureGreen(); |
| 61 | + final int numDocs = scaledRandomIntBetween(50, 100); |
| 62 | + for (int i = 0; i < numDocs; i++) { |
| 63 | + index("test-index", "doc", Integer.toString(i)); |
| 64 | + } |
| 65 | + |
| 66 | + logger.info("--> blocking repository"); |
| 67 | + String blockedNode = blockNodeWithIndex("test-repo", "test-index"); |
| 68 | + dataNodeClient().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") |
| 69 | + .setWaitForCompletion(false) |
| 70 | + .setIndices("test-index") |
| 71 | + .get(); |
| 72 | + waitForBlock(blockedNode, "test-repo", TimeValue.timeValueSeconds(60)); |
| 73 | + |
| 74 | + logger.info("--> start disrupting cluster"); |
| 75 | + final NetworkDisruption networkDisruption = new NetworkDisruption(new NetworkDisruption.TwoPartitions(masterNode, dataNode), |
| 76 | + NetworkDisruption.NetworkDelay.random(random())); |
| 77 | + internalCluster().setDisruptionScheme(networkDisruption); |
| 78 | + networkDisruption.startDisrupting(); |
| 79 | + |
| 80 | + logger.info("--> unblocking repository"); |
| 81 | + unblockNode("test-repo", blockedNode); |
| 82 | + Thread.sleep(200); |
| 83 | + logger.info("--> stop disrupting cluster"); |
| 84 | + internalCluster().clearDisruptionScheme(true); |
| 85 | + |
| 86 | + assertBusy(() -> { |
| 87 | + GetSnapshotsResponse snapshotsStatusResponse = client().admin().cluster() |
| 88 | + .prepareGetSnapshots("test-repo") |
| 89 | + .setSnapshots("test-snap").get(); |
| 90 | + logger.info("Status size [{}]", snapshotsStatusResponse.getSnapshots().get(0).successfulShards()); |
| 91 | + SnapshotInfo snapshotInfo = snapshotsStatusResponse.getSnapshots().get(0); |
| 92 | + assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); |
| 93 | + assertThat(snapshotInfo.successfulShards(), equalTo(shards)); |
| 94 | + }, 10, TimeUnit.SECONDS); |
| 95 | + } |
| 96 | +} |
0 commit comments