Skip to content

Commit c0b1899

Browse files
[Remote Store] Add support for randomizing Remote Store enabled testing. (opensearch-project#12488)
* Add support for randomizing remote store enabled testing. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * fix spotless check Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Updating logic to randomly use remote store once per cluster instead of once per node. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Add Remote Store Randomization within Replication Type Randomization. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> --------- Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com>
1 parent 6532caa commit c0b1899

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ public void testCacheWithInvalidation() throws Exception {
650650
.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
651651
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
652652
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
653+
.put("index.refresh_interval", -1)
653654
)
654655
.get()
655656
);

server/src/internalClusterTest/java/org/opensearch/indices/recovery/ReplicaToPrimaryPromotionIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ protected int numberOfReplicas() {
5656
return 1;
5757
}
5858

59+
@Override
60+
public boolean useRandomReplicationStrategy() {
61+
return true;
62+
}
63+
5964
public void testPromoteReplicaToPrimary() throws Exception {
6065
final String indexName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
6166
createIndex(indexName);
@@ -65,7 +70,7 @@ public void testPromoteReplicaToPrimary() throws Exception {
6570
try (BackgroundIndexer indexer = new BackgroundIndexer(indexName, "_doc", client(), numOfDocs)) {
6671
waitForDocs(numOfDocs, indexer);
6772
}
68-
refresh(indexName);
73+
refreshAndWaitForReplication(indexName);
6974
}
7075

7176
assertHitCount(client().prepareSearch(indexName).setSize(0).get(), numOfDocs);

test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ public abstract class OpenSearchIntegTestCase extends OpenSearchTestCase {
379379
*/
380380
public static final String TESTS_CLUSTER_NAME = "tests.clustername";
381381

382+
protected static final String REMOTE_BACKED_STORAGE_REPOSITORY_NAME = "test-remote-store-repo";
383+
384+
private Path remoteStoreRepositoryPath;
385+
386+
private ReplicationType randomReplicationType;
387+
388+
private String randomStorageType;
389+
382390
@BeforeClass
383391
public static void beforeClass() throws Exception {
384392
testClusterRule.beforeClass();
@@ -1896,11 +1904,19 @@ protected Settings nodeSettings(int nodeOrdinal) {
18961904
builder.put(TelemetrySettings.TRACER_ENABLED_SETTING.getKey(), true);
18971905
}
18981906

1899-
// Randomly set a replication strategy for the node. Replication Strategy can still be manually overridden by subclass if needed.
1907+
// Randomly set a Replication Strategy and storage type for the node. Both Replication Strategy and Storage Type can still be
1908+
// manually overridden by subclass if needed.
19001909
if (useRandomReplicationStrategy()) {
1901-
ReplicationType replicationType = randomBoolean() ? ReplicationType.DOCUMENT : ReplicationType.SEGMENT;
1902-
logger.info("Randomly using Replication Strategy as {}.", replicationType.toString());
1903-
builder.put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), replicationType);
1910+
if (randomReplicationType.equals(ReplicationType.SEGMENT) && randomStorageType.equals("REMOTE_STORE")) {
1911+
logger.info("Randomly using Replication Strategy as {} and Storage Type as {}.", randomReplicationType, randomStorageType);
1912+
if (remoteStoreRepositoryPath == null) {
1913+
remoteStoreRepositoryPath = randomRepoPath().toAbsolutePath();
1914+
}
1915+
builder.put(remoteStoreClusterSettings(REMOTE_BACKED_STORAGE_REPOSITORY_NAME, remoteStoreRepositoryPath));
1916+
} else {
1917+
logger.info("Randomly using Replication Strategy as {} and Storage Type as {}.", randomReplicationType, randomStorageType);
1918+
builder.put(CLUSTER_REPLICATION_TYPE_SETTING.getKey(), randomReplicationType);
1919+
}
19041920
}
19051921
return builder.build();
19061922
}
@@ -1953,6 +1969,14 @@ protected boolean ignoreExternalCluster() {
19531969
}
19541970

19551971
protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException {
1972+
if (useRandomReplicationStrategy()) {
1973+
randomReplicationType = randomBoolean() ? ReplicationType.DOCUMENT : ReplicationType.SEGMENT;
1974+
if (randomReplicationType.equals(ReplicationType.SEGMENT)) {
1975+
randomStorageType = randomBoolean() ? "REMOTE_STORE" : "LOCAL";
1976+
} else {
1977+
randomStorageType = "LOCAL";
1978+
}
1979+
}
19561980
String clusterAddresses = System.getProperty(TESTS_CLUSTER);
19571981
if (Strings.hasLength(clusterAddresses) && ignoreExternalCluster() == false) {
19581982
if (scope == Scope.TEST) {

0 commit comments

Comments
 (0)