diff --git a/docs/dev/Pagination.md b/docs/dev/Pagination.md index c2d1fc24ce..4d6af40c39 100644 --- a/docs/dev/Pagination.md +++ b/docs/dev/Pagination.md @@ -425,8 +425,8 @@ Right now there is inconsistency in results for `csv` and `jdbc` format. This is - By default all requests will be a cursor request - meaning the response will contain `cursor` key to fetch next page of result. This is true for all queries which cursor is supported. - Cursor is supported only via `POST` HTTP request. -- If `fetch_size` is omitted from request, it will default to **1000**, unless overridden by cluster settings (See below). -- A `fetch_size` value of **0**, will imply no cursor and query will fallback to non-cursor behavior. This will allow to use/not-use cursor on a per query basis. +- If `fetch_size` is omitted from request, the query will fallback to non-cursor behavior. +- A `fetch_size` value of **0**, will imply no cursor and query will fallback to non-cursor behavior too. This will allow to use/not-use cursor on a per query basis. - If SQL query limit is less than `fetch_size`, no cursor context will be open and all results will be fetched in first page. - Negative or non-numeric values of `fetch_size` will throw `400` exception. - If `cursor` is given as JSON field in request, other fields like `fetch_size` , `query`, `filter`, `parameters` will be ignored. @@ -439,84 +439,6 @@ When OpenSearch bootstraps, SQL plugin will register a few settings in OpenSearc Most of the settings are able to change dynamically so you can control the behavior of SQL plugin without need to bounce your cluster. For cursors we will be exposing the following settings: -#### opensearch.sql.cursor.enabled - -You can disable cursor for all SQL queries which support pagination. - -- The default value is **true**. -- This setting is node scope. -- This setting can be updated dynamically. -- This can be `persistent` and `transient`. - -Example: - -``` ->> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_cluster/settings -d '{ - "transient" : { - "opensearch.sql.cursor.enabled" : "false" - } -}' -``` - -Response: - -``` -{ - "acknowledged" : true, - "persistent" : { }, - "transient" : { - "opensearch" : { - "sql" : { - "cursor" : { - "enabled" : "false" - } - } - } - } -} - -``` - -#### opensearch.sql.cursor.fetch_size - -This setting controls the default page size for all cursor requests. - -- The default value is **1000**. -- The minimum value is **1**. -- The effective max value is controlled by `index.max_result_window` setting. Increase the fetch_size above this will give a 500 error from OpenSearch. -- This setting is node scope. -- This setting can be updated dynamically. -- This can be `persistent` and `transient`. - -Example: - -``` ->> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_cluster/settings -d '{ - "persistent" : { - "opensearch.sql.cursor.fetch_size" : "100" - } -}' -``` - -Response: - -``` -{ - "acknowledged" : true, - "transient" : { }, - "persistent" : { - "opensearch" : { - "sql" : { - "cursor" : { - "fetch_size" : "100" - } - } - } - } -} - -``` - #### opensearch.sql.cursor.keep_alive This setting controls the how long the cursor context is open for all cursor requests. diff --git a/docs/user/admin/settings.rst b/docs/user/admin/settings.rst index 643c2ef3d9..6e233d0f17 100644 --- a/docs/user/admin/settings.rst +++ b/docs/user/admin/settings.rst @@ -121,90 +121,6 @@ Result set:: } } -opensearch.sql.cursor.enabled -============================= - -Description ------------ - -User can enable/disable pagination for all queries that are supported. - -1. The default value is false. -2. This setting is node scope. -3. This setting can be updated dynamically. - - -Example -------- - -You can update the setting with a new value like this. - -SQL query:: - - >> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_plugins/_sql/settings -d '{ - "transient" : { - "opensearch.sql.cursor.enabled" : "true" - } - }' - -Result set:: - - { - "acknowledged" : true, - "persistent" : { }, - "transient" : { - "opensearch" : { - "sql" : { - "cursor" : { - "enabled" : "true" - } - } - } - } - } - -opensearch.sql.cursor.fetch_size -================================ - -Description ------------ - -User can set the default fetch_size for all queries that are supported by pagination. Explicit `fetch_size` passed in request will override this value - -1. The default value is 1000. -2. This setting is node scope. -3. This setting can be updated dynamically. - - -Example -------- - -You can update the setting with a new value like this. - -SQL query:: - - >> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_plugins/_sql/settings -d '{ - "transient" : { - "opensearch.sql.cursor.fetch_size" : "50" - } - }' - -Result set:: - - { - "acknowledged" : true, - "persistent" : { }, - "transient" : { - "opensearch" : { - "sql" : { - "cursor" : { - "fetch_size" : "50" - } - } - } - } - } - opensearch.sql.cursor.keep_alive ================================ diff --git a/docs/user/interfaces/endpoint.rst b/docs/user/interfaces/endpoint.rst index f8e2c27760..492e12b908 100644 --- a/docs/user/interfaces/endpoint.rst +++ b/docs/user/interfaces/endpoint.rst @@ -97,7 +97,7 @@ Cursor Description ----------- -To get paginated response for a query, user needs to provide `fetch_size` parameter as part of normal query. The value of `fetch_size` should be greater than `0`. In absence of `fetch_size`, default value of 1000 is used. A value of `0` will fallback to non-paginated response. This feature is only available over `jdbc` format for now. +To get paginated response for a query, user needs to provide `fetch_size` parameter as part of normal query. The value of `fetch_size` should be greater than `0`. In absence of `fetch_size` or a value of `0`, it will fallback to non-paginated response. This feature is only available over `jdbc` format for now. Example ------- diff --git a/integ-test/src/test/java/org/opensearch/sql/doctest/admin/PluginSettingIT.java b/integ-test/src/test/java/org/opensearch/sql/doctest/admin/PluginSettingIT.java index 64ccbada54..ad0c93576f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/doctest/admin/PluginSettingIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/doctest/admin/PluginSettingIT.java @@ -36,22 +36,17 @@ import static org.opensearch.sql.doctest.core.request.SqlRequestFormat.IGNORE_REQUEST; import static org.opensearch.sql.doctest.core.response.SqlResponseFormat.IGNORE_RESPONSE; import static org.opensearch.sql.doctest.core.response.SqlResponseFormat.PRETTY_JSON_RESPONSE; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_ENABLED; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_FETCH_SIZE; import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_KEEPALIVE; import static org.opensearch.sql.legacy.plugin.SqlSettings.QUERY_SLOWLOG; import static org.opensearch.sql.legacy.plugin.SqlSettings.SQL_ENABLED; -import java.util.Arrays; import java.util.EnumSet; -import java.util.stream.Collectors; import org.opensearch.common.settings.Setting; import org.opensearch.sql.doctest.core.DocTest; import org.opensearch.sql.doctest.core.annotation.DocTestConfig; import org.opensearch.sql.doctest.core.annotation.Section; import org.opensearch.sql.doctest.core.builder.Example; import org.opensearch.sql.doctest.core.builder.ListItems; -import org.opensearch.sql.legacy.executor.Format; import org.opensearch.sql.legacy.plugin.SqlSettings; import org.opensearch.sql.legacy.utils.StringUtils; @@ -83,25 +78,6 @@ public void slowLogSetting() { ); } - @Section(7) - public void cursorEnabledSetting() { - docSetting( - CURSOR_ENABLED, - "User can enable/disable pagination for all queries that are supported.", - true - ); - } - - @Section(8) - public void cursorDefaultFetchSizeSetting() { - docSetting( - CURSOR_FETCH_SIZE, - "User can set the default fetch_size for all queries that are supported by pagination. " + - "Explicit `fetch_size` passed in request will override this value", - 50 - ); - } - @Section(9) public void cursorDefaultContextKeepAliveSetting() { docSetting( diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java index 7b2a1b2f36..7f8b8cb0a7 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/CursorIT.java @@ -41,6 +41,7 @@ import java.util.List; import org.json.JSONArray; import org.json.JSONObject; +import org.junit.Ignore; import org.junit.Test; import org.opensearch.client.Request; import org.opensearch.client.Response; @@ -58,7 +59,6 @@ public class CursorIT extends SQLIntegTestCase { @Override protected void init() throws Exception { loadIndex(Index.ACCOUNT); - enableCursorClusterSetting(); } /** @@ -132,7 +132,7 @@ public void noPaginationWhenFetchSizeZero() throws IOException { String selectQuery = StringUtils.format("SELECT firstname, state FROM %s", TEST_INDEX_ACCOUNT); JSONObject response = new JSONObject(executeFetchQuery(selectQuery, 0, JDBC)); assertFalse(response.has(CURSOR)); - assertThat(response.getJSONArray(DATAROWS).length(), equalTo(200)); + assertThat(response.getJSONArray(DATAROWS).length(), equalTo(1000)); // Default limit is 1000 in new engine } /** @@ -282,6 +282,7 @@ public void testRegressionOnDateFormatChange() throws IOException { } + @Ignore("Breaking change for OpenSearch: deprecate and enable cursor always") @Test public void defaultBehaviorWhenCursorSettingIsDisabled() throws IOException { updateClusterSettings(new ClusterSetting(PERSISTENT, "opensearch.sql.cursor.enabled", "false")); @@ -300,25 +301,14 @@ public void defaultBehaviorWhenCursorSettingIsDisabled() throws IOException { @Test public void testCursorSettings() throws IOException { - // reverting enableCursorClusterSetting() in init() method before checking defaults - updateClusterSettings(new ClusterSetting(PERSISTENT, "opensearch.sql.cursor.enabled", null)); - // Assert default cursor settings JSONObject clusterSettings = getAllClusterSettings(); - assertThat(clusterSettings.query("/defaults/opensearch.sql.cursor.enabled"), equalTo("false")); - assertThat(clusterSettings.query("/defaults/opensearch.sql.cursor.fetch_size"), - equalTo("1000")); assertThat(clusterSettings.query("/defaults/opensearch.sql.cursor.keep_alive"), equalTo("1m")); - updateClusterSettings(new ClusterSetting(PERSISTENT, "opensearch.sql.cursor.enabled", "true")); - updateClusterSettings(new ClusterSetting(TRANSIENT, "opensearch.sql.cursor.fetch_size", "400")); updateClusterSettings( new ClusterSetting(PERSISTENT, "opensearch.sql.cursor.keep_alive", "200s")); clusterSettings = getAllClusterSettings(); - assertThat(clusterSettings.query("/persistent/opensearch.sql.cursor.enabled"), equalTo("true")); - assertThat(clusterSettings.query("/transient/opensearch.sql.cursor.fetch_size"), - equalTo("400")); assertThat(clusterSettings.query("/persistent/opensearch.sql.cursor.keep_alive"), equalTo("200s")); @@ -326,6 +316,7 @@ public void testCursorSettings() throws IOException { } + @Ignore("Breaking change for OpenSearch: no pagination if fetch_size field absent in request") @Test public void testDefaultFetchSizeFromClusterSettings() throws IOException { // the default fetch size is 1000 @@ -481,11 +472,6 @@ public void verifyDataRows(JSONArray dataRowsOne, JSONArray dataRowsTwo) { assertTrue(dataRowsOne.similar(dataRowsTwo)); } - private void enableCursorClusterSetting() throws IOException { - updateClusterSettings( - new ClusterSetting("persistent", "opensearch.sql.cursor.enabled", "true")); - } - public String executeFetchAsStringQuery(String query, String fetchSize, String requestType) throws IOException { String endpoint = QUERY_API_ENDPOINT + "?format=" + requestType; diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/LegacyAPICompatibilityIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/LegacyAPICompatibilityIT.java index 0c9f8c9413..7515ad98fc 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/LegacyAPICompatibilityIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/LegacyAPICompatibilityIT.java @@ -60,23 +60,15 @@ public void explain() throws IOException { @Test public void closeCursor() throws IOException { - updateClusterSettings( - new ClusterSetting("transient", "opensearch.sql.cursor.enabled", "true")); + String sql = StringUtils.format( + "SELECT firstname FROM %s WHERE balance > 100", TEST_INDEX_ACCOUNT); + JSONObject result = new JSONObject(executeFetchQuery(sql, 50, "jdbc")); - try { - String sql = StringUtils.format( - "SELECT firstname FROM %s WHERE balance > 100", TEST_INDEX_ACCOUNT); - JSONObject result = new JSONObject(executeFetchQuery(sql, 50, "jdbc")); - - Request request = new Request("POST", LEGACY_CURSOR_CLOSE_ENDPOINT); - request.setJsonEntity(makeCursorRequest(result.getString("cursor"))); - request.setOptions(buildJsonOption()); - JSONObject response = new JSONObject(executeRequest(request)); - assertThat(response.getBoolean("succeeded"), equalTo(true)); - } finally { - updateClusterSettings( - new ClusterSetting("transient", "opensearch.sql.cursor.enabled", "false")); - } + Request request = new Request("POST", LEGACY_CURSOR_CLOSE_ENDPOINT); + request.setJsonEntity(makeCursorRequest(result.getString("cursor"))); + request.setOptions(buildJsonOption()); + JSONObject response = new JSONObject(executeRequest(request)); + assertThat(response.getBoolean("succeeded"), equalTo(true)); } @Test diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java index d69b95570a..870e0aaf54 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java @@ -29,7 +29,6 @@ import static org.opensearch.rest.RestStatus.BAD_REQUEST; import static org.opensearch.rest.RestStatus.OK; import static org.opensearch.rest.RestStatus.SERVICE_UNAVAILABLE; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_ENABLED; import static org.opensearch.sql.legacy.plugin.SqlSettings.SQL_ENABLED; import com.alibaba.druid.sql.parser.ParserException; @@ -168,18 +167,16 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli Format format = SqlRequestParam.getFormat(request.params()); - if (isCursorDisabled()) { - // Route request to new query engine if it's supported already - SQLQueryRequest newSqlRequest = new SQLQueryRequest(sqlRequest.getJsonContent(), - sqlRequest.getSql(), request.path(), request.params()); - RestChannelConsumer result = newSqlQueryHandler.prepareRequest(newSqlRequest, client); - if (result != RestSQLQueryAction.NOT_SUPPORTED_YET) { - LOG.info("[{}] Request is handled by new SQL query engine", LogUtils.getRequestId()); - return result; - } - LOG.debug("[{}] Request {} is not supported and falling back to old SQL engine", - LogUtils.getRequestId(), newSqlRequest); + // Route request to new query engine if it's supported already + SQLQueryRequest newSqlRequest = new SQLQueryRequest(sqlRequest.getJsonContent(), + sqlRequest.getSql(), request.path(), request.params()); + RestChannelConsumer result = newSqlQueryHandler.prepareRequest(newSqlRequest, client); + if (result != RestSQLQueryAction.NOT_SUPPORTED_YET) { + LOG.info("[{}] Request is handled by new SQL query engine", LogUtils.getRequestId()); + return result; } + LOG.debug("[{}] Request {} is not supported and falling back to old SQL engine", + LogUtils.getRequestId(), newSqlRequest); final QueryAction queryAction = explainRequest(client, sqlRequest, format); return channel -> executeSqlRequest(request, queryAction, client, channel); @@ -284,11 +281,6 @@ private boolean isSQLFeatureEnabled() { return allowExplicitIndex && isSqlEnabled; } - private boolean isCursorDisabled() { - Boolean isEnabled = LocalClusterState.state().getSettingValue(CURSOR_ENABLED); - return Boolean.FALSE.equals(isEnabled); - } - private static ColumnTypeProvider performAnalysis(String sql) { LocalClusterState clusterState = LocalClusterState.state(); SqlAnalysisConfig config = new SqlAnalysisConfig(false, false, 200); diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/SqlSettings.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/SqlSettings.java index 404798a7d7..268a599421 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/SqlSettings.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/SqlSettings.java @@ -53,8 +53,6 @@ public class SqlSettings { public static final String METRICS_ROLLING_WINDOW = "opensearch.sql.metrics.rollingwindow"; public static final String METRICS_ROLLING_INTERVAL = "opensearch.sql.metrics.rollinginterval"; - public static final String CURSOR_ENABLED= "opensearch.sql.cursor.enabled"; - public static final String CURSOR_FETCH_SIZE = "opensearch.sql.cursor.fetch_size"; public static final String CURSOR_KEEPALIVE= "opensearch.sql.cursor.keep_alive"; public static final String DEFAULT_RESPONSE_FORMAT = Format.JDBC.getFormatName(); @@ -72,9 +70,6 @@ public SqlSettings() { NodeScope, Dynamic)); // Settings for cursor - settings.put(CURSOR_ENABLED, Setting.boolSetting(CURSOR_ENABLED, false, NodeScope, Dynamic)); - settings.put(CURSOR_FETCH_SIZE, Setting.intSetting(CURSOR_FETCH_SIZE, 1000, - 1, NodeScope, Dynamic)); settings.put(CURSOR_KEEPALIVE, Setting.positiveTimeSetting(CURSOR_KEEPALIVE, timeValueMinutes(1), NodeScope, Dynamic)); diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/query/DefaultQueryAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/query/DefaultQueryAction.java index a9e3d7db9c..9b771030f4 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/query/DefaultQueryAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/query/DefaultQueryAction.java @@ -26,7 +26,6 @@ package org.opensearch.sql.legacy.query; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_ENABLED; import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_KEEPALIVE; import com.alibaba.druid.sql.ast.SQLExpr; @@ -118,10 +117,9 @@ public void checkAndSetScroll() { Integer fetchSize = sqlRequest.fetchSize(); TimeValue timeValue = clusterState.getSettingValue(CURSOR_KEEPALIVE); - Boolean cursorEnabled = clusterState.getSettingValue(CURSOR_ENABLED); Integer rowCount = select.getRowCount(); - if (checkIfScrollNeeded(cursorEnabled, fetchSize, rowCount)) { + if (checkIfScrollNeeded(fetchSize, rowCount)) { Metrics.getInstance().getNumericalMetric(MetricName.DEFAULT_CURSOR_REQUEST_COUNT_TOTAL).increment(); Metrics.getInstance().getNumericalMetric(MetricName.DEFAULT_CURSOR_REQUEST_TOTAL).increment(); request.setSize(fetchSize).setScroll(timeValue); @@ -132,9 +130,8 @@ public void checkAndSetScroll() { } - private boolean checkIfScrollNeeded(boolean cursorEnabled, Integer fetchSize, Integer rowCount) { - return cursorEnabled - && (format !=null && format.equals(Format.JDBC)) + private boolean checkIfScrollNeeded(Integer fetchSize, Integer rowCount) { + return (format != null && format.equals(Format.JDBC)) && fetchSize > 0 && (rowCount == null || (rowCount > fetchSize)); } diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequestFactory.java b/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequestFactory.java index 8c52ce65b2..3ff0261719 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequestFactory.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/request/SqlRequestFactory.java @@ -26,8 +26,6 @@ package org.opensearch.sql.legacy.request; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_FETCH_SIZE; - import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -35,7 +33,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.opensearch.rest.RestRequest; -import org.opensearch.sql.legacy.esdomain.LocalClusterState; public class SqlRequestFactory { @@ -102,7 +99,7 @@ private static Integer validateAndGetFetchSize(JSONObject jsonContent) { } catch (JSONException e) { throw new IllegalArgumentException("Failed to parse field [" + SQL_FETCH_FIELD_NAME +"]", e); } - return fetchSize.orElse(LocalClusterState.state().getSettingValue(CURSOR_FETCH_SIZE)); + return fetchSize.orElse(0); } private static List parseParameters( diff --git a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java index b77313d849..bf6face6ee 100644 --- a/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java +++ b/legacy/src/test/java/org/opensearch/sql/legacy/unittest/query/DefaultQueryActionTest.java @@ -34,8 +34,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_ENABLED; -import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_FETCH_SIZE; import static org.opensearch.sql.legacy.plugin.SqlSettings.CURSOR_KEEPALIVE; import static org.opensearch.sql.legacy.plugin.SqlSettings.METRICS_ROLLING_INTERVAL; import static org.opensearch.sql.legacy.plugin.SqlSettings.METRICS_ROLLING_WINDOW; @@ -156,7 +154,7 @@ public void testIfScrollShouldBeOpenWithDifferentFormats() { int settingFetchSize = 500; TimeValue timeValue = new TimeValue(120000); int limit = 2300; - mockLocalClusterStateAndInitializeMetrics(true, settingFetchSize, timeValue); + mockLocalClusterStateAndInitializeMetrics(timeValue); doReturn(limit).when(mockSelect).getRowCount(); doReturn(mockRequestBuilder).when(mockRequestBuilder).setSize(settingFetchSize); @@ -181,7 +179,7 @@ public void testIfScrollShouldBeOpenWithDifferentFormats() { } @Test - public void testIfScrollShouldBeOpenWithCursorEnabled() { + public void testIfScrollShouldBeOpen() { int settingFetchSize = 500; TimeValue timeValue = new TimeValue(120000); int limit = 2300; @@ -193,12 +191,7 @@ public void testIfScrollShouldBeOpenWithCursorEnabled() { queryAction.setSqlRequest(mockSqlRequest); queryAction.setFormat(Format.JDBC); - mockLocalClusterStateAndInitializeMetrics(false, settingFetchSize, timeValue); - queryAction.checkAndSetScroll(); - Mockito.verify(mockRequestBuilder).setSize(limit); - Mockito.verify(mockRequestBuilder, never()).setScroll(any(TimeValue.class)); - - mockLocalClusterStateAndInitializeMetrics(true, settingFetchSize, timeValue); + mockLocalClusterStateAndInitializeMetrics(timeValue); queryAction.checkAndSetScroll(); Mockito.verify(mockRequestBuilder).setSize(settingFetchSize); Mockito.verify(mockRequestBuilder).setScroll(timeValue); @@ -207,10 +200,9 @@ public void testIfScrollShouldBeOpenWithCursorEnabled() { @Test public void testIfScrollShouldBeOpenWithDifferentFetchSize() { - int fetchSize = 500; TimeValue timeValue = new TimeValue(120000); int limit = 2300; - mockLocalClusterStateAndInitializeMetrics(true, fetchSize, timeValue); + mockLocalClusterStateAndInitializeMetrics(timeValue); doReturn(limit).when(mockSelect).getRowCount(); SqlRequest mockSqlRequest = mock(SqlRequest.class); @@ -236,9 +228,8 @@ public void testIfScrollShouldBeOpenWithDifferentFetchSize() { @Test public void testIfScrollShouldBeOpenWithDifferentValidFetchSizeAndLimit() { - int fetchSize = 1000; TimeValue timeValue = new TimeValue(120000); - mockLocalClusterStateAndInitializeMetrics(true, fetchSize, timeValue); + mockLocalClusterStateAndInitializeMetrics(timeValue); int limit = 2300; doReturn(limit).when(mockSelect).getRowCount(); @@ -265,11 +256,9 @@ public void testIfScrollShouldBeOpenWithDifferentValidFetchSizeAndLimit() { Mockito.verify(mockRequestBuilder, never()).setScroll(timeValue); } - private void mockLocalClusterStateAndInitializeMetrics(boolean cursorEnabled, Integer fetchSize, TimeValue time) { + private void mockLocalClusterStateAndInitializeMetrics(TimeValue time) { LocalClusterState mockLocalClusterState = mock(LocalClusterState.class); LocalClusterState.state(mockLocalClusterState); - doReturn(cursorEnabled).when(mockLocalClusterState).getSettingValue(CURSOR_ENABLED); - doReturn(fetchSize).when(mockLocalClusterState).getSettingValue(CURSOR_FETCH_SIZE); doReturn(time).when(mockLocalClusterState).getSettingValue(CURSOR_KEEPALIVE); doReturn(3600L).when(mockLocalClusterState).getSettingValue(METRICS_ROLLING_WINDOW); doReturn(2L).when(mockLocalClusterState).getSettingValue(METRICS_ROLLING_INTERVAL);