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..28c6de7453
--- /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..59eff994ae
--- /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!";
+ }
+}
\ No newline at end of file
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..b5d48c2f26 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,7 @@ 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 +59,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));
}
}