Skip to content

Commit 9886100

Browse files
authored
Fix the filter of integTestWithSecurity (#5098)
* Fix the filter of integTestWithSecurity Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * refactor Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix IT Signed-off-by: Lantao Jin <ltjin@amazon.com> * Use Junit4 Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix Signed-off-by: Lantao Jin <ltjin@amazon.com> * fix httpclient leaking Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix permission IT in Junit4 Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent 914de99 commit 9886100

7 files changed

Lines changed: 105 additions & 154 deletions

File tree

integ-test/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ task integTestWithSecurity(type: RestIntegTestTask) {
406406
configureSecurityPlugin(cluster)
407407
}
408408

409-
useJUnitPlatform()
410409
dependsOn ':opensearch-sql-plugin:bundlePlugin'
411410
testLogging {
412411
events "passed", "skipped", "failed"
@@ -447,11 +446,8 @@ task integTestWithSecurity(type: RestIntegTestTask) {
447446
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
448447
}
449448

450-
// NOTE: this IT config discovers only junit5 (jupiter) tests.
451-
// https://github.com/opensearch-project/sql/issues/1974
452449
filter {
453-
includeTestsMatching 'org.opensearch.sql.security.CrossClusterSearchIT'
454-
includeTestsMatching 'org.opensearch.sql.security.PPLPermissionsIT'
450+
includeTestsMatching 'org.opensearch.sql.security.*'
455451
}
456452
}
457453

integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ protected static void configureHttpsClient(
311311
* cluster.
312312
*/
313313
public void configureMultiClusters(String remote) throws IOException {
314-
initRemoteClient(remote);
314+
if (remoteClient == null) {
315+
initRemoteClient(remote);
316+
}
315317

316318
Request connectionRequest = new Request("PUT", "_cluster/settings");
317319
String connectionSetting =

integ-test/src/test/java/org/opensearch/sql/security/CalciteCrossClusterSearchIT.java

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
package org.opensearch.sql.security;
77

8-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
9-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
10-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
118
import static org.opensearch.sql.util.MatcherUtils.columnName;
129
import static org.opensearch.sql.util.MatcherUtils.rows;
1310
import static org.opensearch.sql.util.MatcherUtils.schema;
@@ -16,51 +13,21 @@
1613
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1714

1815
import java.io.IOException;
19-
import lombok.SneakyThrows;
2016
import org.json.JSONObject;
21-
import org.junit.jupiter.api.BeforeEach;
22-
import org.junit.jupiter.api.Test;
23-
import org.opensearch.sql.ppl.PPLIntegTestCase;
17+
import org.junit.Test;
2418

2519
/** Cross Cluster Search tests with Calcite enabled for enhanced fields features. */
26-
public class CalciteCrossClusterSearchIT extends PPLIntegTestCase {
27-
28-
static {
29-
String[] clusterNames = System.getProperty("cluster.names").split(",");
30-
var remote = "remoteCluster";
31-
for (var cluster : clusterNames) {
32-
if (cluster.startsWith("remote")) {
33-
remote = cluster;
34-
break;
35-
}
36-
}
37-
REMOTE_CLUSTER = remote;
38-
}
39-
40-
public static final String REMOTE_CLUSTER;
41-
private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT;
42-
private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
43-
private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
44-
private static boolean initialized = false;
45-
46-
@SneakyThrows
47-
@BeforeEach
48-
public void initialize() {
49-
if (!initialized) {
50-
setUpIndices();
51-
initialized = true;
52-
}
53-
}
20+
public class CalciteCrossClusterSearchIT extends CrossClusterTestBase {
5421

5522
@Override
5623
protected void init() throws Exception {
57-
configureMultiClusters(REMOTE_CLUSTER);
24+
super.init();
5825
loadIndex(Index.BANK);
5926
loadIndex(Index.BANK, remoteClient());
60-
loadIndex(Index.ACCOUNT);
61-
loadIndex(Index.ACCOUNT, remoteClient());
6227
loadIndex(Index.DOG);
6328
loadIndex(Index.DOG, remoteClient());
29+
loadIndex(Index.ACCOUNT);
30+
loadIndex(Index.ACCOUNT, remoteClient());
6431
loadIndex(Index.TIME_TEST_DATA);
6532
loadIndex(Index.TIME_TEST_DATA, remoteClient());
6633
enableCalcite();
@@ -87,8 +54,8 @@ public void testCrossClusterFieldsWildcardPrefix() throws IOException {
8754
public void testCrossClusterFieldsWildcardSuffix() throws IOException {
8855
JSONObject result =
8956
executeQuery(String.format("search source=%s | fields *Name", TEST_INDEX_DOG_REMOTE));
90-
verifyColumn(result, columnName("dog_name"), columnName("holdersName"));
91-
verifySchema(result, schema("dog_name", "string"), schema("holdersName", "string"));
57+
verifyColumn(result, columnName("holdersName"));
58+
verifySchema(result, schema("holdersName", "string"));
9259
}
9360

9461
@Test
@@ -165,7 +132,7 @@ public void testDefaultBinCrossCluster() throws IOException {
165132
TEST_INDEX_ACCOUNT_REMOTE));
166133
verifySchema(result, schema("count()", null, "bigint"), schema("age", null, "string"));
167134

168-
verifyDataRows(result, rows(451L, "20-30"), rows(504L, "30-40"), rows(45L, "40-50"));
135+
verifyDataRows(result, rows(451, "20.0-30.0"), rows(504L, "30.0-40.0"), rows(45L, "40.0-50.0"));
169136
}
170137

171138
@Test
@@ -218,18 +185,18 @@ public void testRangeBinCrossCluster() throws IOException {
218185
TEST_INDEX_ACCOUNT_REMOTE));
219186
verifySchema(result, schema("count()", null, "bigint"), schema("age", null, "string"));
220187

221-
verifyDataRows(result, rows(1000L, "0-100"));
188+
verifyDataRows(result, rows(451, "20-30"), rows(504L, "30-40"), rows(45L, "40-50"));
222189
}
223190

224191
@Test
225192
public void testTimeBinCrossCluster() throws IOException {
226193
// Time-based binning with span
227194
JSONObject result =
228195
executeQuery(
229-
REMOTE_CLUSTER
230-
+ ":opensearch-sql_test_index_time_data"
231-
+ " | bin @timestamp span=1h"
232-
+ " | fields `@timestamp`, value | sort `@timestamp` | head 3");
196+
String.format(
197+
"source=%s | bin @timestamp span=1h | fields `@timestamp`, value | sort"
198+
+ " `@timestamp` | head 3",
199+
TEST_INDEX_TIME_DATA_REMOTE));
233200
verifySchema(result, schema("@timestamp", null, "timestamp"), schema("value", null, "int"));
234201

235202
// With 1-hour spans
@@ -285,12 +252,27 @@ public void testCrossClusterRenameFullWildcard() throws IOException {
285252
JSONObject result =
286253
executeQuery(String.format("search source=%s | rename * as old_*", TEST_INDEX_DOG_REMOTE));
287254
verifyColumn(
288-
result, columnName("old_dog_name"), columnName("old_holdersName"), columnName("old_age"));
255+
result,
256+
columnName("old_dog_name"),
257+
columnName("old_holdersName"),
258+
columnName("old_age"),
259+
columnName("old__id"),
260+
columnName("old__index"),
261+
columnName("old__score"),
262+
columnName("old__maxscore"),
263+
columnName("old__sort"),
264+
columnName("old__routing"));
289265
verifySchema(
290266
result,
291267
schema("old_dog_name", "string"),
292268
schema("old_holdersName", "string"),
293-
schema("old_age", "bigint"));
269+
schema("old_age", "bigint"),
270+
schema("old__id", "string"),
271+
schema("old__index", "string"),
272+
schema("old__score", "float"),
273+
schema("old__maxscore", "float"),
274+
schema("old__sort", "bigint"),
275+
schema("old__routing", "string"));
294276
}
295277

296278
@Test

integ-test/src/test/java/org/opensearch/sql/security/CrossClusterCoalesceIT.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,21 @@
55

66
package org.opensearch.sql.security;
77

8-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
98
import static org.opensearch.sql.util.MatcherUtils.columnName;
109
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
1110

1211
import java.io.IOException;
13-
import lombok.SneakyThrows;
1412
import org.json.JSONObject;
15-
import org.junit.jupiter.api.BeforeEach;
16-
import org.junit.jupiter.api.Test;
17-
import org.opensearch.sql.ppl.PPLIntegTestCase;
13+
import org.junit.Test;
1814

19-
public class CrossClusterCoalesceIT extends PPLIntegTestCase {
20-
21-
static {
22-
String[] clusterNames = System.getProperty("cluster.names").split(",");
23-
var remote = "remoteCluster";
24-
for (var cluster : clusterNames) {
25-
if (cluster.startsWith("remote")) {
26-
remote = cluster;
27-
break;
28-
}
29-
}
30-
REMOTE_CLUSTER = remote;
31-
}
32-
33-
public static final String REMOTE_CLUSTER;
34-
private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
35-
private static boolean initialized = false;
36-
37-
@SneakyThrows
38-
@BeforeEach
39-
public void initialize() {
40-
if (!initialized) {
41-
setUpIndices();
42-
initialized = true;
43-
}
44-
}
15+
public class CrossClusterCoalesceIT extends CrossClusterTestBase {
4516

4617
@Override
4718
protected void init() throws Exception {
48-
enableCalcite();
49-
configureMultiClusters(REMOTE_CLUSTER);
19+
super.init();
5020
loadIndex(Index.DOG);
5121
loadIndex(Index.DOG, remoteClient());
22+
enableCalcite();
5223
}
5324

5425
@Test

integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,23 @@
55

66
package org.opensearch.sql.security;
77

8-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
98
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
10-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
119
import static org.opensearch.sql.util.MatcherUtils.columnName;
1210
import static org.opensearch.sql.util.MatcherUtils.rows;
1311
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
1412
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
1513

1614
import java.io.IOException;
17-
import lombok.SneakyThrows;
1815
import org.json.JSONObject;
19-
import org.junit.jupiter.api.BeforeEach;
20-
import org.junit.jupiter.api.Test;
16+
import org.junit.Test;
2117
import org.opensearch.client.ResponseException;
22-
import org.opensearch.sql.ppl.PPLIntegTestCase;
2318

2419
/** Cross Cluster Search tests to be executed with security plugin. */
25-
public class CrossClusterSearchIT extends PPLIntegTestCase {
26-
27-
static {
28-
// find a remote cluster
29-
String[] clusterNames = System.getProperty("cluster.names").split(",");
30-
var remote = "remoteCluster";
31-
for (var cluster : clusterNames) {
32-
if (cluster.startsWith("remote")) {
33-
remote = cluster;
34-
break;
35-
}
36-
}
37-
REMOTE_CLUSTER = remote;
38-
}
39-
40-
public static final String REMOTE_CLUSTER;
41-
42-
private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
43-
private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
44-
private static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE =
45-
MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
46-
private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT;
47-
48-
private static boolean initialized = false;
49-
50-
@SneakyThrows
51-
@BeforeEach
52-
public void initialize() {
53-
if (!initialized) {
54-
setUpIndices();
55-
initialized = true;
56-
}
57-
}
20+
public class CrossClusterSearchIT extends CrossClusterTestBase {
5821

5922
@Override
6023
protected void init() throws Exception {
61-
configureMultiClusters(REMOTE_CLUSTER);
24+
super.init();
6225
loadIndex(Index.BANK);
6326
loadIndex(Index.BANK, remoteClient());
6427
loadIndex(Index.DOG);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.security;
7+
8+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
9+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
10+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG;
11+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TIME_DATA;
12+
13+
import org.opensearch.sql.ppl.PPLIntegTestCase;
14+
15+
public class CrossClusterTestBase extends PPLIntegTestCase {
16+
static {
17+
// find a remote cluster
18+
String[] clusterNames = System.getProperty("cluster.names").split(",");
19+
var remote = "remoteCluster";
20+
for (var cluster : clusterNames) {
21+
if (cluster.startsWith("remote")) {
22+
remote = cluster;
23+
break;
24+
}
25+
}
26+
REMOTE_CLUSTER = remote;
27+
}
28+
29+
public static final String REMOTE_CLUSTER;
30+
31+
protected static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
32+
protected static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
33+
protected static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE =
34+
MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
35+
protected static final String TEST_INDEX_ACCOUNT_REMOTE =
36+
REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT;
37+
protected static final String TEST_INDEX_TIME_DATA_REMOTE =
38+
REMOTE_CLUSTER + ":" + TEST_INDEX_TIME_DATA;
39+
40+
@Override
41+
protected void init() throws Exception {
42+
super.init();
43+
configureMultiClusters(REMOTE_CLUSTER);
44+
}
45+
}

0 commit comments

Comments
 (0)