toMap(Response response, String mode) throws
}
}
+ private final Actions actions;
+
+ @Override
+ Actions actions() {
+ return actions;
+ }
+
public RestSqlSecurityIT() {
- super(new RestActions());
+ actions = new RestActions();
}
@Override
diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
index 7fd65a19b090e..27a7a04017f0b 100644
--- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
+++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
@@ -56,6 +56,13 @@
import static org.hamcrest.Matchers.is;
public abstract class SqlSecurityTestCase extends ESRestTestCase {
+ public String elasticsearchAddress() {
+ // CLI only supports a single node at a time so we just give it one.
+ // String cluster = System.getProperty("tests.rest.cluster");
+ // return cluster.split(",")[0];
+ return getTestRestCluster().split(",")[0];
+ }
+
/**
* Actions taken by this test.
*
@@ -131,7 +138,7 @@ private static Path lookupRolledOverAuditLog() {
/**
* The actions taken by this test.
*/
- private final Actions actions;
+ abstract Actions actions();
/**
* How much of the audit log was written before the test started.
@@ -143,10 +150,6 @@ private static Path lookupRolledOverAuditLog() {
*/
private static boolean auditFileRolledOver = false;
- public SqlSecurityTestCase(Actions actions) {
- this.actions = actions;
- }
-
/**
* All tests run as a an administrative user but use
* es-security-runas-user
to become a less privileged user when needed.
@@ -237,23 +240,23 @@ protected String getProtocol() {
}
public void testQueryWorksAsAdmin() throws Exception {
- actions.queryWorksAsAdmin();
+ actions().queryWorksAsAdmin();
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test").assertLogs();
}
public void testQueryWithFullAccess() throws Exception {
- createUser("full_access", actions.minimalPermissionsForAllActions());
+ createUser("full_access", actions().minimalPermissionsForAllActions());
- actions.expectMatchesAdmin("SELECT * FROM test ORDER BY a", "full_access", "SELECT * FROM test ORDER BY a");
+ actions().expectMatchesAdmin("SELECT * FROM test ORDER BY a", "full_access", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("full_access", "test")
.assertLogs();
}
public void testScrollWithFullAccess() throws Exception {
- createUser("full_access", actions.minimalPermissionsForAllActions());
+ createUser("full_access", actions().minimalPermissionsForAllActions());
- actions.expectScrollMatchesAdmin("SELECT * FROM test ORDER BY a", "full_access", "SELECT * FROM test ORDER BY a");
+ actions().expectScrollMatchesAdmin("SELECT * FROM test ORDER BY a", "full_access", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
/* Scrolling doesn't have to access the index again, at least not through sql.
* If we asserted query and scroll logs then we would see the scroll. */
@@ -268,14 +271,14 @@ public void testScrollWithFullAccess() throws Exception {
public void testQueryNoAccess() throws Exception {
createUser("no_access", "read_nothing");
- actions.expectForbidden("no_access", "SELECT * FROM test");
+ actions().expectForbidden("no_access", "SELECT * FROM test");
createAuditLogAsserter().expect(false, SQL_ACTION_NAME, "no_access", empty()).assertLogs();
}
public void testQueryWrongAccess() throws Exception {
createUser("wrong_access", "read_something_else");
- actions.expectUnknownIndex("wrong_access", "SELECT * FROM test");
+ actions().expectUnknownIndex("wrong_access", "SELECT * FROM test");
createAuditLogAsserter()
// This user has permission to run sql queries so they are given preliminary authorization
.expect(true, SQL_ACTION_NAME, "wrong_access", empty())
@@ -287,7 +290,7 @@ public void testQueryWrongAccess() throws Exception {
public void testQuerySingleFieldGranted() throws Exception {
createUser("only_a", "read_test_a");
- actions.expectMatchesAdmin("SELECT a FROM test ORDER BY a", "only_a", "SELECT * FROM test ORDER BY a");
+ actions().expectMatchesAdmin("SELECT a FROM test ORDER BY a", "only_a", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("only_a", "test")
.assertLogs();
@@ -296,7 +299,7 @@ public void testQuerySingleFieldGranted() throws Exception {
public void testScrollWithSingleFieldGranted() throws Exception {
createUser("only_a", "read_test_a");
- actions.expectScrollMatchesAdmin("SELECT a FROM test ORDER BY a", "only_a", "SELECT * FROM test ORDER BY a");
+ actions().expectScrollMatchesAdmin("SELECT a FROM test ORDER BY a", "only_a", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
/* Scrolling doesn't have to access the index again, at least not through sql.
* If we asserted query and scroll logs then we would see the scroll. */
@@ -311,7 +314,7 @@ public void testScrollWithSingleFieldGranted() throws Exception {
public void testQueryStringSingleFieldGrantedWrongRequested() throws Exception {
createUser("only_a", "read_test_a");
- actions.expectUnknownColumn("only_a", "SELECT c FROM test", "c");
+ actions().expectUnknownColumn("only_a", "SELECT c FROM test", "c");
/* The user has permission to query the index but one of the
* columns that they explicitly mention is hidden from them
* by field level access control. This *looks* like a successful
@@ -324,7 +327,7 @@ public void testQueryStringSingleFieldGrantedWrongRequested() throws Exception {
public void testQuerySingleFieldExcepted() throws Exception {
createUser("not_c", "read_test_a_and_b");
- actions.expectMatchesAdmin("SELECT a, b FROM test ORDER BY a", "not_c", "SELECT * FROM test ORDER BY a");
+ actions().expectMatchesAdmin("SELECT a, b FROM test ORDER BY a", "not_c", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("not_c", "test")
.assertLogs();
@@ -333,7 +336,7 @@ public void testQuerySingleFieldExcepted() throws Exception {
public void testScrollWithSingleFieldExcepted() throws Exception {
createUser("not_c", "read_test_a_and_b");
- actions.expectScrollMatchesAdmin("SELECT a, b FROM test ORDER BY a", "not_c", "SELECT * FROM test ORDER BY a");
+ actions().expectScrollMatchesAdmin("SELECT a, b FROM test ORDER BY a", "not_c", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
/* Scrolling doesn't have to access the index again, at least not through sql.
* If we asserted query and scroll logs then we would see the scroll. */
@@ -348,7 +351,7 @@ public void testScrollWithSingleFieldExcepted() throws Exception {
public void testQuerySingleFieldExceptionedWrongRequested() throws Exception {
createUser("not_c", "read_test_a_and_b");
- actions.expectUnknownColumn("not_c", "SELECT c FROM test", "c");
+ actions().expectUnknownColumn("not_c", "SELECT c FROM test", "c");
/* The user has permission to query the index but one of the
* columns that they explicitly mention is hidden from them
* by field level access control. This *looks* like a successful
@@ -361,21 +364,21 @@ public void testQuerySingleFieldExceptionedWrongRequested() throws Exception {
public void testQueryDocumentExcluded() throws Exception {
createUser("no_3s", "read_test_without_c_3");
- actions.expectMatchesAdmin("SELECT * FROM test WHERE c != 3 ORDER BY a", "no_3s", "SELECT * FROM test ORDER BY a");
+ actions().expectMatchesAdmin("SELECT * FROM test WHERE c != 3 ORDER BY a", "no_3s", "SELECT * FROM test ORDER BY a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("no_3s", "test")
.assertLogs();
}
public void testShowTablesWorksAsAdmin() throws Exception {
- actions.expectShowTables(Arrays.asList("bort", "test"), null);
+ actions().expectShowTables(Arrays.asList("bort", "test"), null);
createAuditLogAsserter().expectSqlCompositeActionGetIndex("test_admin", "bort", "test").assertLogs();
}
public void testShowTablesWorksAsFullAccess() throws Exception {
- createUser("full_access", actions.minimalPermissionsForAllActions());
+ createUser("full_access", actions().minimalPermissionsForAllActions());
- actions.expectMatchesAdmin("SHOW TABLES LIKE '%t'", "full_access", "SHOW TABLES");
+ actions().expectMatchesAdmin("SHOW TABLES LIKE '%t'", "full_access", "SHOW TABLES");
createAuditLogAsserter().expectSqlCompositeActionGetIndex("test_admin", "bort", "test")
.expectSqlCompositeActionGetIndex("full_access", "bort", "test")
.assertLogs();
@@ -384,14 +387,14 @@ public void testShowTablesWorksAsFullAccess() throws Exception {
public void testShowTablesWithNoAccess() throws Exception {
createUser("no_access", "read_nothing");
- actions.expectForbidden("no_access", "SHOW TABLES");
+ actions().expectForbidden("no_access", "SHOW TABLES");
createAuditLogAsserter().expect(false, SQL_ACTION_NAME, "no_access", empty()).assertLogs();
}
public void testShowTablesWithLimitedAccess() throws Exception {
createUser("read_bort", "read_bort");
- actions.expectMatchesAdmin("SHOW TABLES LIKE 'bort'", "read_bort", "SHOW TABLES");
+ actions().expectMatchesAdmin("SHOW TABLES LIKE 'bort'", "read_bort", "SHOW TABLES");
createAuditLogAsserter().expectSqlCompositeActionGetIndex("test_admin", "bort")
.expectSqlCompositeActionGetIndex("read_bort", "bort")
.assertLogs();
@@ -400,7 +403,7 @@ public void testShowTablesWithLimitedAccess() throws Exception {
public void testShowTablesWithLimitedAccessUnaccessableIndex() throws Exception {
createUser("read_bort", "read_bort");
- actions.expectMatchesAdmin("SHOW TABLES LIKE 'not-created'", "read_bort", "SHOW TABLES LIKE 'test'");
+ actions().expectMatchesAdmin("SHOW TABLES LIKE 'not-created'", "read_bort", "SHOW TABLES LIKE 'test'");
createAuditLogAsserter().expect(true, SQL_ACTION_NAME, "test_admin", empty())
.expect(true, GetIndexAction.NAME, "test_admin", contains("not-created"))
.expect(true, SQL_ACTION_NAME, "read_bort", empty())
@@ -413,14 +416,14 @@ public void testDescribeWorksAsAdmin() throws Exception {
expected.put("a", asList("BIGINT", "long"));
expected.put("b", asList("BIGINT", "long"));
expected.put("c", asList("BIGINT", "long"));
- actions.expectDescribe(expected, null);
+ actions().expectDescribe(expected, null);
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test").assertLogs();
}
public void testDescribeWorksAsFullAccess() throws Exception {
- createUser("full_access", actions.minimalPermissionsForAllActions());
+ createUser("full_access", actions().minimalPermissionsForAllActions());
- actions.expectMatchesAdmin("DESCRIBE test", "full_access", "DESCRIBE test");
+ actions().expectMatchesAdmin("DESCRIBE test", "full_access", "DESCRIBE test");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("full_access", "test")
.assertLogs();
@@ -429,14 +432,14 @@ public void testDescribeWorksAsFullAccess() throws Exception {
public void testDescribeWithNoAccess() throws Exception {
createUser("no_access", "read_nothing");
- actions.expectForbidden("no_access", "DESCRIBE test");
+ actions().expectForbidden("no_access", "DESCRIBE test");
createAuditLogAsserter().expect(false, SQL_ACTION_NAME, "no_access", empty()).assertLogs();
}
public void testDescribeWithWrongAccess() throws Exception {
createUser("wrong_access", "read_something_else");
- actions.expectDescribe(Collections.emptyMap(), "wrong_access");
+ actions().expectDescribe(Collections.emptyMap(), "wrong_access");
createAuditLogAsserter()
// This user has permission to run sql queries so they are given preliminary authorization
.expect(true, SQL_ACTION_NAME, "wrong_access", empty())
@@ -448,7 +451,7 @@ public void testDescribeWithWrongAccess() throws Exception {
public void testDescribeSingleFieldGranted() throws Exception {
createUser("only_a", "read_test_a");
- actions.expectDescribe(singletonMap("a", asList("BIGINT", "long")), "only_a");
+ actions().expectDescribe(singletonMap("a", asList("BIGINT", "long")), "only_a");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("only_a", "test").assertLogs();
}
@@ -458,14 +461,14 @@ public void testDescribeSingleFieldExcepted() throws Exception {
Map> expected = new TreeMap<>();
expected.put("a", asList("BIGINT", "long"));
expected.put("b", asList("BIGINT", "long"));
- actions.expectDescribe(expected, "not_c");
+ actions().expectDescribe(expected, "not_c");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("not_c", "test").assertLogs();
}
public void testDescribeDocumentExcluded() throws Exception {
createUser("no_3s", "read_test_without_c_3");
- actions.expectMatchesAdmin("DESCRIBE test", "no_3s", "DESCRIBE test");
+ actions().expectMatchesAdmin("DESCRIBE test", "no_3s", "DESCRIBE test");
createAuditLogAsserter().expectSqlCompositeActionFieldCaps("test_admin", "test")
.expectSqlCompositeActionFieldCaps("no_3s", "test")
.assertLogs();
@@ -473,15 +476,15 @@ public void testDescribeDocumentExcluded() throws Exception {
public void testNoMonitorMain() throws Exception {
createUser("no_monitor_main", "no_monitor_main");
- actions.checkNoMonitorMain("no_monitor_main");
+ actions().checkNoMonitorMain("no_monitor_main");
}
public void testNoGetIndex() throws Exception {
createUser("no_get_index", "no_get_index");
- actions.expectForbidden("no_get_index", "SELECT * FROM test");
- actions.expectForbidden("no_get_index", "SHOW TABLES LIKE 'test'");
- actions.expectForbidden("no_get_index", "DESCRIBE test");
+ actions().expectForbidden("no_get_index", "SELECT * FROM test");
+ actions().expectForbidden("no_get_index", "SHOW TABLES LIKE 'test'");
+ actions().expectForbidden("no_get_index", "DESCRIBE test");
}
protected static void createUser(String name, String role) throws IOException {
From b4ec6b1ea2c0e56c458ef577612118cf576e6052 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Fri, 3 Nov 2023 13:00:42 +0100
Subject: [PATCH 06/18] Remove obsolete setting for single node tests
---
x-pack/plugin/sql/qa/server/single-node/build.gradle | 7 -------
1 file changed, 7 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/single-node/build.gradle b/x-pack/plugin/sql/qa/server/single-node/build.gradle
index 215064ec1328f..ce74893733372 100644
--- a/x-pack/plugin/sql/qa/server/single-node/build.gradle
+++ b/x-pack/plugin/sql/qa/server/single-node/build.gradle
@@ -1,10 +1,3 @@
-testClusters.matching { it.name == "javaRestTest" }.configureEach {
- testDistribution = 'DEFAULT'
- setting 'xpack.security.enabled', 'false'
- setting 'xpack.license.self_generated.type', 'trial'
- plugin ':x-pack:qa:freeze-plugin'
-}
-
dependencies {
clusterPlugins project(':x-pack:qa:freeze-plugin')
}
From fe4affc783a98a61297fe91494203af419907784 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Fri, 3 Nov 2023 13:50:57 +0100
Subject: [PATCH 07/18] Move multi-node ITs to new framework
---
x-pack/plugin/sql/qa/server/build.gradle | 5 +---
.../sql/qa/server/multi-node/build.gradle | 7 ++---
.../xpack/sql/qa/multi_node/CliLenientIT.java | 12 ++++++++-
.../xpack/sql/qa/multi_node/CliSelectIT.java | 12 ++++++++-
.../xpack/sql/qa/multi_node/CliShowIT.java | 12 ++++++++-
.../sql/qa/multi_node/CustomDateFormatIT.java | 8 ++++++
.../sql/qa/multi_node/GeoJdbcCsvSpecIT.java | 10 +++++++
.../sql/qa/multi_node/GeoJdbcSqlSpecIT.java | 10 +++++++
.../qa/multi_node/JdbcDatabaseMetaDataIT.java | 12 ++++++++-
.../sql/qa/multi_node/JdbcShowTablesIT.java | 12 ++++++++-
.../xpack/sql/qa/multi_node/RestSqlIT.java | 12 ++++++++-
.../sql/qa/multi_node/RestSqlMultinodeIT.java | 10 +++++++
.../sql/qa/multi_node/SqlProtocolIT.java | 12 ++++++++-
.../sql/qa/multi_node/SqlTestCluster.java | 26 +++++++++++++++++++
.../sql/qa/single_node/SqlTestCluster.java | 2 --
15 files changed, 144 insertions(+), 18 deletions(-)
create mode 100644 x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
diff --git a/x-pack/plugin/sql/qa/server/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle
index 64462fc34d71b..be3fdf1d9f7f0 100644
--- a/x-pack/plugin/sql/qa/server/build.gradle
+++ b/x-pack/plugin/sql/qa/server/build.gradle
@@ -38,19 +38,16 @@ subprojects {
apply plugin: 'elasticsearch.java'
}
-
if (project.name != 'security') {
// The security project just configures its subprojects
- if (project.name == 'single-node') {
+ if (project.name == 'single-node' || project.name == 'multi-node') {
apply plugin: 'elasticsearch.internal-java-rest-test'
tasks.named('javaRestTest') {
usesDefaultDistribution()
}
} else {
apply plugin: 'elasticsearch.legacy-java-rest-test'
- }
- if (project.name != 'single-node') {
testClusters.matching { it.name == "javaRestTest" }.configureEach {
testDistribution = 'DEFAULT'
setting 'xpack.ml.enabled', 'false'
diff --git a/x-pack/plugin/sql/qa/server/multi-node/build.gradle b/x-pack/plugin/sql/qa/server/multi-node/build.gradle
index 4ded053302803..e7a558ba68dd9 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/build.gradle
+++ b/x-pack/plugin/sql/qa/server/multi-node/build.gradle
@@ -6,9 +6,6 @@ description = 'Run a subset of SQL tests against multiple nodes'
* feel should need to be tested against more than one node.
*/
-testClusters.matching { it.name == "javaRestTest" }.configureEach {
- numberOfNodes = 2
- setting 'xpack.security.enabled', 'false'
- setting 'xpack.license.self_generated.type', 'trial'
- plugin ':x-pack:qa:freeze-plugin'
+dependencies {
+ clusterPlugins project(':x-pack:qa:freeze-plugin')
}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliLenientIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliLenientIT.java
index fc4a04570ff67..6a920dcc00b7c 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliLenientIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliLenientIT.java
@@ -6,6 +6,16 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.cli.LenientTestCase;
+import org.junit.ClassRule;
-public class CliLenientIT extends LenientTestCase {}
+public class CliLenientIT extends LenientTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliSelectIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliSelectIT.java
index 6e8162ef11b67..c1ec6ffd25251 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliSelectIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliSelectIT.java
@@ -6,6 +6,16 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.cli.SelectTestCase;
+import org.junit.ClassRule;
-public class CliSelectIT extends SelectTestCase {}
+public class CliSelectIT extends SelectTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliShowIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliShowIT.java
index db1e506f74301..86d8d89e591ed 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliShowIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CliShowIT.java
@@ -6,6 +6,16 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.cli.ShowTestCase;
+import org.junit.ClassRule;
-public class CliShowIT extends ShowTestCase {}
+public class CliShowIT extends ShowTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CustomDateFormatIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CustomDateFormatIT.java
index 81b3fd59c6bed..5b8b52e5312c8 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CustomDateFormatIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/CustomDateFormatIT.java
@@ -7,8 +7,16 @@
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.CustomDateFormatTestCase;
+import org.junit.ClassRule;
public class CustomDateFormatIT extends CustomDateFormatTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcCsvSpecIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcCsvSpecIT.java
index bca7c41b539c8..e21e5cb64a7ab 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcCsvSpecIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcCsvSpecIT.java
@@ -7,11 +7,21 @@
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.geo.GeoCsvSpecTestCase;
+import org.junit.ClassRule;
import static org.elasticsearch.xpack.ql.CsvSpecReader.CsvTestCase;
public class GeoJdbcCsvSpecIT extends GeoCsvSpecTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+
public GeoJdbcCsvSpecIT(String fileName, String groupName, String testName, Integer lineNumber, CsvTestCase testCase) {
super(fileName, groupName, testName, lineNumber, testCase);
}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcSqlSpecIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcSqlSpecIT.java
index 65b433afcd102..68f6701892ec6 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcSqlSpecIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/GeoJdbcSqlSpecIT.java
@@ -7,9 +7,19 @@
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.geo.GeoSqlSpecTestCase;
+import org.junit.ClassRule;
public class GeoJdbcSqlSpecIT extends GeoSqlSpecTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+
public GeoJdbcSqlSpecIT(String fileName, String groupName, String testName, Integer lineNumber, String query) {
super(fileName, groupName, testName, lineNumber, query);
}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcDatabaseMetaDataIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcDatabaseMetaDataIT.java
index 2477a04f95c8a..0de80872a0fa0 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcDatabaseMetaDataIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcDatabaseMetaDataIT.java
@@ -6,6 +6,16 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.jdbc.DatabaseMetaDataTestCase;
+import org.junit.ClassRule;
-public class JdbcDatabaseMetaDataIT extends DatabaseMetaDataTestCase {}
+public class JdbcDatabaseMetaDataIT extends DatabaseMetaDataTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcShowTablesIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcShowTablesIT.java
index ded5bb81663de..3c8356b9e88f3 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcShowTablesIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/JdbcShowTablesIT.java
@@ -6,6 +6,16 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.jdbc.ShowTablesTestCase;
+import org.junit.ClassRule;
-public class JdbcShowTablesIT extends ShowTablesTestCase {}
+public class JdbcShowTablesIT extends ShowTablesTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlIT.java
index 98a8441f8cdab..ae909789f9c66 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlIT.java
@@ -6,10 +6,20 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase;
+import org.junit.ClassRule;
/**
* Integration test for the rest sql action. The one that speaks json directly to a
* user rather than to the JDBC driver or CLI.
*/
-public class RestSqlIT extends RestSqlTestCase {}
+public class RestSqlIT extends RestSqlTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlMultinodeIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlMultinodeIT.java
index 37e19fe428b4a..a51a2f0d34342 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlMultinodeIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/RestSqlMultinodeIT.java
@@ -12,10 +12,12 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.test.NotEqualMessageBuilder;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase;
+import org.junit.ClassRule;
import java.io.IOException;
import java.nio.charset.UnsupportedCharsetException;
@@ -34,6 +36,14 @@
* Tests specific to multiple nodes.
*/
public class RestSqlMultinodeIT extends ESRestTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+
/**
* Tests count of index run across multiple nodes.
*/
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlProtocolIT.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlProtocolIT.java
index 7ea96c39f3b44..cd99bb3744864 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlProtocolIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlProtocolIT.java
@@ -7,6 +7,16 @@
package org.elasticsearch.xpack.sql.qa.multi_node;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.SqlProtocolTestCase;
+import org.junit.ClassRule;
-public class SqlProtocolIT extends SqlProtocolTestCase {}
+public class SqlProtocolIT extends SqlProtocolTestCase {
+ @ClassRule
+ public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster();
+
+ @Override
+ protected String getTestRestCluster() {
+ return cluster.getHttpAddresses();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
new file mode 100644
index 0000000000000..e92778179cc9b
--- /dev/null
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+package org.elasticsearch.xpack.sql.qa.multi_node;
+
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
+import org.elasticsearch.test.cluster.local.distribution.DistributionType;
+
+public class SqlTestCluster {
+ public static ElasticsearchCluster getCluster() {
+ return ElasticsearchCluster.local()
+ .distribution(DistributionType.DEFAULT)
+ .nodes(2)
+ .setting("cluster.name", "javaRestTest")
+ .setting("xpack.ml.enabled", "false")
+ .setting("xpack.watcher.enabled", "false")
+ .setting("xpack.security.enabled", "false")
+ .setting("xpack.license.self_generated.type", "trial")
+ .plugin(":x-pack:qa:freeze-plugin")
+ .build();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
index 2303e5f27627e..44f2e46699956 100644
--- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
+++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
@@ -11,7 +11,6 @@
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
public class SqlTestCluster {
-
public static ElasticsearchCluster getCluster() {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
@@ -23,5 +22,4 @@ public static ElasticsearchCluster getCluster() {
.plugin(":x-pack:qa:freeze-plugin")
.build();
}
-
}
From 9bf3cd439412cf4432226417dbd3c8883a715a70 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 6 Nov 2023 11:53:36 +0100
Subject: [PATCH 08/18] Attempt remote cluster setup with new framework
---
x-pack/plugin/sql/qa/server/build.gradle | 106 ++++++++----------
.../multi-cluster-with-security/build.gradle | 11 ++
.../JdbcCatalogIT.java | 2 +-
.../RestSqlIT.java | 90 ++++++++++++++-
.../SqlTestCluster.java | 31 +++++
.../SqlTestRemoteCluster.java | 29 +++++
.../sql/qa/jdbc/DatabaseMetaDataTestCase.java | 5 +-
.../sql/qa/jdbc/JdbcIntegrationTestCase.java | 8 +-
.../xpack/sql/qa/jdbc/SysColumnsTestCase.java | 2 +-
.../sql/qa/rest/BaseRestSqlTestCase.java | 23 ++--
.../RemoteClusterAwareSqlRestTestCase.java | 12 +-
.../xpack/sql/qa/rest/RestSqlTestCase.java | 4 +-
12 files changed, 243 insertions(+), 80 deletions(-)
create mode 100644 x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
create mode 100644 x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
diff --git a/x-pack/plugin/sql/qa/server/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle
index be3fdf1d9f7f0..67f1bd1eef4b3 100644
--- a/x-pack/plugin/sql/qa/server/build.gradle
+++ b/x-pack/plugin/sql/qa/server/build.gradle
@@ -40,76 +40,66 @@ subprojects {
if (project.name != 'security') {
// The security project just configures its subprojects
- if (project.name == 'single-node' || project.name == 'multi-node') {
- apply plugin: 'elasticsearch.internal-java-rest-test'
- tasks.named('javaRestTest') {
- usesDefaultDistribution()
- }
- } else {
- apply plugin: 'elasticsearch.legacy-java-rest-test'
-
- testClusters.matching { it.name == "javaRestTest" }.configureEach {
- testDistribution = 'DEFAULT'
- setting 'xpack.ml.enabled', 'false'
- setting 'xpack.watcher.enabled', 'false'
- }
+ apply plugin: 'elasticsearch.internal-java-rest-test'
+ tasks.named('javaRestTest') {
+ usesDefaultDistribution()
}
- dependencies {
- configurations.javaRestTestRuntimeClasspath {
- resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
- }
- configurations.javaRestTestRuntimeOnly {
- // This is also required to make resolveAllDependencies work
- resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
- }
+ dependencies {
+ configurations.javaRestTestRuntimeClasspath {
+ resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
+ }
+ configurations.javaRestTestRuntimeOnly {
+ // This is also required to make resolveAllDependencies work
+ resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
+ }
- /* Since we're a standalone rest test we actually get transitive
- * dependencies but we don't really want them because they cause
- * all kinds of trouble with the jar hell checks. So we suppress
- * them explicitly for non-es projects. */
- javaRestTestImplementation(project(':x-pack:plugin:sql:qa:server')) {
- transitive = false
- }
- javaRestTestImplementation project(":test:framework")
- javaRestTestImplementation project(xpackModule('ql:test-fixtures'))
+ /* Since we're a standalone rest test we actually get transitive
+ * dependencies but we don't really want them because they cause
+ * all kinds of trouble with the jar hell checks. So we suppress
+ * them explicitly for non-es projects. */
+ javaRestTestImplementation(project(':x-pack:plugin:sql:qa:server')) {
+ transitive = false
+ }
+ javaRestTestImplementation project(":test:framework")
+ javaRestTestImplementation project(xpackModule('ql:test-fixtures'))
- // JDBC testing dependencies
- javaRestTestRuntimeOnly "net.sourceforge.csvjdbc:csvjdbc:${csvjdbcVersion}"
- javaRestTestRuntimeOnly "com.h2database:h2:${h2Version}"
+ // JDBC testing dependencies
+ javaRestTestRuntimeOnly "net.sourceforge.csvjdbc:csvjdbc:${csvjdbcVersion}"
+ javaRestTestRuntimeOnly "com.h2database:h2:${h2Version}"
- // H2GIS testing dependencies
- javaRestTestRuntimeOnly("org.orbisgis:h2gis:${h2gisVersion}")
- javaRestTestRuntimeOnly("org.orbisgis:h2gis-api:${h2gisVersion}")
- javaRestTestRuntimeOnly("org.orbisgis:h2gis-utilities:${h2gisVersion}")
- javaRestTestRuntimeOnly("org.orbisgis:cts:1.5.2")
+ // H2GIS testing dependencies
+ javaRestTestRuntimeOnly("org.orbisgis:h2gis:${h2gisVersion}")
+ javaRestTestRuntimeOnly("org.orbisgis:h2gis-api:${h2gisVersion}")
+ javaRestTestRuntimeOnly("org.orbisgis:h2gis-utilities:${h2gisVersion}")
+ javaRestTestRuntimeOnly("org.orbisgis:cts:1.5.2")
- javaRestTestRuntimeOnly project(path: xpackModule('sql:jdbc'))
- javaRestTestRuntimeOnly project(':x-pack:plugin:sql:sql-client')
+ javaRestTestRuntimeOnly project(path: xpackModule('sql:jdbc'))
+ javaRestTestRuntimeOnly project(':x-pack:plugin:sql:sql-client')
- // CLI testing dependencies
- javaRestTestRuntimeOnly project(path: xpackModule('sql:sql-cli'))
- javaRestTestRuntimeOnly(project(':x-pack:plugin:sql:sql-action')) {
- transitive = false
- }
+ // CLI testing dependencies
+ javaRestTestRuntimeOnly project(path: xpackModule('sql:sql-cli'))
+ javaRestTestRuntimeOnly(project(':x-pack:plugin:sql:sql-action')) {
+ transitive = false
+ }
- javaRestTestRuntimeOnly("org.jline:jline-terminal-jna:${jlineVersion}") {
- exclude group: "net.java.dev.jna"
- }
- javaRestTestRuntimeOnly "org.jline:jline-terminal:${jlineVersion}"
- javaRestTestRuntimeOnly "org.jline:jline-reader:${jlineVersion}"
- javaRestTestRuntimeOnly "org.jline:jline-style:${jlineVersion}"
+ javaRestTestRuntimeOnly("org.jline:jline-terminal-jna:${jlineVersion}") {
+ exclude group: "net.java.dev.jna"
+ }
+ javaRestTestRuntimeOnly "org.jline:jline-terminal:${jlineVersion}"
+ javaRestTestRuntimeOnly "org.jline:jline-reader:${jlineVersion}"
+ javaRestTestRuntimeOnly "org.jline:jline-style:${jlineVersion}"
- javaRestTestRuntimeOnly "net.java.dev.jna:jna:${versions.jna}"
+ javaRestTestRuntimeOnly "net.java.dev.jna:jna:${versions.jna}"
- // spatial dependency
- javaRestTestRuntimeOnly project(path: xpackModule('spatial'))
- javaRestTestRuntimeOnly project(path: ':modules:legacy-geo')
+ // spatial dependency
+ javaRestTestRuntimeOnly project(path: xpackModule('spatial'))
+ javaRestTestRuntimeOnly project(path: ':modules:legacy-geo')
- javaRestTestRuntimeOnly project(path: ':modules:rest-root')
+ javaRestTestRuntimeOnly project(path: ':modules:rest-root')
- javaRestTestRuntimeOnly "org.slf4j:slf4j-api:1.7.25"
- }
+ javaRestTestRuntimeOnly "org.slf4j:slf4j-api:1.7.25"
+ }
}
}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
index b42ae29e257f0..669f5ae169c3b 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
@@ -1,3 +1,8 @@
+dependencies {
+ javaRestTestImplementation project(path: xpackModule('ql:test-fixtures'))
+}
+
+/*
import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
@@ -53,4 +58,10 @@ tasks.named("javaRestTest").configure {
nonInputProperties.systemProperty 'tests.rest.cluster.multi.password', "x-pack-test-password"
}
}
+*/
+
tasks.named("check").configure {dependsOn("javaRestTest") } // run these tests as part of the "check" task
+
+dependencies {
+ clusterPlugins project(':x-pack:qa:freeze-plugin')
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
index 8807eb679cc27..5249a3d906b3d 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
@@ -36,7 +36,7 @@ static void setupIndex() throws IOException {
@AfterClass
static void cleanupIndex() throws IOException {
- provisioningClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
+ legacyProvisioningClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
}
public void testJdbcSetCatalog() throws Exception {
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
index b56cde303446e..97f19835f3ab1 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
@@ -6,13 +6,101 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
+import org.apache.http.HttpHost;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.common.settings.SecureString;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.util.concurrent.ThreadContext;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase;
+import org.junit.ClassRule;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.io.IOException;
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName;
public class RestSqlIT extends RestSqlTestCase {
+ @ClassRule
+ public static TestClusterWithRemote clusterAndRemote = new TestClusterWithRemote();
+
+ public static class TestClusterWithRemote implements TestRule {
+ private ElasticsearchCluster cluster;
+ private final ElasticsearchCluster remote = SqlTestRemoteCluster.getCluster();
+
+ public Statement apply(Statement base, Description description) {
+ Statement startCluster = new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ // Remote address will look like [::1]:12345 - elasticsearch.yml does not like the square brackets.
+ String remoteAddress = remote.getTransportEndpoint(0).replaceAll("\\[|\\]", "");
+ cluster = SqlTestCluster.getCluster(remoteAddress);
+ cluster.apply(base, description).evaluate();
+ }
+ };
+
+ return remote.apply(startCluster, null);
+ }
+
+ public ElasticsearchCluster cluster() {
+ return cluster;
+ }
+
+ public Settings clusterAuthSettings() {
+ return clientAuthSettings();
+ }
+
+ public ElasticsearchCluster remote() {
+ return remote;
+ }
+
+ public Settings remoteAuthSettings() {
+ return clientAuthSettings();
+ }
+
+ /**
+ * Auth settings for both the cluster and the remote.
+ *
+ * @return
+ */
+ private static Settings clientAuthSettings() {
+ final String value = basicAuthHeaderValue("test_user", new SecureString("x-pack-test-password".toCharArray()));
+ return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
+ }
+ }
+
+ @Override
+ protected String getTestRestCluster() {
+ return clusterAndRemote.cluster().getHttpAddress(0);
+ }
+
+ @Override
+ protected Settings restClientSettings() {
+ return clusterAndRemote.clusterAuthSettings();
+ }
+
+ @Override
+ protected RestClient provisioningClient() {
+ String crossClusterHost = clusterAndRemote.remote().getHttpAddress(0);
+ int portSeparator = crossClusterHost.lastIndexOf(':');
+ if (portSeparator < 0) {
+ throw new IllegalArgumentException("Illegal cluster url [" + crossClusterHost + "]");
+ }
+ String host = crossClusterHost.substring(0, portSeparator);
+ int port = Integer.parseInt(crossClusterHost.substring(portSeparator + 1));
+ HttpHost[] remoteHttpHosts = new HttpHost[] { new HttpHost(host, port) };
+
+ try {
+ return clientBuilder(clusterAndRemote.remoteAuthSettings(), remoteHttpHosts);
+ } catch (IOException e) {
+ // TODO: create and close the client correctly using a test rule.
+ throw new RuntimeException(e);
+ }
+ }
- public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster"; // gradle defined
+ public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
@Override
protected String indexPattern(String pattern) {
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
new file mode 100644
index 0000000000000..fb2db4f79abaf
--- /dev/null
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
+
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
+import org.elasticsearch.test.cluster.local.distribution.DistributionType;
+
+public class SqlTestCluster {
+ public static ElasticsearchCluster getCluster(String remoteAddress) {
+
+ return ElasticsearchCluster.local()
+ .distribution(DistributionType.DEFAULT)
+ .name("javaRestTest")
+ .setting("cluster.name", "javaRestTest")
+ .setting("xpack.ml.enabled", "false")
+ .setting("xpack.watcher.enabled", "false")
+ .setting("cluster.remote.my_remote_cluster.seeds", remoteAddress)
+ .setting("cluster.remote.connections_per_cluster", "1")
+ .setting("xpack.security.enabled", "true")
+ .setting("xpack.license.self_generated.type", "trial")
+ .setting("xpack.security.autoconfiguration.enabled", "false")
+ .user("test_user", "x-pack-test-password")
+ .plugin(":x-pack:qa:freeze-plugin")
+ .build();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
new file mode 100644
index 0000000000000..ec72feccb7a66
--- /dev/null
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
+
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
+import org.elasticsearch.test.cluster.local.distribution.DistributionType;
+
+public class SqlTestRemoteCluster {
+ public static ElasticsearchCluster getCluster() {
+ return ElasticsearchCluster.local()
+ .distribution(DistributionType.DEFAULT)
+ .name("remote-cluster")
+ .setting("cluster.name", "remote-cluster")
+ .setting("node.roles", "[data,ingest,master]")
+ .setting("xpack.ml.enabled", "false")
+ .setting("xpack.watcher.enabled", "false")
+ .setting("xpack.security.enabled", "true")
+ .setting("xpack.license.self_generated.type", "trial")
+ .setting("xpack.security.autoconfiguration.enabled", "false")
+ .user("test_user", "x-pack-test-password")
+ .plugin(":x-pack:qa:freeze-plugin")
+ .build();
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
index e2fd7659fc7e7..febfaee077c67 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
@@ -17,6 +17,7 @@
import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcAssert.assertResultSets;
import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.createDataStream;
import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.deleteDataStream;
+import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.legacyProvisioningClient;
/**
* Tests for our implementation of {@link DatabaseMetaData}.
@@ -129,7 +130,7 @@ public void testGetDataStreamViewByName() throws IOException, SQLException {
private void expectDataStreamTable(String dataStreamName, String tableNamePattern, String[] types) throws SQLException, IOException {
try {
- createDataStream(dataStreamName);
+ createDataStream(dataStreamName, legacyProvisioningClient());
try (Connection es = esJdbc(); ResultSet rs = es.getMetaData().getTables("%", "%", tableNamePattern, types)) {
assertTrue(rs.next());
assertEquals(dataStreamName, rs.getString(3));
@@ -137,7 +138,7 @@ private void expectDataStreamTable(String dataStreamName, String tableNamePatter
assertFalse(rs.next());
}
} finally {
- deleteDataStream(dataStreamName);
+ deleteDataStream(dataStreamName, legacyProvisioningClient());
}
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
index 9123282f22195..878258424b4f0 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
@@ -83,10 +83,10 @@ public static void index(String index, String documentId, CheckedConsumer body) throws IOException {
+ protected void updateMapping(String index, CheckedConsumer body) throws IOException {
Request request = new Request("PUT", "/" + index + "/_mapping");
XContentBuilder updateMapping = JsonXContent.contentBuilder().startObject();
updateMapping.startObject("properties");
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/SysColumnsTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/SysColumnsTestCase.java
index 8239f9d2fc148..e2e3b1fe45af8 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/SysColumnsTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/SysColumnsTestCase.java
@@ -419,7 +419,7 @@ public void testMultiIndicesMultiAlias() throws Exception {
);
}
- private static void createIndexWithMapping(String indexName, CheckedConsumer mapping) throws Exception {
+ private void createIndexWithMapping(String indexName, CheckedConsumer mapping) throws Exception {
createIndexWithSettingsAndMappings(indexName);
updateMapping(indexName, mapping);
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/BaseRestSqlTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/BaseRestSqlTestCase.java
index d6fd9b23860fc..bd43d3d651e52 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/BaseRestSqlTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/BaseRestSqlTestCase.java
@@ -13,6 +13,7 @@
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.Tuple;
@@ -221,24 +222,32 @@ protected void deleteTestIndex() throws IOException {
deleteIndexWithProvisioningClient(TEST_INDEX);
}
- protected static void deleteIndexWithProvisioningClient(String name) throws IOException {
+ protected void deleteIndexWithProvisioningClient(String name) throws IOException {
deleteIndex(provisioningClient(), name);
}
- public static void createDataStream(String dataStreamName) throws IOException {
+ public static void createDataStream(String dataStreamName, RestClient provisioningClient) throws IOException {
Request request = new Request("PUT", "/_index_template/" + DATA_STREAM_TEMPLATE + "-" + dataStreamName);
request.setJsonEntity("{\"index_patterns\": [\"" + dataStreamName + "*\"], \"data_stream\": {}}");
- assertOK(provisioningClient().performRequest(request));
+ assertOK(provisioningClient.performRequest(request));
request = new Request("PUT", "/_data_stream/" + dataStreamName);
- assertOK(provisioningClient().performRequest(request));
+ assertOK(provisioningClient.performRequest(request));
}
- public static void deleteDataStream(String dataStreamName) throws IOException {
+ public void createDataStream(String dataStreamName) throws IOException {
+ createDataStream(dataStreamName, provisioningClient());
+ }
+
+ public static void deleteDataStream(String dataStreamName, RestClient provisioningClient) throws IOException {
Request request = new Request("DELETE", "_data_stream/" + dataStreamName);
- provisioningClient().performRequest(request);
+ provisioningClient.performRequest(request);
request = new Request("DELETE", "/_index_template/" + DATA_STREAM_TEMPLATE + "-" + dataStreamName);
- provisioningClient().performRequest(request);
+ provisioningClient.performRequest(request);
+ }
+
+ public void deleteDataStream(String dataStreamName) throws IOException {
+ deleteDataStream(dataStreamName, provisioningClient());
}
public static RequestObjectBuilder query(String query) {
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
index 1dfbe6ef34cce..9861a2ae2ef06 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
@@ -24,13 +24,12 @@
import static org.elasticsearch.common.Strings.hasText;
public abstract class RemoteClusterAwareSqlRestTestCase extends ESRestTestCase {
-
private static final long CLIENT_TIMEOUT = 40L; // upped from 10s to accommodate for max measured throughput decline
// client used for loading data on a remote cluster only.
private static RestClient remoteClient;
- // gradle defines
+ // gradle defines for legacy test framework
public static final String AUTH_USER = System.getProperty("tests.rest.cluster.multi.user");
public static final String AUTH_PASS = System.getProperty("tests.rest.cluster.multi.password");
@@ -77,10 +76,15 @@ protected static TimeValue timeout() {
return TimeValue.timeValueSeconds(CLIENT_TIMEOUT);
}
+ // When using the legacy test framework, returns a client to the remote cluster if it exists - otherwise returns client().
+ public static RestClient legacyProvisioningClient() {
+ return remoteClient == null ? client() : remoteClient;
+ }
+
// returned client is used to load the test data, either in the local cluster (for rest/javaRestTests) or a remote one (for
// multi-cluster). note: the client()/adminClient() will always connect to the local cluster.
- protected static RestClient provisioningClient() {
- return remoteClient == null ? client() : remoteClient;
+ protected RestClient provisioningClient() {
+ return legacyProvisioningClient();
}
@Override
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java
index 81cc54db19669..fb92ac096fc36 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java
@@ -1434,7 +1434,7 @@ private void executeQueryWithNextPage(String format, String expectedHeader, Stri
assertEquals(0, getNumberOfSearchContexts(provisioningClient(), "test"));
}
- private static void bulkLoadTestData(int count) throws IOException {
+ private void bulkLoadTestData(int count) throws IOException {
Request request = new Request("POST", "/test/_bulk");
request.addParameter("refresh", "true");
StringBuilder bulk = new StringBuilder();
@@ -1801,7 +1801,7 @@ public void testDataStreamInShowTablesFiltered() throws IOException {
expectDataStreamInShowTables(dataStreamName, "SHOW TABLES \\\"" + dataStreamName + "*\\\"");
}
- private static void expectDataStreamInShowTables(String dataStreamName, String sql) throws IOException {
+ private void expectDataStreamInShowTables(String dataStreamName, String sql) throws IOException {
try {
createDataStream(dataStreamName);
From 6a873f437c9ec60a02e7f4f538810a83abd91cdc Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Sat, 11 Nov 2023 11:10:19 +0100
Subject: [PATCH 09/18] Properly close remote client
---
.../RestSqlIT.java | 66 ++++++++++++-------
1 file changed, 43 insertions(+), 23 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
index 97f19835f3ab1..8f505efa6a524 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
@@ -11,6 +11,7 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
+import org.elasticsearch.core.IOUtils;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase;
import org.junit.ClassRule;
@@ -29,41 +30,74 @@ public class RestSqlIT extends RestSqlTestCase {
public static class TestClusterWithRemote implements TestRule {
private ElasticsearchCluster cluster;
private final ElasticsearchCluster remote = SqlTestRemoteCluster.getCluster();
+ private RestClient remoteClient;
public Statement apply(Statement base, Description description) {
- Statement startCluster = new Statement() {
+ return remote.apply(startRemoteClient(startCluster(base)), null);
+ }
+
+ private Statement startRemoteClient(Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try {
+ remoteClient = initRemoteClient();
+ base.evaluate();
+ }
+ finally {
+ IOUtils.close(remoteClient);
+ }
+ }
+ };
+ }
+
+ private Statement startCluster(Statement base) {
+ return new Statement() {
@Override
public void evaluate() throws Throwable {
// Remote address will look like [::1]:12345 - elasticsearch.yml does not like the square brackets.
String remoteAddress = remote.getTransportEndpoint(0).replaceAll("\\[|\\]", "");
cluster = SqlTestCluster.getCluster(remoteAddress);
- cluster.apply(base, description).evaluate();
+ cluster.apply(base, null).evaluate();
}
};
-
- return remote.apply(startCluster, null);
}
public ElasticsearchCluster cluster() {
return cluster;
}
+ public ElasticsearchCluster remote() {
+ return remote;
+ }
+
public Settings clusterAuthSettings() {
return clientAuthSettings();
}
- public ElasticsearchCluster remote() {
- return remote;
+ public RestClient remoteClient() {
+ return remoteClient;
}
public Settings remoteAuthSettings() {
return clientAuthSettings();
}
+ private RestClient initRemoteClient() throws IOException {
+ String crossClusterHost = remote.getHttpAddress(0);
+ int portSeparator = crossClusterHost.lastIndexOf(':');
+ if (portSeparator < 0) {
+ throw new IllegalArgumentException("Illegal cluster url [" + crossClusterHost + "]");
+ }
+ String host = crossClusterHost.substring(0, portSeparator);
+ int port = Integer.parseInt(crossClusterHost.substring(portSeparator + 1));
+ HttpHost[] remoteHttpHosts = new HttpHost[] { new HttpHost(host, port) };
+
+ return clientBuilder(clientAuthSettings(), remoteHttpHosts);
+ }
+
/**
* Auth settings for both the cluster and the remote.
- *
- * @return
*/
private static Settings clientAuthSettings() {
final String value = basicAuthHeaderValue("test_user", new SecureString("x-pack-test-password".toCharArray()));
@@ -83,21 +117,7 @@ protected Settings restClientSettings() {
@Override
protected RestClient provisioningClient() {
- String crossClusterHost = clusterAndRemote.remote().getHttpAddress(0);
- int portSeparator = crossClusterHost.lastIndexOf(':');
- if (portSeparator < 0) {
- throw new IllegalArgumentException("Illegal cluster url [" + crossClusterHost + "]");
- }
- String host = crossClusterHost.substring(0, portSeparator);
- int port = Integer.parseInt(crossClusterHost.substring(portSeparator + 1));
- HttpHost[] remoteHttpHosts = new HttpHost[] { new HttpHost(host, port) };
-
- try {
- return clientBuilder(clusterAndRemote.remoteAuthSettings(), remoteHttpHosts);
- } catch (IOException e) {
- // TODO: create and close the client correctly using a test rule.
- throw new RuntimeException(e);
- }
+ return clusterAndRemote.remoteClient();
}
public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
From 44773e8f178fb28dcd4e927c3920cb2098828014 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Sat, 11 Nov 2023 11:50:10 +0100
Subject: [PATCH 10/18] Refactor
---
.../RestSqlIT.java | 97 +------------
.../SqlTestCluster.java | 31 ----
.../SqlTestClusterWithRemote.java | 133 ++++++++++++++++++
.../SqlTestRemoteCluster.java | 29 ----
.../sql/qa/multi_node/SqlTestCluster.java | 2 +-
.../sql/qa/single_node/SqlTestCluster.java | 2 +-
.../RemoteClusterAwareSqlRestTestCase.java | 2 +-
7 files changed, 140 insertions(+), 156 deletions(-)
delete mode 100644 x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
create mode 100644 x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
delete mode 100644 x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
index 8f505efa6a524..efa1bf4112ee6 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
@@ -6,104 +6,17 @@
*/
package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
-import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
-import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.util.concurrent.ThreadContext;
-import org.elasticsearch.core.IOUtils;
-import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase;
import org.junit.ClassRule;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import java.io.IOException;
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.remoteClusterName;
public class RestSqlIT extends RestSqlTestCase {
@ClassRule
- public static TestClusterWithRemote clusterAndRemote = new TestClusterWithRemote();
-
- public static class TestClusterWithRemote implements TestRule {
- private ElasticsearchCluster cluster;
- private final ElasticsearchCluster remote = SqlTestRemoteCluster.getCluster();
- private RestClient remoteClient;
-
- public Statement apply(Statement base, Description description) {
- return remote.apply(startRemoteClient(startCluster(base)), null);
- }
-
- private Statement startRemoteClient(Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- try {
- remoteClient = initRemoteClient();
- base.evaluate();
- }
- finally {
- IOUtils.close(remoteClient);
- }
- }
- };
- }
-
- private Statement startCluster(Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- // Remote address will look like [::1]:12345 - elasticsearch.yml does not like the square brackets.
- String remoteAddress = remote.getTransportEndpoint(0).replaceAll("\\[|\\]", "");
- cluster = SqlTestCluster.getCluster(remoteAddress);
- cluster.apply(base, null).evaluate();
- }
- };
- }
-
- public ElasticsearchCluster cluster() {
- return cluster;
- }
-
- public ElasticsearchCluster remote() {
- return remote;
- }
-
- public Settings clusterAuthSettings() {
- return clientAuthSettings();
- }
-
- public RestClient remoteClient() {
- return remoteClient;
- }
-
- public Settings remoteAuthSettings() {
- return clientAuthSettings();
- }
-
- private RestClient initRemoteClient() throws IOException {
- String crossClusterHost = remote.getHttpAddress(0);
- int portSeparator = crossClusterHost.lastIndexOf(':');
- if (portSeparator < 0) {
- throw new IllegalArgumentException("Illegal cluster url [" + crossClusterHost + "]");
- }
- String host = crossClusterHost.substring(0, portSeparator);
- int port = Integer.parseInt(crossClusterHost.substring(portSeparator + 1));
- HttpHost[] remoteHttpHosts = new HttpHost[] { new HttpHost(host, port) };
-
- return clientBuilder(clientAuthSettings(), remoteHttpHosts);
- }
-
- /**
- * Auth settings for both the cluster and the remote.
- */
- private static Settings clientAuthSettings() {
- final String value = basicAuthHeaderValue("test_user", new SecureString("x-pack-test-password".toCharArray()));
- return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
- }
- }
+ public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote();
@Override
protected String getTestRestCluster() {
@@ -120,14 +33,12 @@ protected RestClient provisioningClient() {
return clusterAndRemote.remoteClient();
}
- public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
-
@Override
protected String indexPattern(String pattern) {
if (randomBoolean()) {
- return buildRemoteIndexName(REMOTE_CLUSTER_NAME, pattern);
+ return buildRemoteIndexName(remoteClusterName(), pattern);
} else {
- String cluster = REMOTE_CLUSTER_NAME.substring(0, randomIntBetween(0, REMOTE_CLUSTER_NAME.length())) + "*";
+ String cluster = remoteClusterName().substring(0, randomIntBetween(0, remoteClusterName().length())) + "*";
if (pattern.startsWith("\\\"") && pattern.endsWith("\\\"") && pattern.length() > 4) {
pattern = pattern.substring(2, pattern.length() - 2);
}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
deleted file mode 100644
index fb2db4f79abaf..0000000000000
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestCluster.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-
-package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
-
-import org.elasticsearch.test.cluster.ElasticsearchCluster;
-import org.elasticsearch.test.cluster.local.distribution.DistributionType;
-
-public class SqlTestCluster {
- public static ElasticsearchCluster getCluster(String remoteAddress) {
-
- return ElasticsearchCluster.local()
- .distribution(DistributionType.DEFAULT)
- .name("javaRestTest")
- .setting("cluster.name", "javaRestTest")
- .setting("xpack.ml.enabled", "false")
- .setting("xpack.watcher.enabled", "false")
- .setting("cluster.remote.my_remote_cluster.seeds", remoteAddress)
- .setting("cluster.remote.connections_per_cluster", "1")
- .setting("xpack.security.enabled", "true")
- .setting("xpack.license.self_generated.type", "trial")
- .setting("xpack.security.autoconfiguration.enabled", "false")
- .user("test_user", "x-pack-test-password")
- .plugin(":x-pack:qa:freeze-plugin")
- .build();
- }
-}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
new file mode 100644
index 0000000000000..086478cceac44
--- /dev/null
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
+
+import org.apache.http.HttpHost;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.common.settings.SecureString;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.util.concurrent.ThreadContext;
+import org.elasticsearch.core.IOUtils;
+import org.elasticsearch.test.cluster.ElasticsearchCluster;
+import org.elasticsearch.test.cluster.local.distribution.DistributionType;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.io.IOException;
+
+import static org.elasticsearch.test.rest.ESRestTestCase.basicAuthHeaderValue;
+import static org.elasticsearch.xpack.sql.qa.rest.RemoteClusterAwareSqlRestTestCase.clientBuilder;
+
+public class SqlTestClusterWithRemote implements TestRule {
+ private static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
+ private static final String USER_NAME = "test_user";
+ private static final String PASSWORD = "x-pack-test-password";
+
+ private static ElasticsearchCluster getCluster(String remoteAddress) {
+ return ElasticsearchCluster.local()
+ .distribution(DistributionType.DEFAULT)
+ .name("javaRestTest")
+ .setting("xpack.ml.enabled", "false")
+ .setting("xpack.watcher.enabled", "false")
+ .setting("cluster.remote." + REMOTE_CLUSTER_NAME + ".seeds", remoteAddress)
+ .setting("cluster.remote.connections_per_cluster", "1")
+ .setting("xpack.security.enabled", "true")
+ .setting("xpack.license.self_generated.type", "trial")
+ .setting("xpack.security.autoconfiguration.enabled", "false")
+ .user(USER_NAME, PASSWORD)
+ .plugin(":x-pack:qa:freeze-plugin")
+ .build();
+ }
+
+ private static ElasticsearchCluster getRemoteCluster() {
+ return ElasticsearchCluster.local()
+ .distribution(DistributionType.DEFAULT)
+ .name("remote-cluster")
+ .setting("node.roles", "[data,ingest,master]")
+ .setting("xpack.ml.enabled", "false")
+ .setting("xpack.watcher.enabled", "false")
+ .setting("xpack.security.enabled", "true")
+ .setting("xpack.license.self_generated.type", "trial")
+ .setting("xpack.security.autoconfiguration.enabled", "false")
+ .user(USER_NAME, PASSWORD)
+ .plugin(":x-pack:qa:freeze-plugin")
+ .build();
+ }
+
+ /**
+ * Auth settings for both the cluster and the remote.
+ */
+ private static Settings clientAuthSettings() {
+ final String value = basicAuthHeaderValue(USER_NAME, new SecureString(PASSWORD.toCharArray()));
+ return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
+ }
+
+ private ElasticsearchCluster cluster;
+ private final ElasticsearchCluster remote = getRemoteCluster();
+ private RestClient remoteClient;
+
+ public static String remoteClusterName() {
+ return REMOTE_CLUSTER_NAME;
+ }
+
+ public Statement apply(Statement base, Description description) {
+ return remote.apply(startRemoteClient(startCluster(base)), null);
+ }
+
+ public ElasticsearchCluster cluster() {
+ return cluster;
+ }
+
+ public Settings clusterAuthSettings() {
+ return clientAuthSettings();
+ }
+
+ public RestClient remoteClient() {
+ return remoteClient;
+ }
+
+ private Statement startCluster(Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ // Remote address will look like [::1]:12345 - elasticsearch.yml does not like the square brackets.
+ String remoteAddress = remote.getTransportEndpoint(0).replaceAll("\\[|\\]", "");
+ cluster = getCluster(remoteAddress);
+ cluster.apply(base, null).evaluate();
+ }
+ };
+ }
+
+ private Statement startRemoteClient(Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try {
+ remoteClient = initRemoteClient();
+ base.evaluate();
+ } finally {
+ IOUtils.close(remoteClient);
+ }
+ }
+ };
+ }
+
+ private RestClient initRemoteClient() throws IOException {
+ String crossClusterHost = remote.getHttpAddress(0);
+ int portSeparator = crossClusterHost.lastIndexOf(':');
+ if (portSeparator < 0) {
+ throw new IllegalArgumentException("Illegal cluster url [" + crossClusterHost + "]");
+ }
+ String host = crossClusterHost.substring(0, portSeparator);
+ int port = Integer.parseInt(crossClusterHost.substring(portSeparator + 1));
+ HttpHost[] remoteHttpHosts = new HttpHost[] { new HttpHost(host, port) };
+
+ return clientBuilder(clientAuthSettings(), remoteHttpHosts);
+ }
+}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
deleted file mode 100644
index ec72feccb7a66..0000000000000
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestRemoteCluster.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0; you may not use this file except in compliance with the Elastic License
- * 2.0.
- */
-
-package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
-
-import org.elasticsearch.test.cluster.ElasticsearchCluster;
-import org.elasticsearch.test.cluster.local.distribution.DistributionType;
-
-public class SqlTestRemoteCluster {
- public static ElasticsearchCluster getCluster() {
- return ElasticsearchCluster.local()
- .distribution(DistributionType.DEFAULT)
- .name("remote-cluster")
- .setting("cluster.name", "remote-cluster")
- .setting("node.roles", "[data,ingest,master]")
- .setting("xpack.ml.enabled", "false")
- .setting("xpack.watcher.enabled", "false")
- .setting("xpack.security.enabled", "true")
- .setting("xpack.license.self_generated.type", "trial")
- .setting("xpack.security.autoconfiguration.enabled", "false")
- .user("test_user", "x-pack-test-password")
- .plugin(":x-pack:qa:freeze-plugin")
- .build();
- }
-}
diff --git a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
index e92778179cc9b..9859be524ce6a 100644
--- a/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
+++ b/x-pack/plugin/sql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_node/SqlTestCluster.java
@@ -15,7 +15,7 @@ public static ElasticsearchCluster getCluster() {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.nodes(2)
- .setting("cluster.name", "javaRestTest")
+ .name("javaRestTest")
.setting("xpack.ml.enabled", "false")
.setting("xpack.watcher.enabled", "false")
.setting("xpack.security.enabled", "false")
diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
index 44f2e46699956..bfcd1671e4d39 100644
--- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
+++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java
@@ -14,7 +14,7 @@ public class SqlTestCluster {
public static ElasticsearchCluster getCluster() {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
- .setting("cluster.name", "javaRestTest")
+ .name("javaRestTest")
.setting("xpack.ml.enabled", "false")
.setting("xpack.watcher.enabled", "false")
.setting("xpack.security.enabled", "false")
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
index 9861a2ae2ef06..da3f2e2b80a8e 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
@@ -58,7 +58,7 @@ public static void closeRemoteClients() throws IOException {
}
}
- protected static RestClient clientBuilder(Settings settings, HttpHost[] hosts) throws IOException {
+ public static RestClient clientBuilder(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
doConfigureClient(builder, settings);
From f4946762dc022bacdec13ca01f5218a2b1803a82 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 09:34:58 +0100
Subject: [PATCH 11/18] Remove obsolete gradle cluster conf
---
.../multi-cluster-with-security/build.gradle | 58 -------------------
1 file changed, 58 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
index 669f5ae169c3b..6c14377b07276 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
@@ -2,64 +2,6 @@ dependencies {
javaRestTestImplementation project(path: xpackModule('ql:test-fixtures'))
}
-/*
-import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
-import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
-
-apply plugin: 'elasticsearch.legacy-java-rest-test'
-
-dependencies {
- javaRestTestImplementation project(path: xpackModule('ql:test-fixtures'))
-}
-
-def remoteClusterReg = testClusters.register('remote-cluster') {
- testDistribution = 'DEFAULT'
- setting 'node.roles', '[data,ingest,master]'
- setting 'xpack.ml.enabled', 'false'
- setting 'xpack.watcher.enabled', 'false'
- setting 'xpack.security.enabled', 'true'
- setting 'xpack.license.self_generated.type', 'trial'
- setting 'xpack.security.autoconfiguration.enabled', 'false'
-
- user username: "test_user", password: "x-pack-test-password"
- plugin ':x-pack:qa:freeze-plugin'
-}
-
-def javaRestTestClusterReg = testClusters.register('javaRestTest') {
- testDistribution = 'DEFAULT'
- setting 'xpack.ml.enabled', 'false'
- setting 'xpack.watcher.enabled', 'false'
- setting 'cluster.remote.my_remote_cluster.seeds', {
- remoteClusterReg.get().getAllTransportPortURI().collect { "\"$it\"" }.toString()
- }, IGNORE_VALUE
- setting 'cluster.remote.connections_per_cluster', "1"
- setting 'xpack.security.enabled', 'true'
- setting 'xpack.license.self_generated.type', 'trial'
- setting 'xpack.security.autoconfiguration.enabled', 'false'
-
- user username: "test_user", password: "x-pack-test-password"
- plugin ':x-pack:qa:freeze-plugin'
-}
-
-tasks.register("startRemoteCluster", DefaultTestClustersTask.class) {
- useCluster remoteClusterReg
- doLast {
- "Starting remote cluster before integ tests and integ test cluster is started"
- }
-}
-
-tasks.named("javaRestTest").configure {
- dependsOn 'startRemoteCluster'
- useCluster remoteClusterReg
- doFirst {
- nonInputProperties.systemProperty 'tests.rest.cluster.remote.host', remoteClusterReg.map(c->c.getAllHttpSocketURI().get(0))
- // credentials for both local and remote clusters
- nonInputProperties.systemProperty 'tests.rest.cluster.multi.user', "test_user"
- nonInputProperties.systemProperty 'tests.rest.cluster.multi.password', "x-pack-test-password"
- }
-}
-*/
-
tasks.named("check").configure {dependsOn("javaRestTest") } // run these tests as part of the "check" task
dependencies {
From 09cb6b4f8049199ee66f40cbb3b20fdc405a31d9 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 11:16:30 +0100
Subject: [PATCH 12/18] Make JdbcCatalogIT work
---
.../JdbcCatalogIT.java | 49 +++++++++++++++----
.../RestSqlIT.java | 8 +--
.../SqlTestClusterWithRemote.java | 18 +++----
.../sql/qa/jdbc/DatabaseMetaDataTestCase.java | 5 +-
.../sql/qa/jdbc/JdbcIntegrationTestCase.java | 23 +++++++--
.../RemoteClusterAwareSqlRestTestCase.java | 15 ++++--
6 files changed, 82 insertions(+), 36 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
index 5249a3d906b3d..46c9bed65b45b 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
@@ -8,9 +8,12 @@
package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
import org.elasticsearch.client.Request;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import java.io.IOException;
import java.sql.Connection;
@@ -18,25 +21,51 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
+import java.util.Properties;
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.LOCAL_CLUSTER_NAME;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.PASSWORD;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.REMOTE_CLUSTER_ALIAS;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.USER_NAME;
public class JdbcCatalogIT extends JdbcIntegrationTestCase {
+ @ClassRule
+ public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote();
- // gradle defines
- public static final String LOCAL_CLUSTER_NAME = "javaRestTest";
- public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
+ @Override
+ protected String getTestRestCluster() {
+ return clusterAndRemote.cluster().getHttpAddresses();
+ }
+
+ @Override
+ protected Settings restClientSettings() {
+ return clusterAndRemote.clusterAuthSettings();
+ }
+
+ @Override
+ protected RestClient provisioningClient() {
+ return clusterAndRemote.remoteClient();
+ }
+
+ @Override
+ protected Properties connectionProperties() {
+ Properties connectionProperties = super.connectionProperties();
+ connectionProperties.put("user", USER_NAME);
+ connectionProperties.put("password", PASSWORD);
+ return connectionProperties;
+ }
private static final String INDEX_NAME = "test";
@BeforeClass
static void setupIndex() throws IOException {
- index(INDEX_NAME, body -> body.field("zero", 0));
+ index(INDEX_NAME, body -> body.field("zero", 0), clusterAndRemote.remoteClient());
}
@AfterClass
static void cleanupIndex() throws IOException {
- legacyProvisioningClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
+ clusterAndRemote.remoteClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
}
public void testJdbcSetCatalog() throws Exception {
@@ -45,7 +74,7 @@ public void testJdbcSetCatalog() throws Exception {
SQLException ex = expectThrows(SQLException.class, ps::executeQuery);
assertTrue(ex.getMessage().contains("Unknown index [" + INDEX_NAME + "]"));
- String catalog = REMOTE_CLUSTER_NAME.substring(0, randomIntBetween(0, REMOTE_CLUSTER_NAME.length())) + "*";
+ String catalog = REMOTE_CLUSTER_ALIAS.substring(0, randomIntBetween(0, REMOTE_CLUSTER_ALIAS.length())) + "*";
es.setCatalog(catalog);
assertEquals(catalog, es.getCatalog());
@@ -62,7 +91,7 @@ public void testJdbcSetCatalog() throws Exception {
public void testQueryCatalogPrecedence() throws Exception {
try (Connection es = esJdbc()) {
- PreparedStatement ps = es.prepareStatement("SELECT count(*) FROM " + buildRemoteIndexName(REMOTE_CLUSTER_NAME, INDEX_NAME));
+ PreparedStatement ps = es.prepareStatement("SELECT count(*) FROM " + buildRemoteIndexName(REMOTE_CLUSTER_ALIAS, INDEX_NAME));
es.setCatalog(LOCAL_CLUSTER_NAME);
ResultSet rs = ps.executeQuery();
assertTrue(rs.next());
@@ -73,7 +102,7 @@ public void testQueryCatalogPrecedence() throws Exception {
public void testQueryWithQualifierAndSetCatalog() throws Exception {
try (Connection es = esJdbc()) {
PreparedStatement ps = es.prepareStatement("SELECT " + INDEX_NAME + ".zero FROM " + INDEX_NAME);
- es.setCatalog(REMOTE_CLUSTER_NAME);
+ es.setCatalog(REMOTE_CLUSTER_ALIAS);
ResultSet rs = ps.executeQuery();
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
@@ -84,7 +113,7 @@ public void testQueryWithQualifierAndSetCatalog() throws Exception {
public void testQueryWithQualifiedFieldAndIndex() throws Exception {
try (Connection es = esJdbc()) {
PreparedStatement ps = es.prepareStatement(
- "SELECT " + INDEX_NAME + ".zero FROM " + buildRemoteIndexName(REMOTE_CLUSTER_NAME, INDEX_NAME)
+ "SELECT " + INDEX_NAME + ".zero FROM " + buildRemoteIndexName(REMOTE_CLUSTER_ALIAS, INDEX_NAME)
);
es.setCatalog(LOCAL_CLUSTER_NAME); // set, but should be ignored
ResultSet rs = ps.executeQuery();
@@ -105,7 +134,7 @@ public void testCatalogDependentCommands() throws Exception {
ResultSet rs = ps.executeQuery();
assertFalse(rs.next());
- es.setCatalog(REMOTE_CLUSTER_NAME);
+ es.setCatalog(REMOTE_CLUSTER_ALIAS);
rs = ps.executeQuery();
assertTrue(rs.next());
assertFalse(rs.next());
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
index efa1bf4112ee6..30f127333ba61 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
@@ -12,7 +12,7 @@
import org.junit.ClassRule;
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName;
-import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.remoteClusterName;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.REMOTE_CLUSTER_ALIAS;
public class RestSqlIT extends RestSqlTestCase {
@ClassRule
@@ -20,7 +20,7 @@ public class RestSqlIT extends RestSqlTestCase {
@Override
protected String getTestRestCluster() {
- return clusterAndRemote.cluster().getHttpAddress(0);
+ return clusterAndRemote.cluster().getHttpAddresses();
}
@Override
@@ -36,9 +36,9 @@ protected RestClient provisioningClient() {
@Override
protected String indexPattern(String pattern) {
if (randomBoolean()) {
- return buildRemoteIndexName(remoteClusterName(), pattern);
+ return buildRemoteIndexName(REMOTE_CLUSTER_ALIAS, pattern);
} else {
- String cluster = remoteClusterName().substring(0, randomIntBetween(0, remoteClusterName().length())) + "*";
+ String cluster = REMOTE_CLUSTER_ALIAS.substring(0, randomIntBetween(0, REMOTE_CLUSTER_ALIAS.length())) + "*";
if (pattern.startsWith("\\\"") && pattern.endsWith("\\\"") && pattern.length() > 4) {
pattern = pattern.substring(2, pattern.length() - 2);
}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
index 086478cceac44..d385d46e83ea9 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
@@ -25,17 +25,19 @@
import static org.elasticsearch.xpack.sql.qa.rest.RemoteClusterAwareSqlRestTestCase.clientBuilder;
public class SqlTestClusterWithRemote implements TestRule {
- private static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
- private static final String USER_NAME = "test_user";
- private static final String PASSWORD = "x-pack-test-password";
+ public static final String LOCAL_CLUSTER_NAME = "javaRestTest";
+ public static final String REMOTE_CLUSTER_NAME = "remote-cluster";
+ public static final String REMOTE_CLUSTER_ALIAS = "my_remote_cluster";
+ public static final String USER_NAME = "test_user";
+ public static final String PASSWORD = "x-pack-test-password";
private static ElasticsearchCluster getCluster(String remoteAddress) {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
- .name("javaRestTest")
+ .name(LOCAL_CLUSTER_NAME)
.setting("xpack.ml.enabled", "false")
.setting("xpack.watcher.enabled", "false")
- .setting("cluster.remote." + REMOTE_CLUSTER_NAME + ".seeds", remoteAddress)
+ .setting("cluster.remote." + REMOTE_CLUSTER_ALIAS + ".seeds", remoteAddress)
.setting("cluster.remote.connections_per_cluster", "1")
.setting("xpack.security.enabled", "true")
.setting("xpack.license.self_generated.type", "trial")
@@ -48,7 +50,7 @@ private static ElasticsearchCluster getCluster(String remoteAddress) {
private static ElasticsearchCluster getRemoteCluster() {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
- .name("remote-cluster")
+ .name(REMOTE_CLUSTER_NAME)
.setting("node.roles", "[data,ingest,master]")
.setting("xpack.ml.enabled", "false")
.setting("xpack.watcher.enabled", "false")
@@ -72,10 +74,6 @@ private static Settings clientAuthSettings() {
private final ElasticsearchCluster remote = getRemoteCluster();
private RestClient remoteClient;
- public static String remoteClusterName() {
- return REMOTE_CLUSTER_NAME;
- }
-
public Statement apply(Statement base, Description description) {
return remote.apply(startRemoteClient(startCluster(base)), null);
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
index febfaee077c67..7efc4b207a27c 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
@@ -17,7 +17,6 @@
import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcAssert.assertResultSets;
import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.createDataStream;
import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.deleteDataStream;
-import static org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase.legacyProvisioningClient;
/**
* Tests for our implementation of {@link DatabaseMetaData}.
@@ -130,7 +129,7 @@ public void testGetDataStreamViewByName() throws IOException, SQLException {
private void expectDataStreamTable(String dataStreamName, String tableNamePattern, String[] types) throws SQLException, IOException {
try {
- createDataStream(dataStreamName, legacyProvisioningClient());
+ createDataStream(dataStreamName, defaultProvisioningClient());
try (Connection es = esJdbc(); ResultSet rs = es.getMetaData().getTables("%", "%", tableNamePattern, types)) {
assertTrue(rs.next());
assertEquals(dataStreamName, rs.getString(3));
@@ -138,7 +137,7 @@ private void expectDataStreamTable(String dataStreamName, String tableNamePatter
assertFalse(rs.next());
}
} finally {
- deleteDataStream(dataStreamName, legacyProvisioningClient());
+ deleteDataStream(dataStreamName, defaultProvisioningClient());
}
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
index 878258424b4f0..e5a77c0630575 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java
@@ -8,6 +8,7 @@
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
+import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.CheckedConsumer;
@@ -72,18 +73,32 @@ protected Connection createConnection(Properties connectionProperties) throws SQ
return connection;
}
- public static void index(String index, CheckedConsumer body) throws IOException {
- index(index, "1", body);
+ public static void index(String index, CheckedConsumer body, RestClient provisioningClient)
+ throws IOException {
+ index(index, "1", body, provisioningClient);
}
- public static void index(String index, String documentId, CheckedConsumer body) throws IOException {
+ public void index(String index, CheckedConsumer body) throws IOException {
+ index(index, body, provisioningClient());
+ }
+
+ public static void index(
+ String index,
+ String documentId,
+ CheckedConsumer body,
+ RestClient provisioningClient
+ ) throws IOException {
Request request = new Request("PUT", "/" + index + "/_doc/" + documentId);
request.addParameter("refresh", "true");
XContentBuilder builder = JsonXContent.contentBuilder().startObject();
body.accept(builder);
builder.endObject();
request.setJsonEntity(Strings.toString(builder));
- legacyProvisioningClient().performRequest(request);
+ provisioningClient.performRequest(request);
+ }
+
+ public void index(String index, String documentId, CheckedConsumer body) throws IOException {
+ index(index, documentId, body, provisioningClient());
}
public void delete(String index, String documentId) throws IOException {
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
index da3f2e2b80a8e..7c0a876619cb1 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
@@ -76,15 +76,20 @@ protected static TimeValue timeout() {
return TimeValue.timeValueSeconds(CLIENT_TIMEOUT);
}
- // When using the legacy test framework, returns a client to the remote cluster if it exists - otherwise returns client().
- public static RestClient legacyProvisioningClient() {
+ /**
+ * Use this when using the {@code legacy-java-rest-test} plugin.
+ * @return a client to the remote cluster if it exists, otherwise a client to the local cluster
+ */
+ public static RestClient defaultProvisioningClient() {
return remoteClient == null ? client() : remoteClient;
}
- // returned client is used to load the test data, either in the local cluster (for rest/javaRestTests) or a remote one (for
- // multi-cluster). note: the client()/adminClient() will always connect to the local cluster.
+ /**
+ * Override if the test data must be provisioned on a remote cluster while not using the {@code legacy-java-rest-test} plugin.
+ * @return client to use for loading test data
+ */
protected RestClient provisioningClient() {
- return legacyProvisioningClient();
+ return defaultProvisioningClient();
}
@Override
From 342c144274460c4fa2c2acc154d025c31c263f84 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 11:30:50 +0100
Subject: [PATCH 13/18] Refactor
---
.../JdbcCatalogIT.java | 41 +++++++++++--------
.../RestSqlIT.java | 4 +-
.../SqlTestClusterWithRemote.java | 12 +++---
3 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
index 46c9bed65b45b..edd4f6c375e75 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCatalogIT.java
@@ -11,11 +11,12 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -30,12 +31,30 @@
import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.USER_NAME;
public class JdbcCatalogIT extends JdbcIntegrationTestCase {
- @ClassRule
public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote();
+ public static TestRule setupIndex = new TestRule() {
+ @Override
+ public Statement apply(Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try {
+ index(INDEX_NAME, body -> body.field("zero", 0), clusterAndRemote.getRemoteClient());
+ base.evaluate();
+ } finally {
+ clusterAndRemote.getRemoteClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
+ }
+ }
+ };
+ }
+ };
+
+ @ClassRule
+ public static RuleChain testSetup = RuleChain.outerRule(clusterAndRemote).around(setupIndex);
@Override
protected String getTestRestCluster() {
- return clusterAndRemote.cluster().getHttpAddresses();
+ return clusterAndRemote.getCluster().getHttpAddresses();
}
@Override
@@ -45,7 +64,7 @@ protected Settings restClientSettings() {
@Override
protected RestClient provisioningClient() {
- return clusterAndRemote.remoteClient();
+ return clusterAndRemote.getRemoteClient();
}
@Override
@@ -58,16 +77,6 @@ protected Properties connectionProperties() {
private static final String INDEX_NAME = "test";
- @BeforeClass
- static void setupIndex() throws IOException {
- index(INDEX_NAME, body -> body.field("zero", 0), clusterAndRemote.remoteClient());
- }
-
- @AfterClass
- static void cleanupIndex() throws IOException {
- clusterAndRemote.remoteClient().performRequest(new Request("DELETE", "/" + INDEX_NAME));
- }
-
public void testJdbcSetCatalog() throws Exception {
try (Connection es = esJdbc()) {
PreparedStatement ps = es.prepareStatement("SELECT count(*) FROM " + INDEX_NAME);
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
index 30f127333ba61..c8bb5608db1df 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/RestSqlIT.java
@@ -20,7 +20,7 @@ public class RestSqlIT extends RestSqlTestCase {
@Override
protected String getTestRestCluster() {
- return clusterAndRemote.cluster().getHttpAddresses();
+ return clusterAndRemote.getCluster().getHttpAddresses();
}
@Override
@@ -30,7 +30,7 @@ protected Settings restClientSettings() {
@Override
protected RestClient provisioningClient() {
- return clusterAndRemote.remoteClient();
+ return clusterAndRemote.getRemoteClient();
}
@Override
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
index d385d46e83ea9..a6e5baabd98f3 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/SqlTestClusterWithRemote.java
@@ -31,7 +31,7 @@ public class SqlTestClusterWithRemote implements TestRule {
public static final String USER_NAME = "test_user";
public static final String PASSWORD = "x-pack-test-password";
- private static ElasticsearchCluster getCluster(String remoteAddress) {
+ private static ElasticsearchCluster clusterSettings(String remoteAddress) {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.name(LOCAL_CLUSTER_NAME)
@@ -47,7 +47,7 @@ private static ElasticsearchCluster getCluster(String remoteAddress) {
.build();
}
- private static ElasticsearchCluster getRemoteCluster() {
+ private static ElasticsearchCluster remoteClusterSettings() {
return ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.name(REMOTE_CLUSTER_NAME)
@@ -71,14 +71,14 @@ private static Settings clientAuthSettings() {
}
private ElasticsearchCluster cluster;
- private final ElasticsearchCluster remote = getRemoteCluster();
+ private final ElasticsearchCluster remote = remoteClusterSettings();
private RestClient remoteClient;
public Statement apply(Statement base, Description description) {
return remote.apply(startRemoteClient(startCluster(base)), null);
}
- public ElasticsearchCluster cluster() {
+ public ElasticsearchCluster getCluster() {
return cluster;
}
@@ -86,7 +86,7 @@ public Settings clusterAuthSettings() {
return clientAuthSettings();
}
- public RestClient remoteClient() {
+ public RestClient getRemoteClient() {
return remoteClient;
}
@@ -96,7 +96,7 @@ private Statement startCluster(Statement base) {
public void evaluate() throws Throwable {
// Remote address will look like [::1]:12345 - elasticsearch.yml does not like the square brackets.
String remoteAddress = remote.getTransportEndpoint(0).replaceAll("\\[|\\]", "");
- cluster = getCluster(remoteAddress);
+ cluster = clusterSettings(remoteAddress);
cluster.apply(base, null).evaluate();
}
};
From 9f9350b2cbf7bfba47e3ec0227658aaad5355bac Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 11:36:47 +0100
Subject: [PATCH 14/18] Make JdbcCsvSpecIT and JdbcMetadataIT work
---
.../JdbcCsvSpecIT.java | 37 ++++++++++++++++--
.../JdbcMetadataIT.java | 38 +++++++++++++++++--
2 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCsvSpecIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCsvSpecIT.java
index 5a6e1956d39d1..6552cd0df2355 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCsvSpecIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcCsvSpecIT.java
@@ -8,24 +8,55 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.ql.SpecReader;
import org.elasticsearch.xpack.sql.qa.jdbc.CsvSpecTestCase;
+import org.junit.ClassRule;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
+import java.util.Properties;
import java.util.regex.Pattern;
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName;
import static org.elasticsearch.xpack.ql.CsvSpecReader.CsvTestCase;
import static org.elasticsearch.xpack.ql.CsvSpecReader.specParser;
import static org.elasticsearch.xpack.ql.TestUtils.classpathResources;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.PASSWORD;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.REMOTE_CLUSTER_ALIAS;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.USER_NAME;
public class JdbcCsvSpecIT extends CsvSpecTestCase {
+ @ClassRule
+ public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote();
+
+ @Override
+ protected String getTestRestCluster() {
+ return clusterAndRemote.getCluster().getHttpAddresses();
+ }
+
+ @Override
+ protected Settings restClientSettings() {
+ return clusterAndRemote.clusterAuthSettings();
+ }
+
+ @Override
+ protected RestClient provisioningClient() {
+ return clusterAndRemote.getRemoteClient();
+ }
+
+ @Override
+ protected Properties connectionProperties() {
+ Properties connectionProperties = super.connectionProperties();
+ connectionProperties.put("user", USER_NAME);
+ connectionProperties.put("password", PASSWORD);
+ return connectionProperties;
+ }
- public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster"; // gradle defined
public static final String EXTRACT_FN_NAME = "EXTRACT";
private static final Pattern DESCRIBE_OR_SHOW = Pattern.compile("(?i)\\s*(DESCRIBE|SHOW).*");
@@ -58,7 +89,7 @@ private static CsvTestCase qualifyFromClause(CsvTestCase testCase) {
j = j >= 0 ? i + j : query.length();
sb.append(
query.substring(i, j)
- .replaceAll("(?i)(FROM)(\\s+)(\\w+|\"[^\"]+\")", "$1$2" + buildRemoteIndexName(REMOTE_CLUSTER_NAME, "$3"))
+ .replaceAll("(?i)(FROM)(\\s+)(\\w+|\"[^\"]+\")", "$1$2" + buildRemoteIndexName(REMOTE_CLUSTER_ALIAS, "$3"))
);
boolean inString = false, escaping = false;
char stringDelim = 0, crrChar;
@@ -104,7 +135,7 @@ public Connection esJdbc() throws SQLException {
// Only set the default catalog if the query index isn't yet qualified with the catalog, which can happen if query has been written
// qualified from the start (for the documentation) or edited in qualifyFromClause() above.
if (isFromQualified(csvTestCase().query) == false) {
- connection.setCatalog(REMOTE_CLUSTER_NAME);
+ connection.setCatalog(REMOTE_CLUSTER_ALIAS);
}
return connection;
}
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcMetadataIT.java b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcMetadataIT.java
index ce18532dc12a2..8317b8975382c 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcMetadataIT.java
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/multi_cluster_with_security/JdbcMetadataIT.java
@@ -7,17 +7,47 @@
package org.elasticsearch.xpack.sql.qa.multi_cluster_with_security;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase;
+import org.junit.ClassRule;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Properties;
+
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.LOCAL_CLUSTER_NAME;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.PASSWORD;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.REMOTE_CLUSTER_ALIAS;
+import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.USER_NAME;
public class JdbcMetadataIT extends JdbcIntegrationTestCase {
+ @ClassRule
+ public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote();
+
+ @Override
+ protected String getTestRestCluster() {
+ return clusterAndRemote.getCluster().getHttpAddresses();
+ }
+
+ @Override
+ protected Settings restClientSettings() {
+ return clusterAndRemote.clusterAuthSettings();
+ }
+
+ @Override
+ protected RestClient provisioningClient() {
+ return clusterAndRemote.getRemoteClient();
+ }
- // gradle defines
- public static final String LOCAL_CLUSTER_NAME = "javaRestTest";
- public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster";
+ @Override
+ protected Properties connectionProperties() {
+ Properties connectionProperties = super.connectionProperties();
+ connectionProperties.put("user", USER_NAME);
+ connectionProperties.put("password", PASSWORD);
+ return connectionProperties;
+ }
public void testJdbcGetClusters() throws SQLException {
try (Connection es = esJdbc()) {
@@ -26,7 +56,7 @@ public void testJdbcGetClusters() throws SQLException {
assertTrue(rs.next());
assertEquals(LOCAL_CLUSTER_NAME, rs.getString(1));
assertTrue(rs.next());
- assertEquals(REMOTE_CLUSTER_NAME, rs.getString(1));
+ assertEquals(REMOTE_CLUSTER_ALIAS, rs.getString(1));
assertFalse(rs.next());
}
}
From 0de17ae8d9eb6675d92a5a1f2bae5e4be754f45f Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 12:01:20 +0100
Subject: [PATCH 15/18] Cleanup
---
.../xpack/sql/qa/cli/CliIntegrationTestCase.java | 2 --
.../xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java | 4 ++--
.../xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java | 3 ++-
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java
index 6d544d6f4da22..698df9882ede0 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java
@@ -26,8 +26,6 @@ public abstract class CliIntegrationTestCase extends ESRestTestCase {
*/
public String elasticsearchAddress() {
// CLI only supports a single node at a time so we just give it one.
- // String cluster = System.getProperty("tests.rest.cluster");
- // return cluster.split(",")[0];
return getTestRestCluster().split(",")[0];
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
index 7efc4b207a27c..0b2effe6e3e87 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java
@@ -129,7 +129,7 @@ public void testGetDataStreamViewByName() throws IOException, SQLException {
private void expectDataStreamTable(String dataStreamName, String tableNamePattern, String[] types) throws SQLException, IOException {
try {
- createDataStream(dataStreamName, defaultProvisioningClient());
+ createDataStream(dataStreamName, provisioningClient());
try (Connection es = esJdbc(); ResultSet rs = es.getMetaData().getTables("%", "%", tableNamePattern, types)) {
assertTrue(rs.next());
assertEquals(dataStreamName, rs.getString(3));
@@ -137,7 +137,7 @@ private void expectDataStreamTable(String dataStreamName, String tableNamePatter
assertFalse(rs.next());
}
} finally {
- deleteDataStream(dataStreamName, defaultProvisioningClient());
+ deleteDataStream(dataStreamName, provisioningClient());
}
}
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
index 7c0a876619cb1..8d670f945d35a 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
@@ -24,12 +24,13 @@
import static org.elasticsearch.common.Strings.hasText;
public abstract class RemoteClusterAwareSqlRestTestCase extends ESRestTestCase {
+
private static final long CLIENT_TIMEOUT = 40L; // upped from 10s to accommodate for max measured throughput decline
// client used for loading data on a remote cluster only.
private static RestClient remoteClient;
- // gradle defines for legacy test framework
+ // gradle defines when using legacy-java-rest-test
public static final String AUTH_USER = System.getProperty("tests.rest.cluster.multi.user");
public static final String AUTH_PASS = System.getProperty("tests.rest.cluster.multi.password");
From 5f6fddeb3845bb9f18081d69de7d8b7597a8261c Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 12:10:17 +0100
Subject: [PATCH 16/18] Spotless
---
.../xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
index 8d670f945d35a..c81fe83a96f66 100644
--- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
+++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RemoteClusterAwareSqlRestTestCase.java
@@ -24,7 +24,7 @@
import static org.elasticsearch.common.Strings.hasText;
public abstract class RemoteClusterAwareSqlRestTestCase extends ESRestTestCase {
-
+
private static final long CLIENT_TIMEOUT = 40L; // upped from 10s to accommodate for max measured throughput decline
// client used for loading data on a remote cluster only.
From 724a7081887744fb4d3b959b6fedfe7007e474cc Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 15:17:47 +0100
Subject: [PATCH 17/18] Fix gradle config for Security tests
---
x-pack/plugin/sql/qa/server/build.gradle | 18 +++++++++++++++---
.../multi-cluster-with-security/build.gradle | 5 +----
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle
index 67f1bd1eef4b3..cee10d81c9573 100644
--- a/x-pack/plugin/sql/qa/server/build.gradle
+++ b/x-pack/plugin/sql/qa/server/build.gradle
@@ -40,9 +40,21 @@ subprojects {
if (project.name != 'security') {
// The security project just configures its subprojects
- apply plugin: 'elasticsearch.internal-java-rest-test'
- tasks.named('javaRestTest') {
- usesDefaultDistribution()
+
+ if (project.parent.name == 'security')
+ {
+ apply plugin: 'elasticsearch.legacy-java-rest-test'
+
+ testClusters.matching { it.name == "javaRestTest" }.configureEach {
+ testDistribution = 'DEFAULT'
+ setting 'xpack.ml.enabled', 'false'
+ setting 'xpack.watcher.enabled', 'false'
+ }
+ } else {
+ apply plugin: 'elasticsearch.internal-java-rest-test'
+ tasks.named('javaRestTest') {
+ usesDefaultDistribution()
+ }
}
dependencies {
diff --git a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
index 6c14377b07276..04f25f7175451 100644
--- a/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
+++ b/x-pack/plugin/sql/qa/server/multi-cluster-with-security/build.gradle
@@ -1,9 +1,6 @@
dependencies {
javaRestTestImplementation project(path: xpackModule('ql:test-fixtures'))
+ clusterPlugins project(':x-pack:qa:freeze-plugin')
}
tasks.named("check").configure {dependsOn("javaRestTest") } // run these tests as part of the "check" task
-
-dependencies {
- clusterPlugins project(':x-pack:qa:freeze-plugin')
-}
From 366df7445a02fe840067c5b2ae346e28831d8f51 Mon Sep 17 00:00:00 2001
From: Alexander Spies
Date: Mon, 13 Nov 2023 16:41:28 +0100
Subject: [PATCH 18/18] Remove leftover comment
---
.../xpack/sql/qa/security/SqlSecurityTestCase.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
index 27a7a04017f0b..0ab942fcff39f 100644
--- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
+++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java
@@ -58,8 +58,6 @@
public abstract class SqlSecurityTestCase extends ESRestTestCase {
public String elasticsearchAddress() {
// CLI only supports a single node at a time so we just give it one.
- // String cluster = System.getProperty("tests.rest.cluster");
- // return cluster.split(",")[0];
return getTestRestCluster().split(",")[0];
}