[ 
https://issues.apache.org/jira/browse/HIVE-25667?focusedWorklogId=708334&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-708334
 ]

ASF GitHub Bot logged work on HIVE-25667:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jan/22 14:18
            Start Date: 13/Jan/22 14:18
    Worklog Time Spent: 10m 
      Work Description: zabetak commented on a change in pull request #2919:
URL: https://github.com/apache/hive/pull/2919#discussion_r783998590



##########
File path: 
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/AbstractDatabase.java
##########
@@ -0,0 +1,302 @@
+package org.apache.hadoop.hive.metastore.dbinstall;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.metastore.tools.schematool.MetastoreSchemaTool;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sqlline.SqlLine;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public abstract class AbstractDatabase extends ExternalResource {
+
+  private final Logger LOG = LoggerFactory.getLogger(AbstractDatabase.class);
+
+  private final int MAX_STARTUP_WAIT = 5 * 60 * 1000;
+  private final String HIVE_USER = "hiveuser";
+  private final String HIVE_PASSWORD = "hivepassword";
+
+  private String db = "hivedb";
+  private boolean verbose = System.getProperty("verbose.schematool") != null;
+  protected boolean useDockerDatabaseArg = false;
+
+  public AbstractDatabase setVerbose(boolean verbose) {
+    this.verbose = verbose;
+    return this;
+  }
+
+  public AbstractDatabase setUseDockerDatabaseArg(boolean 
useDockerDatabaseArg) {
+    this.useDockerDatabaseArg = useDockerDatabaseArg;
+    return this;
+  }
+
+  public AbstractDatabase setDb(String db) {
+    this.db = db;
+    return this;
+  }
+
+  protected abstract String getDockerImageName();
+  protected abstract List<String> getDockerBaseArgs();
+  protected abstract String getDbType();
+  protected abstract String getDbRootUser();
+  protected abstract String getDbRootPassword();
+  public abstract String getJdbcDriver();
+  protected abstract String getJdbcUrl(String hostAddress);
+  protected abstract boolean isContainerReady(ProcessResults pr);
+
+  public String getJdbcUrl() {
+    return getJdbcUrl(getContainerHostAddress());
+  }
+
+  protected String getDockerDatabaseArg() {
+    return null;
+  }
+
+  /**
+   * URL to use when connecting as root rather than Hive
+   *
+   * @return URL
+   */
+  public abstract String getInitialJdbcUrl(String hostAddress);
+
+  public final String getInitialJdbcUrl() {
+    return getInitialJdbcUrl(getContainerHostAddress());
+  }
+
+  public String getHiveUser(){
+    return HIVE_USER;
+  }
+
+  public String getHivePassword(){
+    return HIVE_PASSWORD;
+  }
+
+  protected String getDb() {
+    return db;
+  }
+
+  private String getDockerContainerName() {
+    return String.format("testDb-%s", getClass().getSimpleName());
+  }
+
+  private List<String> getDockerAdditionalArgs() {
+    List<String> dockerArgs = getDockerBaseArgs();
+    if (useDockerDatabaseArg && 
StringUtils.isNotEmpty(getDockerDatabaseArg())) {
+      dockerArgs.addAll(Arrays.asList("-e", getDockerDatabaseArg()));
+    }
+    return dockerArgs;
+  }

Review comment:
       OK makes sense. Thanks for the clarification.




-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 708334)
    Time Spent: 1h 50m  (was: 1h 40m)

> Unify code managing JDBC databases in tests
> -------------------------------------------
>
>                 Key: HIVE-25667
>                 URL: https://issues.apache.org/jira/browse/HIVE-25667
>             Project: Hive
>          Issue Type: Task
>          Components: Testing Infrastructure
>    Affects Versions: 4.0.0
>            Reporter: Stamatis Zampetakis
>            Assignee: Mark Bathori
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Currently there are two class hierarchies managing JDBC databases in tests, 
> [DatabaseRule|https://github.com/apache/hive/blob/d35de014dd49fdcfe0aacb68e6c587beff6d1dea/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/dbinstall/rules/DatabaseRule.java]
>  and 
> [AbstractExternalDB|https://github.com/apache/hive/blob/d35de014dd49fdcfe0aacb68e6c587beff6d1dea/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java].
>  There are many similarities between these hierarchies and certain parts are 
> duplicated. 
> The goal of this JIRA is to refactor the aforementioned hierarchies to reduce 
> code duplication and improve extensibility.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to