Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Add support for randomizing Remote Store enabled testing #13845

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ protected int numberOfReplicas() {
return 1;
}

@Override
public boolean useRandomReplicationStrategy() {
return true;
}

public void testPromoteReplicaToPrimary() throws Exception {
final String indexName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
createIndex(indexName);
Expand All @@ -65,7 +70,7 @@ public void testPromoteReplicaToPrimary() throws Exception {
try (BackgroundIndexer indexer = new BackgroundIndexer(indexName, "_doc", client(), numOfDocs)) {
waitForDocs(numOfDocs, indexer);
}
refresh(indexName);
refreshAndWaitForReplication(indexName);
}

assertHitCount(client().prepareSearch(indexName).setSize(0).get(), numOfDocs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
*/
public static final String TESTS_CLUSTER_NAME = "tests.clustername";

protected static final String REMOTE_BACKED_STORAGE_REPOSITORY_NAME = "test-remote-store-repo";

private Path remoteStoreRepositoryPath;

private ReplicationType randomReplicationType;

private String randomStorageType;

/**
* The lucene_default {@link Codec} is not added to the list as it internally maps to Asserting {@link Codec}.
* The override to fetch the {@link CompletionFieldMapper.CompletionFieldType} postings format is not available for this codec.
Expand Down Expand Up @@ -1985,11 +1993,19 @@ protected Settings nodeSettings(int nodeOrdinal) {
builder.put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), true);
}

// Randomly set a replication strategy for the node. Replication Strategy can still be manually overridden by subclass if needed.
// Randomly set a Replication Strategy and storage type for the node. Both Replication Strategy and Storage Type can still be
// manually overridden by subclass if needed.
if (useRandomReplicationStrategy()) {
ReplicationType replicationType = randomBoolean() ? ReplicationType.DOCUMENT : ReplicationType.SEGMENT;
logger.info("Randomly using Replication Strategy as {}.", replicationType.toString());
builder.put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), replicationType);
if (randomReplicationType.equals(ReplicationType.SEGMENT) && randomStorageType.equals("REMOTE_STORE")) {
logger.info("Randomly using Replication Strategy as {} and Storage Type as {}.", randomReplicationType, randomStorageType);
if (remoteStoreRepositoryPath == null) {
remoteStoreRepositoryPath = randomRepoPath().toAbsolutePath();
}
builder.put(remoteStoreClusterSettings(REMOTE_BACKED_STORAGE_REPOSITORY_NAME, remoteStoreRepositoryPath));
} else {
logger.info("Randomly using Replication Strategy as {} and Storage Type as {}.", randomReplicationType, randomStorageType);
builder.put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), randomReplicationType);
}
}
return builder.build();
}
Expand Down Expand Up @@ -2042,6 +2058,14 @@ protected boolean ignoreExternalCluster() {
}

protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException {
if (useRandomReplicationStrategy()) {
randomReplicationType = randomBoolean() ? ReplicationType.DOCUMENT : ReplicationType.SEGMENT;
if (randomReplicationType.equals(ReplicationType.SEGMENT)) {
randomStorageType = randomBoolean() ? "REMOTE_STORE" : "LOCAL";
} else {
randomStorageType = "LOCAL";
}
}
String clusterAddresses = System.getProperty(TESTS_CLUSTER);
if (Strings.hasLength(clusterAddresses) && ignoreExternalCluster() == false) {
if (scope == Scope.TEST) {
Expand Down
Loading