cmd = new ArrayList<>(4 + getDockerAdditionalArgs().length);
- cmd.add("docker");
- cmd.add("run");
- cmd.add("--name");
- cmd.add(getDockerContainerName());
- cmd.addAll(Arrays.asList(getDockerAdditionalArgs()));
- cmd.add(getDockerImageName());
- return cmd.toArray(new String[cmd.size()]);
- }
-
- private String[] buildStopCmd() {
- return buildArray(
- "docker",
- "stop",
- getDockerContainerName()
- );
- }
+ protected abstract DatabaseRule getRule();
- private String[] buildRmCmd() {
- return buildArray(
- "docker",
- "rm",
- getDockerContainerName()
- );
- }
-
- private String[] buildLogCmd() {
- return buildArray(
- "docker",
- "logs",
- getDockerContainerName()
- );
+ protected String[] buildArray(String... strs) {
+ return strs;
}
}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestMysql.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestMysql.java
index 9999d8d705..1c36468252 100644
--- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestMysql.java
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestMysql.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,66 +17,20 @@
*/
package org.apache.hadoop.hive.metastore.dbinstall;
-public class ITestMysql extends DbInstallBase {
-
- @Override
- protected String getDockerImageName() {
- return "mariadb:5.5";
- }
-
- @Override
- protected String[] getDockerAdditionalArgs() {
- return buildArray(
- "-p",
- "3306:3306",
- "-e",
- "MYSQL_ROOT_PASSWORD=" + getDbRootPassword(),
- "-d"
- );
- }
-
- @Override
- protected String getDbType() {
- return "mysql";
- }
-
- @Override
- protected String getDbRootUser() {
- return "root";
- }
-
- @Override
- protected String getDbRootPassword() {
- return "its-a-secret";
- }
+import org.apache.hadoop.hive.metastore.dbinstall.rules.DatabaseRule;
+import org.apache.hadoop.hive.metastore.dbinstall.rules.Mysql;
+import org.junit.Rule;
- @Override
- protected String getJdbcDriver() {
- return org.mariadb.jdbc.Driver.class.getName();
- }
-
- @Override
- protected String getJdbcUrl() {
- return "jdbc:mysql://localhost:3306/" + HIVE_DB;
- }
-
- @Override
- protected String getInitialJdbcUrl() {
- return "jdbc:mysql://localhost:3306/";
- }
-
- @Override
- protected boolean isContainerReady(String logOutput) {
- return logOutput.contains("MySQL init process done. Ready for start up.");
- }
+/**
+ * Mysql-specific DbInstallBase child test class.
+ */
+public class ITestMysql extends DbInstallBase {
- @Override
- protected String getDockerContainerName() {
- return "metastore-test-mysql-install";
- }
+ @Rule
+ public final DatabaseRule databaseRule = new Mysql();
@Override
- protected String getHivePassword() {
- return "hivepassword";
+ protected DatabaseRule getRule() {
+ return databaseRule;
}
}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestOracle.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestOracle.java
index 5b93e0ffae..b2de064a76 100644
--- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestOracle.java
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestOracle.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,67 +17,20 @@
*/
package org.apache.hadoop.hive.metastore.dbinstall;
-public class ITestOracle extends DbInstallBase {
- @Override
- protected String getDockerContainerName() {
- return "metastore-test-oracle-install";
- }
-
- @Override
- protected String getDockerImageName() {
- return "orangehrm/oracle-xe-11g";
- }
-
- @Override
- protected String[] getDockerAdditionalArgs() {
- return buildArray(
- "-p",
- "1521:1521",
- "-e",
- "DEFAULT_SYS_PASS=" + getDbRootPassword(),
- "-e",
- "ORACLE_ALLOW_REMOTE=true",
- "-d"
- );
- }
-
- @Override
- protected String getDbType() {
- return "oracle";
- }
-
- @Override
- protected String getDbRootUser() {
- return "SYS as SYSDBA";
- }
+import org.apache.hadoop.hive.metastore.dbinstall.rules.DatabaseRule;
+import org.apache.hadoop.hive.metastore.dbinstall.rules.Oracle;
+import org.junit.Rule;
- @Override
- protected String getDbRootPassword() {
- return "oracle";
- }
-
- @Override
- protected String getJdbcDriver() {
- return "oracle.jdbc.OracleDriver";
- }
-
- @Override
- protected String getJdbcUrl() {
- return "jdbc:oracle:thin:@//localhost:1521/xe";
- }
-
- @Override
- protected String getInitialJdbcUrl() {
- return "jdbc:oracle:thin:@//localhost:1521/xe";
- }
+/**
+ * Oracle-specific DbInstallBase child test class.
+ */
+public class ITestOracle extends DbInstallBase {
- @Override
- protected boolean isContainerReady(String logOutput) {
- return logOutput.contains("Oracle started successfully!");
- }
+ @Rule
+ public final DatabaseRule databaseRule = new Oracle();
@Override
- protected String getHivePassword() {
- return "hivepassword";
+ protected DatabaseRule getRule() {
+ return databaseRule;
}
}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestPostgres.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestPostgres.java
index 9151ac766e..1e43d4f8ce 100644
--- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestPostgres.java
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestPostgres.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,66 +17,20 @@
*/
package org.apache.hadoop.hive.metastore.dbinstall;
-public class ITestPostgres extends DbInstallBase {
- @Override
- protected String getDockerContainerName() {
- return "metastore-test-postgres-install";
- }
-
- @Override
- protected String getDockerImageName() {
- return "postgres:9.3";
- }
-
- @Override
- protected String[] getDockerAdditionalArgs() {
- return buildArray(
- "-p",
- "5432:5432",
- "-e",
- "POSTGRES_PASSWORD=" + getDbRootPassword(),
- "-d"
-
- );
- }
-
- @Override
- protected String getDbType() {
- return "postgres";
- }
-
- @Override
- protected String getDbRootUser() {
- return "postgres";
- }
+import org.apache.hadoop.hive.metastore.dbinstall.rules.DatabaseRule;
+import org.apache.hadoop.hive.metastore.dbinstall.rules.Postgres;
+import org.junit.Rule;
- @Override
- protected String getDbRootPassword() {
- return "its-a-secret";
- }
-
- @Override
- protected String getJdbcDriver() {
- return org.postgresql.Driver.class.getName();
- }
-
- @Override
- protected String getJdbcUrl() {
- return "jdbc:postgresql://localhost:5432/" + HIVE_DB;
- }
-
- @Override
- protected String getInitialJdbcUrl() {
- return "jdbc:postgresql://localhost:5432/postgres";
- }
+/**
+ * Postgres-specific DbInstallBase child test class.
+ */
+public class ITestPostgres extends DbInstallBase {
- @Override
- protected boolean isContainerReady(String logOutput) {
- return logOutput.contains("database system is ready to accept connections");
- }
+ @Rule
+ public final DatabaseRule databaseRule = new Postgres();
@Override
- protected String getHivePassword() {
- return "hivepassword";
+ protected DatabaseRule getRule() {
+ return databaseRule;
}
}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestSqlServer.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestSqlServer.java
index 67b6eeeab2..6ec0e8764d 100644
--- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestSqlServer.java
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/ITestSqlServer.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,68 +17,20 @@
*/
package org.apache.hadoop.hive.metastore.dbinstall;
-public class ITestSqlServer extends DbInstallBase {
- @Override
- protected String getDockerContainerName() {
- return "metastore-test-mssql-install";
- }
-
- @Override
- protected String getDockerImageName() {
- return "microsoft/mssql-server-linux:2017-GA";
- }
-
- @Override
- protected String[] getDockerAdditionalArgs() {
- return buildArray(
- "-p",
- "1433:1433",
- "-e",
- "ACCEPT_EULA=Y",
- "-e",
- "SA_PASSWORD=" + getDbRootPassword(),
- "-d"
- );
- }
-
- @Override
- protected String getDbType() {
- return "mssql";
- }
-
- @Override
- protected String getDbRootUser() {
- return "SA";
- }
+import org.apache.hadoop.hive.metastore.dbinstall.rules.DatabaseRule;
+import org.apache.hadoop.hive.metastore.dbinstall.rules.Mssql;
+import org.junit.Rule;
- @Override
- protected String getDbRootPassword() {
- return "Its-a-s3cret";
- }
-
- @Override
- protected String getJdbcDriver() {
- return com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName();
- //return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
- }
-
- @Override
- protected String getJdbcUrl() {
- return "jdbc:sqlserver://localhost:1433;DatabaseName=" + HIVE_DB + ";";
- }
-
- @Override
- protected String getInitialJdbcUrl() {
- return "jdbc:sqlserver://localhost:1433";
- }
+/**
+ * Mssql-specific DbInstallBase child test class.
+ */
+public class ITestSqlServer extends DbInstallBase {
- @Override
- protected boolean isContainerReady(String logOutput) {
- return logOutput.contains("Recovery is complete. This is an informational message only. No user action is required.");
- }
+ @Rule
+ public final DatabaseRule databaseRule = new Mssql();
@Override
- protected String getHivePassword() {
- return "h1vePassword!";
+ protected DatabaseRule getRule() {
+ return databaseRule;
}
}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/DatabaseRule.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/DatabaseRule.java
new file mode 100644
index 0000000000..c1f49d8d46
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/DatabaseRule.java
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.hive.metastore.tools.schematool.MetastoreSchemaTool;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract JUnit TestRule for different RDMBS types.
+ */
+public abstract class DatabaseRule extends ExternalResource {
+ private static final Logger LOG = LoggerFactory.getLogger(DatabaseRule.class);
+
+ protected static final String HIVE_USER = "hiveuser";
+ // used in most of the RDBMS configs, except MSSQL
+ protected static final String HIVE_PASSWORD = "hivepassword";
+ protected static final String HIVE_DB = "hivedb";
+ private static final int MAX_STARTUP_WAIT = 5 * 60 * 1000;
+
+ public abstract String getHivePassword();
+
+ public abstract String getDockerImageName();
+
+ public abstract String[] getDockerAdditionalArgs();
+
+ public abstract String getDbType();
+
+ public abstract String getDbRootUser();
+
+ public abstract String getDbRootPassword();
+
+ public abstract String getJdbcDriver();
+
+ public abstract String getJdbcUrl();
+
+ private boolean verbose;
+
+ public DatabaseRule setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ return this;
+ };
+
+ public String getDb() {
+ return HIVE_DB;
+ };
+
+ /**
+ * URL to use when connecting as root rather than Hive
+ *
+ * @return URL
+ */
+ public abstract String getInitialJdbcUrl();
+
+ /**
+ * Determine if the docker container is ready to use.
+ *
+ * @param logOutput output of docker logs command
+ * @return true if ready, false otherwise
+ */
+ public abstract boolean isContainerReady(String logOutput);
+
+ protected String[] buildArray(String... strs) {
+ return strs;
+ }
+
+ private static class ProcessResults {
+ final String stdout;
+ final String stderr;
+ final int rc;
+
+ public ProcessResults(String stdout, String stderr, int rc) {
+ this.stdout = stdout;
+ this.stderr = stderr;
+ this.rc = rc;
+ }
+ }
+
+ @Override
+ public void before() throws Exception { //runDockerContainer
+ if (runCmdAndPrintStreams(buildRunCmd(), 600) != 0) {
+ throw new RuntimeException("Unable to start docker container");
+ }
+ long startTime = System.currentTimeMillis();
+ ProcessResults pr;
+ do {
+ Thread.sleep(5000);
+ pr = runCmd(buildLogCmd(), 5);
+ if (pr.rc != 0) {
+ throw new RuntimeException("Failed to get docker logs");
+ }
+ } while (startTime + MAX_STARTUP_WAIT >= System.currentTimeMillis() && !isContainerReady(pr.stdout));
+ if (startTime + MAX_STARTUP_WAIT < System.currentTimeMillis()) {
+ throw new RuntimeException("Container failed to be ready in " + MAX_STARTUP_WAIT/1000 +
+ " seconds");
+ }
+ MetastoreSchemaTool.setHomeDirForTesting();
+ }
+
+ @Override
+ public void after() { // stopAndRmDockerContainer
+ if ("true".equalsIgnoreCase(System.getProperty("metastore.itest.no.stop.container"))) {
+ LOG.warn("Not stopping container " + getDockerContainerName() + " at user request, please "
+ + "be sure to shut it down before rerunning the test.");
+ return;
+ }
+ try {
+ if (runCmdAndPrintStreams(buildStopCmd(), 60) != 0) {
+ throw new RuntimeException("Unable to stop docker container");
+ }
+ if (runCmdAndPrintStreams(buildRmCmd(), 15) != 0) {
+ throw new RuntimeException("Unable to remove docker container");
+ }
+ } catch (InterruptedException | IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected String getDockerContainerName(){
+ return String.format("metastore-test-%s-install", getDbType());
+ };
+
+ private ProcessResults runCmd(String[] cmd, long secondsToWait)
+ throws IOException, InterruptedException {
+ LOG.info("Going to run: " + StringUtils.join(cmd, " "));
+ Process proc = Runtime.getRuntime().exec(cmd);
+ if (!proc.waitFor(secondsToWait, TimeUnit.SECONDS)) {
+ throw new RuntimeException(
+ "Process " + cmd[0] + " failed to run in " + secondsToWait + " seconds");
+ }
+ BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ final StringBuilder lines = new StringBuilder();
+ reader.lines().forEach(s -> lines.append(s).append('\n'));
+
+ reader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
+ final StringBuilder errLines = new StringBuilder();
+ reader.lines().forEach(s -> errLines.append(s).append('\n'));
+ return new ProcessResults(lines.toString(), errLines.toString(), proc.exitValue());
+ }
+
+ private int runCmdAndPrintStreams(String[] cmd, long secondsToWait)
+ throws InterruptedException, IOException {
+ ProcessResults results = runCmd(cmd, secondsToWait);
+ LOG.info("Stdout from proc: " + results.stdout);
+ LOG.info("Stderr from proc: " + results.stderr);
+ return results.rc;
+ }
+
+ private String[] buildRunCmd() {
+ List cmd = new ArrayList<>(4 + getDockerAdditionalArgs().length);
+ cmd.add("docker");
+ cmd.add("run");
+ cmd.add("--name");
+ cmd.add(getDockerContainerName());
+ cmd.addAll(Arrays.asList(getDockerAdditionalArgs()));
+ cmd.add(getDockerImageName());
+ return cmd.toArray(new String[cmd.size()]);
+ }
+
+ private String[] buildStopCmd() {
+ return buildArray(
+ "docker",
+ "stop",
+ getDockerContainerName()
+ );
+ }
+
+ private String[] buildRmCmd() {
+ return buildArray(
+ "docker",
+ "rm",
+ getDockerContainerName()
+ );
+ }
+
+ private String[] buildLogCmd() {
+ return buildArray(
+ "docker",
+ "logs",
+ getDockerContainerName()
+ );
+ }
+
+ public String getHiveUser(){
+ return HIVE_USER;
+ }
+
+ public int createUser() {
+ return new MetastoreSchemaTool().setVerbose(verbose).run(buildArray(
+ "-createUser",
+ "-dbType",
+ getDbType(),
+ "-userName",
+ getDbRootUser(),
+ "-passWord",
+ getDbRootPassword(),
+ "-hiveUser",
+ getHiveUser(),
+ "-hivePassword",
+ getHivePassword(),
+ "-hiveDb",
+ getDb(),
+ "-url",
+ getInitialJdbcUrl(),
+ "-driver",
+ getJdbcDriver()
+ ));
+ }
+
+ public int installLatest() {
+ return new MetastoreSchemaTool().setVerbose(verbose).run(buildArray(
+ "-initSchema",
+ "-dbType",
+ getDbType(),
+ "-userName",
+ getHiveUser(),
+ "-passWord",
+ getHivePassword(),
+ "-url",
+ getJdbcUrl(),
+ "-driver",
+ getJdbcDriver()
+ ));
+ }
+
+ public int installAVersion(String version) {
+ return new MetastoreSchemaTool().setVerbose(verbose).run(buildArray(
+ "-initSchemaTo",
+ version,
+ "-dbType",
+ getDbType(),
+ "-userName",
+ getHiveUser(),
+ "-passWord",
+ getHivePassword(),
+ "-url",
+ getJdbcUrl(),
+ "-driver",
+ getJdbcDriver()
+ ));
+ }
+
+ public int upgradeToLatest() {
+ return new MetastoreSchemaTool().setVerbose(verbose).run(buildArray(
+ "-upgradeSchema",
+ "-dbType",
+ getDbType(),
+ "-userName",
+ HIVE_USER,
+ "-passWord",
+ getHivePassword(),
+ "-url",
+ getJdbcUrl(),
+ "-driver",
+ getJdbcDriver()
+ ));
+ }
+
+ public void install() {
+ createUser();
+ installLatest();
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Derby.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Derby.java
new file mode 100644
index 0000000000..6415d7ec9f
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Derby.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+import org.apache.hadoop.hive.metastore.tools.schematool.MetastoreSchemaTool;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils;
+
+/**
+ * JUnit TestRule for Derby.
+ */
+public class Derby extends DatabaseRule {
+
+ @Override
+ public String getDockerImageName() {
+ return null;
+ }
+
+ @Override
+ public String[] getDockerAdditionalArgs() {
+ return null;
+ }
+
+ @Override
+ public String getDbType() {
+ return "derby";
+ }
+
+ @Override
+ public String getDbRootUser() {
+ return "APP";
+ }
+
+ @Override
+ public String getHiveUser() {
+ return "APP";
+ }
+
+ @Override
+ public String getDbRootPassword() {
+ return "mine";
+ }
+
+ @Override
+ public String getHivePassword() {
+ return "mine";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return "org.apache.derby.jdbc.EmbeddedDriver";
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return String.format("jdbc:derby:memory:%s/%s;create=true", System.getProperty("test.tmp.dir"),
+ getDb());
+ }
+
+ @Override
+ public String getInitialJdbcUrl() {
+ return String.format("jdbc:derby:memory:%s/%s;create=true", System.getProperty("test.tmp.dir"),
+ getDb());
+ }
+
+ public String getDb() {
+ return MetaStoreServerUtils.JUNIT_DATABASE_PREFIX;
+ };
+
+ @Override
+ public boolean isContainerReady(String logOutput) {
+ return true;
+ }
+
+ @Override
+ public void before() throws Exception {
+ MetastoreSchemaTool.setHomeDirForTesting();
+ }
+
+ @Override
+ public void after() {
+ // no-op, no need for docker container for derby
+ }
+
+ @Override
+ public int createUser() {
+ return 0; // no-op
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mssql.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mssql.java
new file mode 100644
index 0000000000..f9994817e3
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mssql.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+/**
+ * JUnit TestRule for Mssql.
+ */
+public class Mssql extends DatabaseRule {
+
+ @Override
+ public String getDockerImageName() {
+ return "microsoft/mssql-server-linux:2017-GA";
+ }
+
+ @Override
+ public String[] getDockerAdditionalArgs() {
+ return buildArray(
+ "-p",
+ "1433:1433",
+ "-e",
+ "ACCEPT_EULA=Y",
+ "-e",
+ "SA_PASSWORD=" + getDbRootPassword(),
+ "-d"
+ );
+ }
+
+ @Override
+ public String getDbType() {
+ return "mssql";
+ }
+
+ @Override
+ public String getDbRootUser() {
+ return "SA";
+ }
+
+ @Override
+ public String getDbRootPassword() {
+ return "Its-a-s3cret";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName();
+ // return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return "jdbc:sqlserver://localhost:1433;DatabaseName=" + HIVE_DB + ";";
+ }
+
+ @Override
+ public String getInitialJdbcUrl() {
+ return "jdbc:sqlserver://localhost:1433";
+ }
+
+ @Override
+ public boolean isContainerReady(String logOutput) {
+ return logOutput.contains(
+ "Recovery is complete. This is an informational message only. No user action is required.");
+ }
+
+ @Override
+ public String getHivePassword() {
+ return "h1vePassword!";
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mysql.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mysql.java
new file mode 100644
index 0000000000..c537d95470
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Mysql.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+/**
+ * JUnit TestRule for MySql.
+ */
+public class Mysql extends DatabaseRule {
+
+ @Override
+ public String getDockerImageName() {
+ return "mariadb:5.5";
+ }
+
+ @Override
+ public String[] getDockerAdditionalArgs() {
+ return buildArray("-p", "3306:3306", "-e", "MYSQL_ROOT_PASSWORD=" + getDbRootPassword(), "-d");
+ }
+
+ @Override
+ public String getDbType() {
+ return "mysql";
+ }
+
+ @Override
+ public String getDbRootUser() {
+ return "root";
+ }
+
+ @Override
+ public String getDbRootPassword() {
+ return "its-a-secret";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return org.mariadb.jdbc.Driver.class.getName();
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return "jdbc:mysql://localhost:3306/" + HIVE_DB;
+ }
+
+ @Override
+ public String getInitialJdbcUrl() {
+ return "jdbc:mysql://localhost:3306/";
+ }
+
+ @Override
+ public boolean isContainerReady(String logOutput) {
+ return logOutput.contains("MySQL init process done. Ready for start up.");
+ }
+
+ @Override
+ public String getHivePassword() {
+ return HIVE_PASSWORD;
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Oracle.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Oracle.java
new file mode 100644
index 0000000000..0b070e19ac
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Oracle.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+/**
+ * JUnit TestRule for Oracle.
+ */
+public class Oracle extends DatabaseRule {
+
+ @Override
+ public String getDockerImageName() {
+ return "orangehrm/oracle-xe-11g";
+ }
+
+ @Override
+ public String[] getDockerAdditionalArgs() {
+ return buildArray(
+ "-p",
+ "1521:1521",
+ "-e",
+ "DEFAULT_SYS_PASS=" + getDbRootPassword(),
+ "-e",
+ "ORACLE_ALLOW_REMOTE=true",
+ "-d"
+ );
+ }
+
+ @Override
+ public String getDbType() {
+ return "oracle";
+ }
+
+ @Override
+ public String getDbRootUser() {
+ return "SYS as SYSDBA";
+ }
+
+ @Override
+ public String getDbRootPassword() {
+ return "oracle";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return "oracle.jdbc.OracleDriver";
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return "jdbc:oracle:thin:@//localhost:1521/xe";
+ }
+
+ @Override
+ public String getInitialJdbcUrl() {
+ return "jdbc:oracle:thin:@//localhost:1521/xe";
+ }
+
+ @Override
+ public boolean isContainerReady(String logOutput) {
+ return logOutput.contains("Oracle started successfully!");
+ }
+
+ @Override
+ public String getHivePassword() {
+ return HIVE_PASSWORD;
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java
new file mode 100644
index 0000000000..5840095a3f
--- /dev/null
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/Postgres.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.dbinstall.rules;
+
+/**
+ * JUnit TestRule for Postgres.
+ */
+public class Postgres extends DatabaseRule {
+ @Override
+ public String getDockerImageName() {
+ return "postgres:9.3";
+ }
+
+ @Override
+ public String[] getDockerAdditionalArgs() {
+ return buildArray("-p", "5432:5432", "-e", "POSTGRES_PASSWORD=" + getDbRootPassword(), "-d");
+ }
+
+ @Override
+ public String getDbType() {
+ return "postgres";
+ }
+
+ @Override
+ public String getDbRootUser() {
+ return "postgres";
+ }
+
+ @Override
+ public String getDbRootPassword() {
+ return "its-a-secret";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return org.postgresql.Driver.class.getName();
+ }
+
+ @Override
+ public String getJdbcUrl() {
+ return "jdbc:postgresql://localhost:5432/" + HIVE_DB;
+ }
+
+ @Override
+ public String getInitialJdbcUrl() {
+ return "jdbc:postgresql://localhost:5432/postgres";
+ }
+
+ @Override
+ public boolean isContainerReady(String logOutput) {
+ return logOutput.contains("database system is ready to accept connections");
+ }
+
+ @Override
+ public String getHivePassword() {
+ return HIVE_PASSWORD;
+ }
+}
diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/tools/schematool/TestMetastoreSchemaTool.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/tools/schematool/TestMetastoreSchemaTool.java
index b4a0844be3..a93e23b245 100644
--- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/tools/schematool/TestMetastoreSchemaTool.java
+++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/tools/schematool/TestMetastoreSchemaTool.java
@@ -40,7 +40,7 @@
@Mock
private Configuration conf;
private MetastoreSchemaTool.CommandBuilder builder;
- private String pasword = "reallySimplePassword";
+ private String password = "reallySimplePassword";
@Before
public void setup() throws IOException {
@@ -49,7 +49,9 @@ public void setup() throws IOException {
if (!file.exists()) {
file.createNewFile();
}
- builder = new MetastoreSchemaTool.CommandBuilder(conf, null, null, "testUser", pasword, scriptFile);
+ builder =
+ new MetastoreSchemaTool.CommandBuilder(conf, null, null, "testUser", password, scriptFile)
+ .setVerbose(false);
}
@After
@@ -59,12 +61,12 @@ public void globalAssert() throws IOException {
@Test
public void shouldReturnStrippedPassword() throws IOException {
- assertFalse(builder.buildToLog().contains(pasword));
+ assertFalse(builder.buildToLog().contains(password));
}
@Test
public void shouldReturnActualPassword() throws IOException {
String[] strings = builder.buildToRun();
- assertTrue(Arrays.asList(strings).contains(pasword));
+ assertTrue(Arrays.asList(strings).contains(password));
}
}