zabetak commented on a change in pull request #2742:
URL: https://github.com/apache/hive/pull/2742#discussion_r737519278
##########
File path:
itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java
##########
@@ -193,96 +147,62 @@ public final String getContainerHostAddress() {
}
}
- public abstract void setJdbcUrl(String hostAddress);
-
- public abstract void setJdbcDriver();
-
- public abstract String getDockerImageName();
-
- public abstract String[] getDockerAdditionalArgs();
-
- public abstract boolean isContainerReady(ProcessResults pr);
+ /**
+ * Return the name of the root user.
+ *
+ * Override the method if the name of the root user must be different than
the default.
+ */
+ protected String getRootUser() {
+ return "qtestuser";
+ }
- protected String[] buildArray(String... strs) {
- return strs;
+ /**
+ * Return the password of the root user.
+ *
+ * Override the method if the password must be different than the default.
+ */
+ protected String getRootPassword() {
+ return "qtestpassword";
}
+
+ protected abstract String getJdbcUrl();
- public Connection getConnectionToExternalDB() throws SQLException,
ClassNotFoundException {
- try {
- LOG.info("external database connection URL:\t " + url);
- LOG.info("JDBC Driver :\t " + driver);
- LOG.info("external database connection User:\t " + userName);
- LOG.info("external database connection Password:\t " + password);
+ protected abstract String getJdbcDriver();
- // load required JDBC driver
- Class.forName(driver);
+ protected abstract String getDockerImageName();
- // Connect using the JDBC URL and user/password
- Connection conn = DriverManager.getConnection(url, userName,
password);
- return conn;
- } catch (SQLException e) {
- LOG.error("Failed to connect to external databse", e);
- throw new SQLException(e);
- } catch (ClassNotFoundException e) {
- LOG.error("Unable to find driver class", e);
- throw new ClassNotFoundException("Unable to find driver class");
- }
- }
+ protected abstract String[] getDockerAdditionalArgs();
- public void testConnectionToExternalDB() throws SQLException,
ClassNotFoundException {
- Connection conn = getConnectionToExternalDB();
- try {
- conn.close();
- } catch (SQLException e) {
- LOG.error("Failed to close external database connection", e);
- }
- }
+ protected abstract boolean isContainerReady(ProcessResults pr);
- protected String[] SQLLineCmdBuild(String sqlScriptFile) throws
IOException {
- return new String[] {"-u", url,
- "-d", driver,
- "-n", userName,
- "-p", password,
+ private String[] SQLLineCmdBuild(String sqlScriptFile) {
+ return new String[] {"-u", getJdbcUrl(),
+ "-d", getJdbcDriver(),
+ "-n", getRootUser(),
+ "-p", getRootPassword(),
"--isolation=TRANSACTION_READ_COMMITTED",
"-f", sqlScriptFile};
}
- protected void execSql(String sqlScriptFile) throws IOException {
- // run the script using SqlLine
- SqlLine sqlLine = new SqlLine();
- ByteArrayOutputStream outputForLog = null;
- OutputStream out;
- if (LOG.isDebugEnabled()) {
- out = outputForLog = new ByteArrayOutputStream();
- } else {
- out = new NullOutputStream();
+ public void execute(String script) throws IOException, SQLException,
ClassNotFoundException {
+ // Test we can connect to database
+ Class.forName(getJdbcDriver());
+ try (Connection ignored = DriverManager.getConnection(getJdbcUrl(),
getRootUser(), getRootPassword())) {
+ LOG.info("Successfully connected to {} with user {} and password
{}", getJdbcUrl(), getRootUser(), getRootPassword());
}
+ LOG.info("Starting {} initialization", getClass().getSimpleName());
+ SqlLine sqlLine = new SqlLine();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
sqlLine.setOutputStream(new PrintStream(out));
+ sqlLine.setErrorStream(new PrintStream(out));
System.setProperty("sqlline.silent", "true");
-
- SqlLine.Status status = sqlLine.begin(SQLLineCmdBuild(sqlScriptFile),
null, false);
- if (LOG.isDebugEnabled() && outputForLog != null) {
- LOG.debug("Received following output from Sqlline:");
- LOG.debug(outputForLog.toString("UTF-8"));
- }
+ SqlLine.Status status = sqlLine.begin(SQLLineCmdBuild(script), null,
false);
+ LOG.debug("Printing output from SQLLine:");
Review comment:
Please check comment
https://github.com/apache/hive/pull/2742/commits/10a2f90dafd040c5fdb59080a88c0c3866745006.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]