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/build.gradle b/x-pack/plugin/sql/qa/server/build.gradle index c2c9731b8d363..cee10d81c9573 100644 --- a/x-pack/plugin/sql/qa/server/build.gradle +++ b/x-pack/plugin/sql/qa/server/build.gradle @@ -38,73 +38,80 @@ subprojects { apply plugin: 'elasticsearch.java' } - if (project.name != 'security') { // The security project just configures its subprojects - 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' - } - - - 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')) - // 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") - - - 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 + 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() + } } - javaRestTestRuntimeOnly("org.jline:jline-terminal-jna:${jlineVersion}") { - exclude group: "net.java.dev.jna" + 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')) + + // 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") + + + 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 + } + + 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}" + + // spatial dependency + javaRestTestRuntimeOnly project(path: xpackModule('spatial')) + javaRestTestRuntimeOnly project(path: ':modules:legacy-geo') + + javaRestTestRuntimeOnly project(path: ':modules:rest-root') + + javaRestTestRuntimeOnly "org.slf4j:slf4j-api:1.7.25" } - 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}" - - // spatial dependency - javaRestTestRuntimeOnly project(path: xpackModule('spatial')) - javaRestTestRuntimeOnly project(path: ':modules:legacy-geo') - - javaRestTestRuntimeOnly project(path: ':modules:rest-root') - - 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..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,56 +1,6 @@ -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')) + clusterPlugins project(':x-pack:qa:freeze-plugin') } -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 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..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 @@ -8,44 +8,82 @@ 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 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; 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 { + 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)); + } + } + }; + } + }; - // gradle defines - public static final String LOCAL_CLUSTER_NAME = "javaRestTest"; - public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster"; + @ClassRule + public static RuleChain testSetup = RuleChain.outerRule(clusterAndRemote).around(setupIndex); - private static final String INDEX_NAME = "test"; + @Override + protected String getTestRestCluster() { + return clusterAndRemote.getCluster().getHttpAddresses(); + } - @BeforeClass - static void setupIndex() throws IOException { - index(INDEX_NAME, body -> body.field("zero", 0)); + @Override + protected Settings restClientSettings() { + return clusterAndRemote.clusterAuthSettings(); } - @AfterClass - static void cleanupIndex() throws IOException { - provisioningClient().performRequest(new Request("DELETE", "/" + INDEX_NAME)); + @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; + } + + private static final String INDEX_NAME = "test"; + public void testJdbcSetCatalog() throws Exception { try (Connection es = esJdbc()) { PreparedStatement ps = es.prepareStatement("SELECT count(*) FROM " + INDEX_NAME); 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 +100,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 +111,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 +122,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 +143,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/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()); } } 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..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 @@ -6,20 +6,39 @@ */ 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.rest.RestSqlTestCase; +import org.junit.ClassRule; import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName; +import static org.elasticsearch.xpack.sql.qa.multi_cluster_with_security.SqlTestClusterWithRemote.REMOTE_CLUSTER_ALIAS; public class RestSqlIT extends RestSqlTestCase { + @ClassRule + public static SqlTestClusterWithRemote clusterAndRemote = new SqlTestClusterWithRemote(); - public static final String REMOTE_CLUSTER_NAME = "my_remote_cluster"; // gradle defined + @Override + protected String getTestRestCluster() { + return clusterAndRemote.getCluster().getHttpAddresses(); + } + + @Override + protected Settings restClientSettings() { + return clusterAndRemote.clusterAuthSettings(); + } + + @Override + protected RestClient provisioningClient() { + return clusterAndRemote.getRemoteClient(); + } @Override protected String indexPattern(String pattern) { if (randomBoolean()) { - return buildRemoteIndexName(REMOTE_CLUSTER_NAME, pattern); + return buildRemoteIndexName(REMOTE_CLUSTER_ALIAS, pattern); } else { - String cluster = REMOTE_CLUSTER_NAME.substring(0, randomIntBetween(0, REMOTE_CLUSTER_NAME.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 new file mode 100644 index 0000000000000..a6e5baabd98f3 --- /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,131 @@ +/* + * 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 { + 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 clusterSettings(String remoteAddress) { + return ElasticsearchCluster.local() + .distribution(DistributionType.DEFAULT) + .name(LOCAL_CLUSTER_NAME) + .setting("xpack.ml.enabled", "false") + .setting("xpack.watcher.enabled", "false") + .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") + .setting("xpack.security.autoconfiguration.enabled", "false") + .user(USER_NAME, PASSWORD) + .plugin(":x-pack:qa:freeze-plugin") + .build(); + } + + private static ElasticsearchCluster remoteClusterSettings() { + return ElasticsearchCluster.local() + .distribution(DistributionType.DEFAULT) + .name(REMOTE_CLUSTER_NAME) + .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 = remoteClusterSettings(); + private RestClient remoteClient; + + public Statement apply(Statement base, Description description) { + return remote.apply(startRemoteClient(startCluster(base)), null); + } + + public ElasticsearchCluster getCluster() { + return cluster; + } + + public Settings clusterAuthSettings() { + return clientAuthSettings(); + } + + public RestClient getRemoteClient() { + 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 = clusterSettings(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-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..9859be524ce6a --- /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) + .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/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..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 @@ -56,6 +56,11 @@ 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. + return getTestRestCluster().split(",")[0]; + } + /** * Actions taken by this test. *

@@ -131,7 +136,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 +148,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 +238,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 +269,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 +288,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 +297,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 +312,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 +325,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 +334,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 +349,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 +362,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 +385,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 +401,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 +414,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 +430,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 +449,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 +459,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 +474,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 { 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..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,7 +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') } - 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/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/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/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/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..bfcd1671e4d39 --- /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,25 @@ +/* + * 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) + .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/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/cli/CliIntegrationTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/CliIntegrationTestCase.java index eb253e16cd848..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 @@ -24,10 +24,9 @@ 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]; + return getTestRestCluster().split(",")[0]; } private EmbeddedCli cli; @@ -37,7 +36,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 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..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); + 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); + deleteDataStream(dataStreamName, provisioningClient()); } } 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..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; @@ -38,8 +39,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 @@ -72,21 +73,35 @@ 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)); - provisioningClient().performRequest(request); + provisioningClient.performRequest(request); + } + + public void index(String index, String documentId, CheckedConsumer body) throws IOException { + index(index, documentId, body, provisioningClient()); } - public static void delete(String index, String documentId) throws IOException { + public void delete(String index, String documentId) throws IOException { Request request = new Request("DELETE", "/" + index + "/_doc/" + documentId); request.addParameter("refresh", "true"); provisioningClient().performRequest(request); @@ -116,7 +131,7 @@ protected Properties connectionProperties() { return connectionProperties; } - protected static void createIndexWithSettingsAndMappings(String index) throws IOException { + protected void createIndexWithSettingsAndMappings(String index) throws IOException { Request request = new Request("PUT", "/" + index); XContentBuilder createIndex = JsonXContent.contentBuilder().startObject(); createIndex.startObject("settings"); @@ -135,7 +150,7 @@ protected static void createIndexWithSettingsAndMappings(String index) throws IO provisioningClient().performRequest(request); } - protected static void updateMapping(String index, 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..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 @@ -30,7 +30,7 @@ public abstract class RemoteClusterAwareSqlRestTestCase extends ESRestTestCase { // client used for loading data on a remote cluster only. private static RestClient remoteClient; - // gradle defines + // 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"); @@ -59,7 +59,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); @@ -77,12 +77,22 @@ protected static TimeValue timeout() { return TimeValue.timeValueSeconds(CLIENT_TIMEOUT); } - // 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() { + /** + * 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; } + /** + * 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 defaultProvisioningClient(); + } + @Override protected Settings restClientSettings() { return secureRemoteClientSettings(); 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);