forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegacyAPICompatibilityIT.java
More file actions
90 lines (78 loc) · 3.1 KB
/
LegacyAPICompatibilityIT.java
File metadata and controls
90 lines (78 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.sql.ppl;
import static org.opensearch.sql.plugin.rest.RestQuerySettingsAction.SETTINGS_API_ENDPOINT;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.Request;
import org.opensearch.client.RequestOptions;
import org.opensearch.client.Response;
/** For backward compatibility, check if legacy API endpoints are accessible. */
public class LegacyAPICompatibilityIT extends PPLIntegTestCase {
public static final String LEGACY_PPL_API_ENDPOINT = "/_opendistro/_ppl";
public static final String LEGACY_PPL_EXPLAIN_API_ENDPOINT = "/_opendistro/_ppl/_explain";
public static final String LEGACY_PPL_SETTINGS_API_ENDPOINT = "/_opendistro/_ppl/settings";
public static final String LEGACY_PPL_STATS_API_ENDPOINT = "/_opendistro/_ppl/stats";
@Override
public void init() throws IOException {
loadIndex(Index.ACCOUNT);
}
@Test
public void query() {
String query = "source=opensearch-sql_test_index_account | where age > 30";
Request request = buildRequest(query, LEGACY_PPL_API_ENDPOINT);
assertBadRequest(() -> client().performRequest(request));
}
@Test
public void explain() {
String query = "source=opensearch-sql_test_index_account | where age > 30";
Request request = buildRequest(query, LEGACY_PPL_EXPLAIN_API_ENDPOINT);
assertBadRequest(() -> client().performRequest(request));
}
@Test
public void stats() {
Request request = new Request("GET", LEGACY_PPL_STATS_API_ENDPOINT);
assertBadRequest(() -> client().performRequest(request));
}
@Test
public void legacyPPLSettingNewEndpoint() {
String requestBody =
"{"
+ " \"persistent\": {"
+ " \"opendistro.ppl.query.memory_limit\": \"80%\""
+ " }"
+ "}";
assertBadRequest(() -> updateSetting(SETTINGS_API_ENDPOINT, requestBody));
}
@Test
public void newPPLSettingsLegacyEndpoint() {
String requestBody =
"{"
+ " \"persistent\": {"
+ " \"plugins.ppl.query.memory_limit\": \"90%\""
+ " }"
+ "}";
assertBadRequest(() -> updateSetting(LEGACY_PPL_SETTINGS_API_ENDPOINT, requestBody));
}
@Test
public void newPPLSettingNewEndpoint() throws IOException {
String requestBody =
"{" + " \"persistent\": {" + " \"plugins.query.size_limit\": \"100\"" + " }" + "}";
Response response = updateSetting(SETTINGS_API_ENDPOINT, requestBody);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}
private Response updateSetting(String endpoint, String requestBody) throws IOException {
Request request = new Request("PUT", endpoint);
request.setJsonEntity(requestBody);
request.setOptions(buildJsonOption());
return client().performRequest(request);
}
private RequestOptions.Builder buildJsonOption() {
RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
restOptionsBuilder.addHeader("Content-Type", "application/json");
return restOptionsBuilder;
}
}