Skip to content

Commit

Permalink
Fix test by using non cluster manager for client
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Bafna <[email protected]>
  • Loading branch information
gbbafna committed Sep 25, 2024
1 parent a948ec0 commit dce4359
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.admin.cluster.remotestore.restore.RestoreRemoteStoreRequest;
import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
import org.opensearch.action.admin.indices.recovery.RecoveryResponse;
Expand All @@ -25,6 +27,7 @@
import org.opensearch.common.blobstore.BlobPath;
import org.opensearch.common.io.PathUtils;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.index.Index;
Expand Down Expand Up @@ -63,6 +66,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -997,7 +1001,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
}

public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws InterruptedException, ExecutionException, IOException {
public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Exception {
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings());
Expand Down Expand Up @@ -1033,14 +1037,16 @@ public void testConcurrentSnapshotV2CreateOperation_MasterChange() throws Interr
Thread thread = new Thread(() -> {
try {
String snapshotName = "snapshot-earlier-master";
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
internalCluster().nonClusterManagerClient()
.admin()
.cluster()
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
.setWaitForCompletion(true)
.setMasterNodeTimeout(TimeValue.timeValueSeconds(60))
.get();
} catch (Exception e) {}
});

} catch (Exception ignored) {}
});
thread.start();

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

// Validate that we have greater one snapshot has been created
String snapshotName = "new-snapshot";
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
.cluster()
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
.setWaitForCompletion(false)
.get();
Repository repository = internalCluster().getInstance(RepositoriesService.class).repository(snapshotRepoName);
PlainActionFuture<RepositoryData> repositoryDataPlainActionFuture = new PlainActionFuture<>();
repository.getRepositoryData(repositoryDataPlainActionFuture);
try {
client().admin().cluster().prepareCreateSnapshot(snapshotRepoName, snapshotName).setWaitForCompletion(true).get();
} catch (Exception e) {
logger.info("Exception while creating new-snapshot", e);
}

RepositoryData repositoryData = repositoryDataPlainActionFuture.get();
assertThat(repositoryData.getSnapshotIds().size(), greaterThanOrEqualTo(1));
// Validate that snapshot is present in repository data
assertBusy(() -> {
GetSnapshotsRequest request = new GetSnapshotsRequest(snapshotRepoName);
GetSnapshotsResponse response2 = client().admin().cluster().getSnapshots(request).actionGet();
assertThat(response2.getSnapshots().size(), greaterThanOrEqualTo(1));
}, 30, TimeUnit.SECONDS);
thread.join();
}

Expand Down

0 comments on commit dce4359

Please sign in to comment.