Skip to content

Commit a4c4e8a

Browse files
committed
Fix bwc IT gracefully
Signed-off-by: Louis Chu <clingzhi@amazon.com>
1 parent 30586c5 commit a4c4e8a

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import static org.opensearch.sql.legacy.TestUtils.isIndexExist;
1010
import static org.opensearch.sql.legacy.TestUtils.loadDataByRestClient;
1111
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
12+
import static org.opensearch.sql.sql.LegacyAPICompatibilityIT.LEGACY_QUERY_API_ENDPOINT;
13+
import static org.opensearch.sql.sql.LegacyAPICompatibilityIT.LEGACY_SQL_SETTINGS_API_ENDPOINT;
1214
import static org.opensearch.sql.util.MatcherUtils.rows;
1315
import static org.opensearch.sql.util.MatcherUtils.schema;
1416
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
@@ -91,10 +93,33 @@ public void testBackwardsCompatibility() throws Exception {
9193
List<Map<String, Object>> plugins = (List<Map<String, Object>>) response.get("plugins");
9294
Set<Object> pluginNames =
9395
plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet());
96+
String version = (String) response.get("version");
97+
98+
boolean isBackwardsIncompatibleVersion = version.startsWith("2.");
99+
94100
switch (CLUSTER_TYPE) {
101+
case OLD:
102+
Assert.assertTrue(pluginNames.contains("opensearch-sql"));
103+
if (isBackwardsIncompatibleVersion) {
104+
updateLegacySQLSettings();
105+
}
106+
loadIndex(Index.ACCOUNT);
107+
verifySQLQueries(
108+
isBackwardsIncompatibleVersion ? LEGACY_QUERY_API_ENDPOINT : QUERY_API_ENDPOINT);
109+
break;
110+
case MIXED:
111+
Assert.assertTrue(pluginNames.contains("opensearch-sql"));
112+
if (isBackwardsIncompatibleVersion) {
113+
verifySQLSettings();
114+
} else {
115+
// For upgraded nodes, we don't need to verify legacy settings
116+
}
117+
verifySQLQueries(
118+
isBackwardsIncompatibleVersion ? LEGACY_QUERY_API_ENDPOINT : QUERY_API_ENDPOINT);
119+
break;
95120
case UPGRADED:
96121
Assert.assertTrue(pluginNames.contains("opensearch-sql"));
97-
verifySQLSettings();
122+
// For fully upgraded clusters, we don't need to verify legacy settings
98123
verifySQLQueries(QUERY_API_ENDPOINT);
99124
break;
100125
}
@@ -122,6 +147,24 @@ private String getUri() {
122147
}
123148
}
124149

150+
private void updateLegacySQLSettings() throws IOException {
151+
Request request = new Request("PUT", LEGACY_SQL_SETTINGS_API_ENDPOINT);
152+
request.setJsonEntity(
153+
String.format(
154+
Locale.ROOT,
155+
"{\n" + " \"persistent\" : {\n \"%s\" : \"%s\"\n }\n}",
156+
"opendistro.sql.cursor.keep_alive",
157+
"7m"));
158+
159+
RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
160+
restOptionsBuilder.addHeader("Content-Type", "application/json");
161+
request.setOptions(restOptionsBuilder);
162+
163+
Response response = client().performRequest(request);
164+
JSONObject jsonObject = new JSONObject(getResponseBody(response));
165+
Assert.assertTrue((boolean) jsonObject.get("acknowledged"));
166+
}
167+
125168
private void verifySQLSettings() throws IOException {
126169
Request request = new Request("GET", "_cluster/settings?flat_settings");
127170

@@ -132,7 +175,7 @@ private void verifySQLSettings() throws IOException {
132175
Response response = client().performRequest(request);
133176
JSONObject jsonObject = new JSONObject(getResponseBody(response));
134177
Assert.assertEquals(
135-
"{\"transient\":{},\"persistent\":{\"plugins.sql.cursor.keep_alive\":\"7m\"}}",
178+
"{\"transient\":{},\"persistent\":{\"opendistro.sql.cursor.keep_alive\":\"7m\"}}",
136179
jsonObject.toString());
137180
}
138181

0 commit comments

Comments
 (0)