aboutsummaryrefslogtreecommitdiff
path: root/bigtop-tests/smoke-tests/odpi-runtime/src/test/java/org/odpi/specs/runtime/hive/JdbcConnector.java
blob: 7512dabfa7e4b3ea5be9b4fa610474d1f0360dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.odpi.specs.runtime.hive;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JdbcConnector {
  private static final Log LOG = LogFactory.getLog(JdbcConnector.class.getName());

  protected static final String URL = "odpi.test.hive.jdbc.url";
  protected static final String USER = "odpi.test.hive.jdbc.user";
  protected static final String PASSWD = "odpi.test.hive.jdbc.password";
  protected static final String LOCATION = "odpi.test.hive.location";
  protected static final String METASTORE_URL = "odpi.test.hive.metastore.url";
  protected static final String TEST_THRIFT = "odpi.test.hive.thrift.test";
  protected static final String TEST_HCATALOG = "odpi.test.hive.hcatalog.test";
  protected static final String HIVE_CONF_DIR = "odpi.test.hive.conf.dir";
  protected static final String HADOOP_CONF_DIR = "odpi.test.hadoop.conf.dir";

  protected static Connection conn;

  @BeforeClass
  public static void connectToJdbc() throws SQLException {
    // Assume they've put the URL for the JDBC driver in an environment variable.
    String jdbcUrl = getProperty(URL, "the JDBC URL");
    String jdbcUser = getProperty(USER, "the JDBC user name");
    String jdbcPasswd = getProperty(PASSWD, "the JDBC password");

    Properties props = new Properties();
    props.put("user", jdbcUser);
    if (!jdbcPasswd.equals("")) props.put("password", jdbcPasswd);
    conn = DriverManager.getConnection(jdbcUrl, props);
  }

  @AfterClass
  public static void closeJdbc() throws SQLException {
    if (conn != null) conn.close();
  }

  protected static String getProperty(String property, String description) {
    String val = System.getProperty(property);
    if (val == null) {
      throw new RuntimeException("You must set the property " + property + " with " +
          description);
    }
    LOG.debug(description + " is " + val);
    return val;
  }

  protected static boolean testActive(String property, String description) {
    String val = System.getProperty(property, "true");
    LOG.debug(description + " is " + val);
    return Boolean.valueOf(val);
  }

}