Skip to content

Commit

Permalink
refactor integ tests
Browse files Browse the repository at this point in the history
Signed-off-by: bansvaru <[email protected]>
  • Loading branch information
linuxpi committed Nov 27, 2023
1 parent b76b21f commit 8b54836
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
import org.opensearch.test.OpenSearchIntegTestCase;
import org.junit.Before;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

import static org.opensearch.indices.IndicesService.CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING;
import static org.opensearch.indices.IndicesService.CLUSTER_MINIMUM_INDEX_REFRESH_INTERVAL_SETTING;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 2)
public class ClusterIndexRefreshIntervalIT extends OpenSearchIntegTestCase {

public static final String INDEX_NAME = "test-index";
Expand All @@ -77,20 +78,33 @@ static void putIndexTemplate(String refreshInterval) {

request.settings(
Settings.builder() // <1>
.put("index.number_of_shards", 3)
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("index.refresh_interval", refreshInterval)
);
assertTrue(client().admin().indices().putTemplate(request).actionGet().isAcknowledged());
}

public void testIndexTemplateCreationWithLessThanMinimumRefreshInterval() throws Exception {
putIndexTemplate("1s");
public void testIndexTemplateCreationWithLessThanMinimumRefreshInterval() throws ExecutionException, InterruptedException {
String clusterManagerName = internalCluster().getClusterManagerName();
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
putIndexTemplate("2s");

// Test index creation using template with valid refresh interval
String indexName = "log-myindex-1";
createIndex(indexName);
ensureYellowAndNoInitializingShards(indexName);
ensureGreen(indexName);
GetIndexResponse getIndexResponse = client(clusterManagerName).admin().indices().getIndex(new GetIndexRequest()).get();
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, randomFrom(dataNodes));
String uuid = getIndexResponse.getSettings().get(indexName).get(IndexMetadata.SETTING_INDEX_UUID);
IndexService indexService = indicesService.indexService(new Index(indexName, uuid));
assertEquals(TimeValue.timeValueSeconds(2), indexService.getRefreshTaskInterval());
}

public void testDefaultRefreshIntervalWithUpdateClusterAndIndexSettings() throws Exception {
String clusterManagerName = internalCluster().getClusterManagerName();
List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
createIndex(INDEX_NAME);
ensureYellowAndNoInitializingShards(INDEX_NAME);
ensureGreen(INDEX_NAME);
Expand Down Expand Up @@ -224,7 +238,7 @@ public void testRefreshIntervalDisabled() throws ExecutionException, Interrupted
.getAsTime(IndicesService.CLUSTER_MINIMUM_INDEX_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.MINUS_ONE);
boolean createIndexSuccess = clusterMinimumRefreshInterval.equals(TimeValue.MINUS_ONE);
String clusterManagerName = internalCluster().getClusterManagerName();
List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
Settings settings = Settings.builder()
.put(indexSettings())
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), IndexSettings.MINIMUM_REFRESH_INTERVAL)
Expand Down Expand Up @@ -255,7 +269,7 @@ protected TimeValue getMinRefreshIntervalForRefreshDisabled() {

public void testInvalidRefreshInterval() {
String invalidRefreshInterval = "-10s";
internalCluster().startDataOnlyNodes(2);
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
Settings settings = Settings.builder()
.put(indexSettings())
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), invalidRefreshInterval)
Expand All @@ -270,7 +284,7 @@ public void testInvalidRefreshInterval() {
}

public void testCreateIndexWithExplicitNullRefreshInterval() throws ExecutionException, InterruptedException {
List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
Settings indexSettings = Settings.builder()
.put(indexSettings())
.putNull(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey())
Expand All @@ -297,7 +311,7 @@ public void testCreateIndexWithExplicitNullRefreshInterval() throws ExecutionExc
* the index setting. The underlying index should continue to use the same refresh interval as earlier.
*/
public void testClusterMinimumChangeOnIndexWithCustomRefreshInterval() throws ExecutionException, InterruptedException {
List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
List<String> dataNodes = new ArrayList<>(internalCluster().getDataNodeNames());
TimeValue customRefreshInterval = TimeValue.timeValueSeconds(getDefaultRefreshInterval().getSeconds() + randomIntBetween(1, 5));
Settings indexSettings = Settings.builder()
.put(indexSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opensearch.indices.IndicesService;

import java.util.Locale;
import java.util.concurrent.ExecutionException;

public class ClusterIndexRefreshIntervalWithNodeSettingsIT extends ClusterIndexRefreshIntervalIT {

Expand All @@ -28,7 +29,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
.build();
}

public void testIndexTemplateCreationFailsWithLessThanMinimumRefreshInterval() {
public void testIndexTemplateCreationFailsWithLessThanMinimumRefreshInterval() throws ExecutionException, InterruptedException {
Throwable throwable = assertThrows(IllegalArgumentException.class, () -> putIndexTemplate("0s"));
assertEquals(
throwable.getMessage(),
Expand All @@ -39,6 +40,7 @@ public void testIndexTemplateCreationFailsWithLessThanMinimumRefreshInterval() {
getMinRefreshIntervalForRefreshDisabled()
)
);
super.testIndexTemplateCreationWithLessThanMinimumRefreshInterval();
}

@Override
Expand Down

0 comments on commit 8b54836

Please sign in to comment.