From c814e8e60c643efd92c5284dca2ca944a72bb812 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 28 Feb 2018 08:04:50 -0800 Subject: [PATCH] SQL: Rename testing class Renamed `RemoteCli` to `EmbeddedCli` because it now contains an embedded version of the SQL CLI. Original commit: elastic/x-pack-elasticsearch@c88a79a02962b7267fd7fe031b6a5ed2933d13c8 --- .../xpack/qa/sql/security/CliErrorsIT.java | 2 +- .../xpack/qa/sql/security/CliFetchSizeIT.java | 2 +- .../xpack/qa/sql/security/CliSecurityIT.java | 24 +++++++++---------- .../xpack/qa/sql/security/CliSelectIT.java | 2 +- .../xpack/qa/sql/security/CliShowIT.java | 2 +- .../qa/sql/cli/CliIntegrationTestCase.java | 6 ++--- .../cli/{RemoteCli.java => EmbeddedCli.java} | 7 +++--- 7 files changed, 22 insertions(+), 23 deletions(-) rename qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/{RemoteCli.java => EmbeddedCli.java} (98%) diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliErrorsIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliErrorsIT.java index b59c9f91282..92d9608a527 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliErrorsIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliErrorsIT.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.qa.sql.security; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; public class CliErrorsIT extends ErrorsTestCase { @Override diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliFetchSizeIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliFetchSizeIT.java index 8420f8a2a7c..c8ca7db71d1 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliFetchSizeIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliFetchSizeIT.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.qa.sql.security; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.qa.sql.cli.FetchSizeTestCase; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; public class CliFetchSizeIT extends FetchSizeTestCase { @Override diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSecurityIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSecurityIT.java index 84d3107384c..5e8aa4ec6ad 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSecurityIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSecurityIT.java @@ -8,8 +8,8 @@ package org.elasticsearch.xpack.qa.sql.security; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -66,7 +66,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { @Override public void queryWorksAsAdmin() throws Exception { - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, adminSecurityConfig())) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, adminSecurityConfig())) { assertThat(cli.command("SELECT * FROM test ORDER BY a"), containsString("a | b | c")); assertEquals("---------------+---------------+---------------", cli.readLine()); assertThat(cli.readLine(), containsString("1 |2 |3")); @@ -90,9 +90,9 @@ public class CliSecurityIT extends SqlSecurityTestCase { } public void expectMatchesAdmin(String adminSql, String user, String userSql, - CheckedConsumer customizer) throws Exception { + CheckedConsumer customizer) throws Exception { List adminResult = new ArrayList<>(); - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, adminSecurityConfig())) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, adminSecurityConfig())) { customizer.accept(cli); adminResult.add(cli.command(adminSql)); String line; @@ -104,7 +104,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { } Iterator expected = adminResult.iterator(); - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) { customizer.accept(cli); assertTrue(expected.hasNext()); assertEquals(expected.next(), cli.command(userSql)); @@ -122,7 +122,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { @Override public void expectDescribe(Map columns, String user) throws Exception { - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) { assertThat(cli.command("DESCRIBE test"), containsString("column | type")); assertEquals("---------------+---------------", cli.readLine()); for (Map.Entry column : columns.entrySet()) { @@ -134,7 +134,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { @Override public void expectShowTables(List tables, String user) throws Exception { - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) { String tablesOutput = cli.command("SHOW TABLES"); assertThat(tablesOutput, containsString("name")); assertThat(tablesOutput, containsString("type")); @@ -157,7 +157,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { @Override public void expectUnknownIndex(String user, String sql) throws Exception { - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) { ErrorsTestCase.assertFoundOneProblem(cli.command(sql)); assertThat(cli.readLine(), containsString("Unknown index")); } @@ -169,14 +169,14 @@ public class CliSecurityIT extends SqlSecurityTestCase { * Cause the CLI to skip its connection test on startup so we * can get a forbidden exception when we run the query. */ - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), false, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), false, userSecurity(user))) { assertThat(cli.command(sql), containsString("is unauthorized for user [" + user + "]")); } } @Override public void expectUnknownColumn(String user, String sql, String column) throws Exception { - try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) { + try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) { ErrorsTestCase.assertFoundOneProblem(cli.command(sql)); assertThat(cli.readLine(), containsString("Unknown column [" + column + "]" + ErrorsTestCase.END)); } @@ -186,7 +186,7 @@ public class CliSecurityIT extends SqlSecurityTestCase { public void checkNoMonitorMain(String user) throws Exception { // Building the cli will attempt the connection and run the assertion @SuppressWarnings("resource") // forceClose will close it - RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user)) { + EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user)) { @Override protected void assertConnectionTest() throws IOException { assertThat(readLine(), containsString("action [cluster:monitor/main] is unauthorized for user [" + user + "]")); diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSelectIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSelectIT.java index 706fbf13f66..596fd1e7236 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSelectIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliSelectIT.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.qa.sql.security; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; import org.elasticsearch.xpack.qa.sql.cli.SelectTestCase; public class CliSelectIT extends SelectTestCase { diff --git a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliShowIT.java b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliShowIT.java index f1f9d2a6258..c05dbcc3d13 100644 --- a/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliShowIT.java +++ b/qa/sql/security/src/test/java/org/elasticsearch/xpack/qa/sql/security/CliShowIT.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.qa.sql.security; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; import org.elasticsearch.xpack.qa.sql.cli.ShowTestCase; public class CliShowIT extends ShowTestCase { diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/CliIntegrationTestCase.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/CliIntegrationTestCase.java index 88407026f6c..9b8ffff6f40 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/CliIntegrationTestCase.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/CliIntegrationTestCase.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig; +import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig; import org.junit.After; import org.junit.Before; @@ -31,14 +31,14 @@ public abstract class CliIntegrationTestCase extends ESRestTestCase { return cluster.split(",")[0]; } - private RemoteCli cli; + private EmbeddedCli cli; /** * Asks the CLI Fixture to start a CLI instance. */ @Before public void startCli() throws IOException { - cli = new RemoteCli(CliIntegrationTestCase.elasticsearchAddress(), true, securityConfig()); + cli = new EmbeddedCli(CliIntegrationTestCase.elasticsearchAddress(), true, securityConfig()); } @After diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/EmbeddedCli.java similarity index 98% rename from qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java rename to qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/EmbeddedCli.java index be0c956c5d3..f9208f71418 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/RemoteCli.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/cli/EmbeddedCli.java @@ -58,9 +58,8 @@ import static org.junit.Assert.fail; * the CLI using packaging tests which is super "real" but not super fast * and doesn't run super frequently. */ -public class RemoteCli implements Closeable { - // TODO rename this class to EmbeddedCli very soon - private static final Logger logger = Loggers.getLogger(RemoteCli.class); +public class EmbeddedCli implements Closeable { + private static final Logger logger = Loggers.getLogger(EmbeddedCli.class); private final Thread exec; private final Cli cli; @@ -73,7 +72,7 @@ public class RemoteCli implements Closeable { */ private boolean closed = false; - public RemoteCli(String elasticsearchAddress, boolean checkConnectionOnStartup, + public EmbeddedCli(String elasticsearchAddress, boolean checkConnectionOnStartup, @Nullable SecurityConfig security) throws IOException { PipedOutputStream outgoing = new PipedOutputStream(); PipedInputStream cliIn = new PipedInputStream(outgoing);