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

[Remote Store] Add support for randomizing Remote Store enabled testing. #12488

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ protected int numberOfReplicas() {
return 1;
}

@Override
public boolean useRemoteBackedStorageRandomly() {
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 @@ -377,6 +377,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;

@BeforeClass
public static void beforeClass() throws Exception {
testClusterRule.beforeClass();
Expand Down Expand Up @@ -1896,9 +1904,19 @@ protected Settings nodeSettings(int nodeOrdinal) {

// Randomly set a replication strategy for the node. Replication Strategy 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);
logger.info("Randomly using Replication Strategy as {}.", randomReplicationType.toString());
builder.put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), randomReplicationType);
}

// Randomly set storage type for the node. Storage Type can still be manually overridden by subclass if needed.
if (useRemoteBackedStorageRandomly()) {
Rishikesh1159 marked this conversation as resolved.
Show resolved Hide resolved
logger.info("Randomly using Storage Type as {}.", randomStorageType);
if (randomStorageType.equals("REMOTE_STORE")) {
if (remoteStoreRepositoryPath == null) {
remoteStoreRepositoryPath = randomRepoPath().toAbsolutePath();
}
builder.put(remoteStoreClusterSettings(REMOTE_BACKED_STORAGE_REPOSITORY_NAME, remoteStoreRepositoryPath));
}
}
return builder.build();
}
Expand All @@ -1912,6 +1930,10 @@ protected boolean useRandomReplicationStrategy() {
return false;
}

protected boolean useRemoteBackedStorageRandomly() {
return false;
}

protected Path nodeConfigPath(int nodeOrdinal) {
return null;
}
Expand Down Expand Up @@ -1951,6 +1973,12 @@ protected boolean ignoreExternalCluster() {
}

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