Skip to content

Commit dce4359

Browse files
committed
Fix test by using non cluster manager for client
Signed-off-by: Gaurav Bafna <[email protected]>
1 parent a948ec0 commit dce4359

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.opensearch.action.DocWriteResponse;
1212
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
1313
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
14+
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
15+
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
1416
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1517
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
1618
import org.opensearch.action.admin.indices.recovery.RecoveryResponse;
@@ -25,6 +27,7 @@
2527
import org.opensearch.common.blobstore.BlobPath;
2628
import org.opensearch.common.io.PathUtils;
2729
import org.opensearch.common.settings.Settings;
30+
import org.opensearch.common.unit.TimeValue;
2831
import org.opensearch.common.util.io.IOUtils;
2932
import org.opensearch.core.common.unit.ByteSizeUnit;
3033
import org.opensearch.core.index.Index;
@@ -63,6 +66,7 @@
6366
import java.util.Objects;
6467
import java.util.Optional;
6568
import java.util.concurrent.ExecutionException;
69+
import java.util.concurrent.TimeUnit;
6670
import java.util.stream.Collectors;
6771
import java.util.stream.Stream;
6872

@@ -997,7 +1001,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
9971001
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
9981002
}
9991003

1000-
public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws InterruptedException, ExecutionException, IOException {
1004+
public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Exception {
10011005
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
10021006
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
10031007
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
@@ -1033,14 +1037,16 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
10331037
Thread thread = new Thread(() -> {
10341038
try {
10351039
String snapshotName = "snapshot-earlier-master";
1036-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
1040+
internalCluster().nonClusterManagerClient()
1041+
.admin()
10371042
.cluster()
10381043
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
10391044
.setWaitForCompletion(true)
1045+
.setMasterNodeTimeout(TimeValue.timeValueSeconds(60))
10401046
.get();
1041-
} catch (Exception e) {}
1042-
});
10431047

1048+
} catch (Exception ignored) {}
1049+
});
10441050
thread.start();
10451051

10461052
// stop existing master
@@ -1049,17 +1055,18 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
10491055

10501056
// Validate that we have greater one snapshot has been created
10511057
String snapshotName = "new-snapshot";
1052-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
1053-
.cluster()
1054-
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
1055-
.setWaitForCompletion(false)
1056-
.get();
1057-
Repository repository = internalCluster().getInstance(RepositoriesService.class).repository(snapshotRepoName);
1058-
PlainActionFuture<RepositoryData> repositoryDataPlainActionFuture = new PlainActionFuture<>();
1059-
repository.getRepositoryData(repositoryDataPlainActionFuture);
1058+
try {
1059+
client().admin().cluster().prepareCreateSnapshot(snapshotRepoName, snapshotName).setWaitForCompletion(true).get();
1060+
} catch (Exception e) {
1061+
logger.info("Exception while creating new-snapshot", e);
1062+
}
10601063

1061-
RepositoryData repositoryData = repositoryDataPlainActionFuture.get();
1062-
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
1064+
// Validate that snapshot is present in repository data
1065+
assertBusy(() -> {
1066+
GetSnapshotsRequest request = new GetSnapshotsRequest(snapshotRepoName);
1067+
GetSnapshotsResponse response2 = client().admin().cluster().getSnapshots(request).actionGet();
1068+
assertThat(response2.getSnapshots().size(), greaterThanOrEqualTo(1));
1069+
}, 30, TimeUnit.SECONDS);
10631070
thread.join();
10641071
}
10651072

0 commit comments

Comments
 (0)