Skip to content

Commit 31ef1bb

Browse files
committed
refactor
Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent 3c52fcf commit 31ef1bb

4 files changed

Lines changed: 65 additions & 113 deletions

File tree

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

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +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;
11-
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_TIME_DATA;
128
import static org.opensearch.sql.util.MatcherUtils.columnName;
139
import static org.opensearch.sql.util.MatcherUtils.rows;
1410
import static org.opensearch.sql.util.MatcherUtils.schema;
@@ -17,53 +13,21 @@
1713
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1814

1915
import java.io.IOException;
20-
import lombok.SneakyThrows;
2116
import org.json.JSONObject;
22-
import org.junit.jupiter.api.BeforeEach;
2317
import org.junit.jupiter.api.Test;
24-
import org.opensearch.sql.ppl.PPLIntegTestCase;
2518

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

5822
@Override
5923
protected void init() throws Exception {
24+
super.init();
6025
configureMultiClusters(REMOTE_CLUSTER);
6126
loadIndex(Index.BANK);
6227
loadIndex(Index.BANK, remoteClient());
63-
loadIndex(Index.ACCOUNT);
64-
loadIndex(Index.ACCOUNT, remoteClient());
6528
loadIndex(Index.DOG);
6629
loadIndex(Index.DOG, remoteClient());
30+
loadIndex(Index.ACCOUNT);
6731
loadIndex(Index.TIME_TEST_DATA);
6832
loadIndex(Index.TIME_TEST_DATA, remoteClient());
6933
enableCalcite();
@@ -303,12 +267,12 @@ public void testCrossClusterRenameFullWildcard() throws IOException {
303267
schema("old_dog_name", "string"),
304268
schema("old_holdersName", "string"),
305269
schema("old_age", "bigint"),
306-
schema("old__id", "bigint"),
307-
schema("old__index", "bigint"),
308-
schema("old__score", "bigint"),
309-
schema("old__maxscore", "bigint"),
270+
schema("old__id", "string"),
271+
schema("old__index", "string"),
272+
schema("old__score", "float"),
273+
schema("old__maxscore", "float"),
310274
schema("old__sort", "bigint"),
311-
schema("old__routing", "bigint"));
275+
schema("old__routing", "string"));
312276
}
313277

314278
@Test

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

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,22 @@
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;
1613
import org.junit.jupiter.api.Test;
17-
import org.opensearch.sql.ppl.PPLIntegTestCase;
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();
19+
super.init();
4920
configureMultiClusters(REMOTE_CLUSTER);
5021
loadIndex(Index.DOG);
5122
loadIndex(Index.DOG, remoteClient());
23+
enableCalcite();
5224
}
5325

5426
@Test

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +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;
2016
import org.junit.jupiter.api.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 {
24+
super.init();
6125
configureMultiClusters(REMOTE_CLUSTER);
6226
loadIndex(Index.BANK);
6327
loadIndex(Index.BANK, remoteClient());
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 lombok.SneakyThrows;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.opensearch.sql.ppl.PPLIntegTestCase;
16+
17+
public class CrossClusterTestBase extends PPLIntegTestCase {
18+
static {
19+
// find a remote cluster
20+
String[] clusterNames = System.getProperty("cluster.names").split(",");
21+
var remote = "remoteCluster";
22+
for (var cluster : clusterNames) {
23+
if (cluster.startsWith("remote")) {
24+
remote = cluster;
25+
break;
26+
}
27+
}
28+
REMOTE_CLUSTER = remote;
29+
}
30+
31+
public static final String REMOTE_CLUSTER;
32+
33+
protected static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK;
34+
protected static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
35+
protected static final String TEST_INDEX_DOG_MATCH_ALL_REMOTE =
36+
MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG;
37+
protected static final String TEST_INDEX_ACCOUNT_REMOTE =
38+
REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT;
39+
protected static final String TEST_INDEX_TIME_DATA_REMOTE =
40+
REMOTE_CLUSTER + ":" + TEST_INDEX_TIME_DATA;
41+
42+
protected static boolean initialized = false;
43+
44+
@SneakyThrows
45+
@BeforeEach
46+
public void initialize() {
47+
if (!initialized) {
48+
setUpIndices();
49+
initialized = true;
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)