From 5f68d8d559a09269b5307fe7bb623f0a774b8eed Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Thu, 2 Nov 2023 13:25:41 +0100 Subject: [PATCH 01/18] Switch RestSqlIT to new framework --- x-pack/plugin/sql/qa/server/build.gradle | 19 ++++++++++---- .../xpack/sql/qa/single_node/RestSqlIT.java | 9 +++++++ .../sql/qa/single_node/SqlTestCluster.java | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java diff --git a/x-pack/plugin/sql/qa/server/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle index c2c9731b8d363..769922bc28bd3 100644 --- a/x-pack/plugin/sql/qa/server/build.gradle +++ b/x-pack/plugin/sql/qa/server/build.gradle @@ -41,12 +41,21 @@ subprojects { if (project.name != 'security') { // The security project just configures its subprojects - apply plugin: 'elasticsearch.legacy-java-rest-test' + if (project.name == 'single-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' + if (project.name != 'single-node') { + testClusters.matching { it.name == "javaRestTest" }.configureEach { + testDistribution = 'DEFAULT' + setting 'xpack.ml.enabled', 'false' + setting 'xpack.watcher.enabled', 'false' + } } diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlIT.java index c0a1a79e4c9a7..167cc212685d7 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlIT.java @@ -10,7 +10,9 @@ import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Request; import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase; +import org.junit.ClassRule; import java.io.IOException; @@ -21,6 +23,13 @@ * user rather than to the JDBC driver or CLI. */ public class RestSqlIT extends RestSqlTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } public void testErrorMessageForTranslatingQueryWithWhereEvaluatingToFalse() throws IOException { index("{\"foo\":1}"); 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 new file mode 100644 index 0000000000000..4ff56bd1ae830 --- /dev/null +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_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.single_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) + .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") + .build(); + } + +} From 87ddc785db7cb4ac7d9f5aeee6146a9d8de3c7d8 Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Thu, 2 Nov 2023 14:12:00 +0100 Subject: [PATCH 02/18] Enable freeze plugin as before --- x-pack/plugin/sql/qa/server/build.gradle | 1 - x-pack/plugin/sql/qa/server/single-node/build.gradle | 3 +++ .../elasticsearch/xpack/sql/qa/single_node/SqlTestCluster.java | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/sql/qa/server/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle index 769922bc28bd3..64462fc34d71b 100644 --- a/x-pack/plugin/sql/qa/server/build.gradle +++ b/x-pack/plugin/sql/qa/server/build.gradle @@ -58,7 +58,6 @@ subprojects { } } - dependencies { configurations.javaRestTestRuntimeClasspath { resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25" 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 c58dca254db03..215064ec1328f 100644 --- a/x-pack/plugin/sql/qa/server/single-node/build.gradle +++ b/x-pack/plugin/sql/qa/server/single-node/build.gradle @@ -5,3 +5,6 @@ testClusters.matching { it.name == "javaRestTest" }.configureEach { plugin ':x-pack:qa:freeze-plugin' } +dependencies { + clusterPlugins project(':x-pack:qa:freeze-plugin') +} 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 4ff56bd1ae830..2303e5f27627e 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 @@ -20,6 +20,7 @@ public static ElasticsearchCluster getCluster() { .setting("xpack.watcher.enabled", "false") .setting("xpack.security.enabled", "false") .setting("xpack.license.self_generated.type", "trial") + .plugin(":x-pack:qa:freeze-plugin") .build(); } From 93f67aa7af171d6da0a66a6319db5047449f4685 Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Thu, 2 Nov 2023 15:10:09 +0100 Subject: [PATCH 03/18] Make CliErrorsIT work for single-node --- .../xpack/sql/qa/single_node/CliErrorsIT.java | 12 +++++++++++- .../xpack/sql/qa/cli/CliIntegrationTestCase.java | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliErrorsIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliErrorsIT.java index 2256890f33a1b..02cdfc993c12c 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliErrorsIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliErrorsIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.cli.ErrorsTestCase; +import org.junit.ClassRule; -public class CliErrorsIT extends ErrorsTestCase {} +public class CliErrorsIT extends ErrorsTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } +} 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 eb253e16cd848..6d544d6f4da22 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 @@ -24,10 +24,11 @@ public abstract class CliIntegrationTestCase extends ESRestTestCase { /** * Read an address for Elasticsearch suitable for the CLI from the system properties. */ - public static String elasticsearchAddress() { - String cluster = System.getProperty("tests.rest.cluster"); + public String elasticsearchAddress() { // CLI only supports a single node at a time so we just give it one. - return cluster.split(",")[0]; + // String cluster = System.getProperty("tests.rest.cluster"); + // return cluster.split(",")[0]; + return getTestRestCluster().split(",")[0]; } private EmbeddedCli cli; @@ -37,7 +38,7 @@ public static String elasticsearchAddress() { */ @Before public void startCli() throws IOException { - cli = new EmbeddedCli(CliIntegrationTestCase.elasticsearchAddress(), true, securityConfig()); + cli = new EmbeddedCli(elasticsearchAddress(), true, securityConfig()); } @After From 9c5964fdfbee57c5986eebf97e7aedd8863017e0 Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Fri, 3 Nov 2023 11:13:59 +0100 Subject: [PATCH 04/18] Make all single node IT run with new framework --- .../sql/qa/jdbc/JdbcIntegrationTestCase.java | 4 ++-- .../sql/qa/single_node/CliExplainIT.java | 10 +++++++++ .../sql/qa/single_node/CliFetchSizeIT.java | 12 +++++++++- .../sql/qa/single_node/CliLenientIT.java | 12 +++++++++- .../qa/single_node/CliPartialResultsIT.java | 8 +++++++ .../xpack/sql/qa/single_node/CliSelectIT.java | 12 +++++++++- .../xpack/sql/qa/single_node/CliShowIT.java | 12 +++++++++- .../ConsistentFunctionArgHandlingIT.java | 9 ++++++++ .../qa/single_node/CustomDateFormatIT.java | 8 +++++++ .../sql/qa/single_node/FieldExtractorIT.java | 8 +++++++ .../sql/qa/single_node/GeoJdbcCsvSpecIT.java | 9 ++++++++ .../sql/qa/single_node/GeoJdbcSqlSpecIT.java | 10 +++++++++ .../sql/qa/single_node/JdbcCsvSpecIT.java | 9 ++++++++ .../single_node/JdbcDatabaseMetaDataIT.java | 12 +++++++++- .../sql/qa/single_node/JdbcDocCsvSpecIT.java | 9 ++++++++ .../qa/single_node/JdbcFrozenCsvSpecIT.java | 9 ++++++++ .../qa/single_node/JdbcShardFailureIT.java | 22 +++++++++++++++++++ .../sql/qa/single_node/JdbcShowTablesIT.java | 12 +++++++++- .../sql/qa/single_node/JdbcSqlSpecIT.java | 10 +++++++++ .../qa/single_node/RestSqlDeprecationIT.java | 9 ++++++++ .../qa/single_node/RestSqlPaginationIT.java | 12 +++++++++- .../sql/qa/single_node/RestSqlUsageIT.java | 12 +++++++++- .../sql/qa/single_node/SqlProtocolIT.java | 12 +++++++++- .../sql/qa/single_node/SysColumnsIT.java | 8 +++++++ .../sql/qa/jdbc/JdbcIntegrationTestCase.java | 4 ++-- 25 files changed, 241 insertions(+), 13 deletions(-) diff --git a/x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java b/x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java index 16bd33ca31d74..43d6d04bfac2c 100644 --- a/x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java +++ b/x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcIntegrationTestCase.java @@ -38,8 +38,8 @@ public void checkSearchContent() throws IOException { /** * Read an address for Elasticsearch suitable for the JDBC driver from the system properties. */ - public static String elasticsearchAddress() { - String cluster = System.getProperty("tests.rest.cluster"); + public String elasticsearchAddress() { + String cluster = getTestRestCluster(); // JDBC only supports a single node at a time so we just give it one. return cluster.split(",")[0]; /* This doesn't include "jdbc:es://" because we want the example in diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliExplainIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliExplainIT.java index 7f95afc32181a..46e16418e0642 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliExplainIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliExplainIT.java @@ -6,7 +6,9 @@ */ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.cli.CliIntegrationTestCase; +import org.junit.ClassRule; import java.io.IOException; @@ -14,6 +16,14 @@ import static org.hamcrest.Matchers.startsWith; public class CliExplainIT extends CliIntegrationTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } + public void testExplainBasic() throws IOException { index("test", body -> body.field("test_field", "test_value")); diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliFetchSizeIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliFetchSizeIT.java index f7a6854b02fce..9811142d3611c 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliFetchSizeIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliFetchSizeIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.cli.FetchSizeTestCase; +import org.junit.ClassRule; -public class CliFetchSizeIT extends FetchSizeTestCase {} +public class CliFetchSizeIT extends FetchSizeTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } +} diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliLenientIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliLenientIT.java index afcfca0a01ed2..99895823adc7f 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliLenientIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliLenientIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliPartialResultsIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliPartialResultsIT.java index 82e89da3cefb6..8baa265780f40 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliPartialResultsIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliPartialResultsIT.java @@ -6,8 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.cli.PartialResultsTestCase; +import org.junit.ClassRule; public class CliPartialResultsIT extends PartialResultsTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliSelectIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliSelectIT.java index d45d82512fe55..ecdd41a203ad3 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliSelectIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliSelectIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliShowIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliShowIT.java index 982dd744a6934..2f9deffa48f08 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliShowIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CliShowIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/ConsistentFunctionArgHandlingIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/ConsistentFunctionArgHandlingIT.java index a3f966e712b29..de502bf886ff3 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/ConsistentFunctionArgHandlingIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/ConsistentFunctionArgHandlingIT.java @@ -14,7 +14,9 @@ import org.elasticsearch.core.PathUtils; import org.elasticsearch.core.Strings; import org.elasticsearch.core.Tuple; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase; +import org.junit.ClassRule; import java.io.IOException; import java.nio.file.Files; @@ -49,6 +51,13 @@ * new Fn("ASCII", "foobar").ignore()

*/ public class ConsistentFunctionArgHandlingIT extends JdbcIntegrationTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } private static final List FUNCTION_CALLS_TO_TEST = asList( new Fn("ASCII", "foobar"), diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CustomDateFormatIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CustomDateFormatIT.java index c0d0127f17f77..4a91372abe5d4 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CustomDateFormatIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/CustomDateFormatIT.java @@ -7,8 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/FieldExtractorIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/FieldExtractorIT.java index 2fa2457a5c608..ac967710e360c 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/FieldExtractorIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/FieldExtractorIT.java @@ -7,8 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.FieldExtractorTestCase; +import org.junit.ClassRule; public class FieldExtractorIT extends FieldExtractorTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcCsvSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcCsvSpecIT.java index bb0d16cc5ec9a..8fb61b79970ec 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcCsvSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcCsvSpecIT.java @@ -9,7 +9,9 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.geo.GeoCsvSpecTestCase; +import org.junit.ClassRule; import java.util.ArrayList; import java.util.List; @@ -18,6 +20,13 @@ import static org.elasticsearch.xpack.ql.CsvSpecReader.specParser; public class GeoJdbcCsvSpecIT extends GeoCsvSpecTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } @ParametersFactory(argumentFormatting = PARAM_FORMATTING) public static List readScriptSpec() throws Exception { diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcSqlSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcSqlSpecIT.java index 7eb7a7be5febd..e2796051653b5 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcSqlSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/GeoJdbcSqlSpecIT.java @@ -7,9 +7,19 @@ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcCsvSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcCsvSpecIT.java index 4346aad97e4cd..6ccc2662fcf9f 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcCsvSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcCsvSpecIT.java @@ -8,7 +8,9 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.CsvSpecTestCase; +import org.junit.ClassRule; import java.util.ArrayList; import java.util.List; @@ -17,6 +19,13 @@ import static org.elasticsearch.xpack.ql.CsvSpecReader.specParser; public class JdbcCsvSpecIT extends CsvSpecTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } @ParametersFactory(argumentFormatting = PARAM_FORMATTING) public static List readScriptSpec() throws Exception { diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDatabaseMetaDataIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDatabaseMetaDataIT.java index da1ec865922a2..958bb212e8a13 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDatabaseMetaDataIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDatabaseMetaDataIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDocCsvSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDocCsvSpecIT.java index 73742a553f7a2..6147d0759f459 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDocCsvSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcDocCsvSpecIT.java @@ -10,10 +10,12 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.client.RestClient; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.DataLoader; import org.elasticsearch.xpack.sql.qa.jdbc.JdbcAssert; import org.elasticsearch.xpack.sql.qa.jdbc.SpecBaseIntegrationTestCase; import org.elasticsearch.xpack.sql.qa.jdbc.SqlSpecTestCase; +import org.junit.ClassRule; import java.sql.Connection; import java.sql.ResultSet; @@ -39,6 +41,13 @@ * at this stage and, to not keep things stalling, started with this approach. */ public class JdbcDocCsvSpecIT extends SpecBaseIntegrationTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } private final CsvTestCase testCase; diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcFrozenCsvSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcFrozenCsvSpecIT.java index d912eb5a6261e..fcf6241f51c0f 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcFrozenCsvSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcFrozenCsvSpecIT.java @@ -8,7 +8,9 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.CsvSpecTestCase; +import org.junit.ClassRule; import java.util.List; import java.util.Properties; @@ -18,6 +20,13 @@ import static org.elasticsearch.xpack.ql.CsvSpecReader.specParser; public class JdbcFrozenCsvSpecIT extends CsvSpecTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } @ParametersFactory(argumentFormatting = PARAM_FORMATTING) public static List readScriptSpec() throws Exception { diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShardFailureIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShardFailureIT.java index 492971cf2a13c..572c809468784 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShardFailureIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShardFailureIT.java @@ -8,7 +8,9 @@ import org.elasticsearch.client.Request; import org.elasticsearch.core.Strings; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase; +import org.junit.ClassRule; import java.io.IOException; import java.sql.Connection; @@ -22,7 +24,27 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; public class JdbcShardFailureIT extends JdbcIntegrationTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + private String nodeAddresses; + + /** + * Caches the node addresses when called for the first time. + * Once cluster is in red health, calling this will time out if it was not called before. + */ + @Override + protected String getTestRestCluster() { + if (nodeAddresses == null) { + nodeAddresses = cluster.getHttpAddresses(); + } + return nodeAddresses; + } + private void createTestIndex() throws IOException { + // This method will put the cluster into a red state intentionally, so cache the node addresses first. + getTestRestCluster(); + Request createTest1 = new Request("PUT", "/test1"); String body1 = """ {"aliases":{"test":{}}, "mappings": {"properties": {"test_field":{"type":"integer"}}}}"""; diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShowTablesIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShowTablesIT.java index d9677bd832226..40b90e1a42c6c 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShowTablesIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcShowTablesIT.java @@ -6,6 +6,16 @@ */ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcSqlSpecIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcSqlSpecIT.java index 15b69f0158ef3..15d6895be9010 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcSqlSpecIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/JdbcSqlSpecIT.java @@ -6,9 +6,19 @@ */ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.SqlSpecTestCase; +import org.junit.ClassRule; public class JdbcSqlSpecIT extends SqlSpecTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } + public JdbcSqlSpecIT(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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlDeprecationIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlDeprecationIT.java index 88af42929a741..7074091f4f166 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlDeprecationIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlDeprecationIT.java @@ -10,13 +10,22 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Request; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.rest.BaseRestSqlTestCase; +import org.junit.ClassRule; import java.io.IOException; import static org.elasticsearch.xpack.sql.qa.rest.RestSqlTestCase.SQL_QUERY_REST_ENDPOINT; public class RestSqlDeprecationIT extends BaseRestSqlTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } public void testIndexIncludeParameterIsDeprecated() throws IOException { testDeprecationWarning( diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlPaginationIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlPaginationIT.java index da26f550cafe4..6ef56274cdbb0 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlPaginationIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlPaginationIT.java @@ -7,6 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.rest.RestSqlPaginationTestCase; +import org.junit.ClassRule; -public class RestSqlPaginationIT extends RestSqlPaginationTestCase {} +public class RestSqlPaginationIT extends RestSqlPaginationTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } +} diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlUsageIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlUsageIT.java index e1f9ff782146d..297302c534030 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlUsageIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/RestSqlUsageIT.java @@ -7,6 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.rest.RestSqlUsageTestCase; +import org.junit.ClassRule; -public class RestSqlUsageIT extends RestSqlUsageTestCase {} +public class RestSqlUsageIT extends RestSqlUsageTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } +} diff --git a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlProtocolIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlProtocolIT.java index c3d08d34542bd..e59a8392f7335 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlProtocolIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SqlProtocolIT.java @@ -7,6 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_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/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SysColumnsIT.java b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SysColumnsIT.java index 5c5dcd2afbe72..928916b3c40ae 100644 --- a/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SysColumnsIT.java +++ b/x-pack/plugin/sql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/sql/qa/single_node/SysColumnsIT.java @@ -7,8 +7,16 @@ package org.elasticsearch.xpack.sql.qa.single_node; +import org.elasticsearch.test.cluster.ElasticsearchCluster; import org.elasticsearch.xpack.sql.qa.jdbc.SysColumnsTestCase; +import org.junit.ClassRule; public class SysColumnsIT extends SysColumnsTestCase { + @ClassRule + public static final ElasticsearchCluster cluster = SqlTestCluster.getCluster(); + @Override + protected String getTestRestCluster() { + return cluster.getHttpAddresses(); + } } 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 34383404544a5..9123282f22195 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 @@ -38,8 +38,8 @@ public void checkSearchContent() throws Exception { /** * Read an address for Elasticsearch suitable for the JDBC driver from the system properties. */ - public static String elasticsearchAddress() { - String cluster = System.getProperty("tests.rest.cluster"); + public String elasticsearchAddress() { + String cluster = getTestRestCluster(); // JDBC only supports a single node at a time so we just give it one. return cluster.split(",")[0]; /* This doesn't include "jdbc:es://" because we want the example in From b0f4e60d48429dd36af6b421158d2179e2c484e6 Mon Sep 17 00:00:00 2001 From: Alexander Spies Date: Fri, 3 Nov 2023 11:59:07 +0100 Subject: [PATCH 05/18] Refactor SqlSecurityTestCase Do not obtain node addresses directly from global property - use getTestRestCluster instead. This is non-static, which requires refactoring. --- .../xpack/sql/qa/security/CliSecurityIT.java | 13 +++- .../xpack/sql/qa/security/JdbcSecurityIT.java | 29 ++++--- .../sql/qa/security/RestSqlSecurityIT.java | 9 ++- .../sql/qa/security/SqlSecurityTestCase.java | 77 ++++++++++--------- 4 files changed, 74 insertions(+), 54 deletions(-) diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/CliSecurityIT.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/CliSecurityIT.java index 4fb5143860380..d0eb8a4b6eade 100644 --- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/CliSecurityIT.java +++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/CliSecurityIT.java @@ -21,12 +21,10 @@ import java.util.List; import java.util.Map; -import static org.elasticsearch.xpack.sql.qa.cli.CliIntegrationTestCase.elasticsearchAddress; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.startsWith; public class CliSecurityIT extends SqlSecurityTestCase { - @Override public void testDescribeWorksAsFullAccess() {} @@ -64,7 +62,7 @@ static SecurityConfig adminSecurityConfig() { /** * Perform security test actions using the CLI. */ - private static class CliActions implements Actions { + private class CliActions implements Actions { @Override public String minimalPermissionsForAllActions() { return "cli_or_drivers_minimal"; @@ -227,7 +225,14 @@ protected void assertConnectionTest() throws IOException { } } + private final Actions actions; + + @Override + Actions actions() { + return actions; + } + public CliSecurityIT() { - super(new CliActions()); + actions = new CliActions(); } } diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/JdbcSecurityIT.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/JdbcSecurityIT.java index 1d88bf4f59100..0e0c2bc8d78b4 100644 --- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/JdbcSecurityIT.java +++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/JdbcSecurityIT.java @@ -26,7 +26,6 @@ import java.util.Properties; import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcAssert.assertResultSets; -import static org.elasticsearch.xpack.sql.qa.jdbc.JdbcIntegrationTestCase.elasticsearchAddress; import static org.elasticsearch.xpack.sql.qa.security.RestSqlIT.SSL_ENABLED; import static org.hamcrest.Matchers.containsString; @@ -41,7 +40,7 @@ static Properties adminProperties() { return properties; } - static Connection es(Properties properties) throws SQLException { + Connection es(Properties properties) throws SQLException { Properties props = new Properties(); props.put("timezone", randomZone().getId()); props.putAll(properties); @@ -82,7 +81,7 @@ private static void addSslPropertiesIfNeeded(Properties properties) { properties.put("ssl.truststore.pass", "keypass"); } - static void expectActionMatchesAdmin( + void expectActionMatchesAdmin( CheckedFunction adminAction, String user, CheckedFunction userAction @@ -92,15 +91,15 @@ static void expectActionMatchesAdmin( } } - static void expectForbidden(String user, CheckedConsumer action) throws Exception { + void expectForbidden(String user, CheckedConsumer action) throws Exception { expectError(user, action, "is unauthorized for user [" + user + "]"); } - static void expectUnknownIndex(String user, CheckedConsumer action) throws Exception { + void expectUnknownIndex(String user, CheckedConsumer action) throws Exception { expectError(user, action, "Unknown index"); } - static void expectError(String user, CheckedConsumer action, String errorMessage) throws Exception { + void expectError(String user, CheckedConsumer action, String errorMessage) throws Exception { SQLException e; try (Connection connection = es(userProperties(user))) { e = expectThrows(SQLException.class, () -> action.accept(connection)); @@ -108,8 +107,7 @@ static void expectError(String user, CheckedConsumer a assertThat(e.getMessage(), containsString(errorMessage)); } - static void expectActionThrowsUnknownColumn(String user, CheckedConsumer action, String column) - throws Exception { + void expectActionThrowsUnknownColumn(String user, CheckedConsumer action, String column) throws Exception { SQLException e; try (Connection connection = es(userProperties(user))) { e = expectThrows(SQLException.class, () -> action.accept(connection)); @@ -117,7 +115,7 @@ static void expectActionThrowsUnknownColumn(String user, CheckedConsumer tables, String user) throws Exception @Override public void expectForbidden(String user, String sql) throws Exception { - JdbcSecurityIT.expectForbidden(user, con -> con.createStatement().executeQuery(sql)); + JdbcSecurityIT.this.expectForbidden(user, con -> con.createStatement().executeQuery(sql)); } @Override public void expectUnknownIndex(String user, String sql) throws Exception { - JdbcSecurityIT.expectUnknownIndex(user, con -> con.createStatement().executeQuery(sql)); + JdbcSecurityIT.this.expectUnknownIndex(user, con -> con.createStatement().executeQuery(sql)); } @Override @@ -245,8 +243,15 @@ private void expectUnauthorized(String action, String user, ThrowingRunnable r) } } + private final Actions actions; + + @Override + Actions actions() { + return actions; + } + public JdbcSecurityIT() { - super(new JdbcActions()); + actions = new JdbcActions(); } // Metadata methods only available to JDBC diff --git a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java index 3b23daf9dde54..7195fa00ce350 100644 --- a/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java +++ b/x-pack/plugin/sql/qa/server/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java @@ -271,8 +271,15 @@ private static Map 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]; }