drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject drill git commit: DRILL-2127: make JDBC tests re-use bit instances; reset cached bits on failure
Date Fri, 13 Feb 2015 19:50:43 GMT
Repository: drill
Updated Branches:
  refs/heads/master e46d68bee -> 4ed0a8d68


DRILL-2127: make JDBC tests re-use bit instances; reset cached bits on failure


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/4ed0a8d6
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/4ed0a8d6
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/4ed0a8d6

Branch: refs/heads/master
Commit: 4ed0a8d68ec5ef344fb54ff7c9d857f7f3f153aa
Parents: e46d68b
Author: Hanifi Gunes <hgunes@maprtech.com>
Authored: Fri Feb 6 12:57:15 2015 -0800
Committer: vkorukanti <venki.korukanti@gmail.com>
Committed: Thu Feb 12 14:06:12 2015 -0800

----------------------------------------------------------------------
 .../apache/drill/common/config/DrillConfig.java |   4 +-
 .../drill/jdbc/CachingConnectionFactory.java    |  31 +++
 .../apache/drill/jdbc/ConnectionFactory.java    |  33 +++
 .../org/apache/drill/jdbc/ConnectionInfo.java   |  81 ++++++
 .../java/org/apache/drill/jdbc/JdbcTest.java    |  98 ++++++-
 .../jdbc/MultiConnectionCachingFactory.java     |  65 +++++
 .../drill/jdbc/NonClosableConnection.java       | 272 +++++++++++++++++++
 .../jdbc/SingleConnectionCachingFactory.java    |  53 ++++
 .../org/apache/drill/jdbc/test/JdbcAssert.java  |  71 +++--
 .../drill/jdbc/test/JdbcTestQueryBase.java      |   4 +-
 .../jdbc/test/TestAggregateFunctionsQuery.java  |   3 +-
 .../drill/jdbc/test/TestHiveScalarUDFs.java     |   3 +-
 .../apache/drill/jdbc/test/TestHiveStorage.java |   4 +-
 .../apache/drill/jdbc/test/TestMetadataDDL.java |   2 +-
 .../org/apache/drill/jdbc/test/TestViews.java   |   2 +-
 15 files changed, 687 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
index f075cc9..dee8a8a 100644
--- a/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
+++ b/common/src/main/java/org/apache/drill/common/config/DrillConfig.java
@@ -96,9 +96,9 @@ public final class DrillConfig extends NestedConfig{
   }
 
   /**
-   * Creates a {{@link DrillConfig configuration}} disabling server specific configuration
options.
+   * Creates a {@link DrillConfig configuration} disabling server specific configuration
options.
    *
-   * @return {{@link DrillConfig}} instance
+   * @return {@link DrillConfig} instance
    */
   public static DrillConfig forClient() {
     return create(null, false);

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/CachingConnectionFactory.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/CachingConnectionFactory.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/CachingConnectionFactory.java
new file mode 100644
index 0000000..df64366
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/CachingConnectionFactory.java
@@ -0,0 +1,31 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.SQLException;
+
+/**
+ * A connection factory that caches connections.
+ */
+public interface CachingConnectionFactory extends ConnectionFactory {
+
+  /**
+   * Closes all active connections in the cache.
+   */
+  void close() throws SQLException;
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionFactory.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionFactory.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionFactory.java
new file mode 100644
index 0000000..8491436
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionFactory.java
@@ -0,0 +1,33 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * A factory used to create {@link java.sql.Connection} instances.
+ */
+public interface ConnectionFactory {
+  /**
+   * Creates a new {@link java.sql.Connection} based on the given {@link org.apache.drill.jdbc.ConnectionInfo
info}
+   *
+   * @param info connection parameters
+   * @throws Exception if factory fails to create a connection.
+   */
+  Connection createConnection(ConnectionInfo info) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionInfo.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionInfo.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionInfo.java
new file mode 100644
index 0000000..282eba8
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ConnectionInfo.java
@@ -0,0 +1,81 @@
+/**
+ * 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.drill.jdbc;
+
+import java.util.Map;
+import java.util.Properties;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * An immutable bag of parameters that describes a {@link java.sql.Connection}.
+ */
+public class ConnectionInfo {
+  private final String url;
+  private final Map<Object, Object> params;
+
+  public ConnectionInfo(String url, Properties params) {
+    this(url, ImmutableMap.copyOf(params));
+  }
+
+  public ConnectionInfo(String url, ImmutableMap<Object, Object> params) {
+    this.url = Preconditions.checkNotNull(url, "URL cannot be null");
+    this.params = params;
+  }
+
+  /**
+   * Returns connection url.
+   */
+  public String getUrl() {
+    return url;
+  }
+
+  /**
+   * Returns connection parameters.
+   */
+  public Map<Object, Object> getParameters() {
+    return params;
+  }
+
+  /**
+   * Creates a new {@link java.util.Properties} instance from underlying parameters.
+   */
+  public Properties getParamsAsProperties() {
+    final Properties props = new Properties();
+    for (Object key:params.keySet()) {
+      props.put(key, params.get(key));
+    }
+    return props;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(url, params);
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj instanceof ConnectionInfo) {
+      final ConnectionInfo info = ConnectionInfo.class.cast(obj);
+      return Objects.equal(url, info.getUrl()) && Objects.equal(params, info.getParameters());
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTest.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTest.java
index 3f44ed8..40b1445 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTest.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTest.java
@@ -17,8 +17,104 @@
  */
 package org.apache.drill.jdbc;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import com.google.common.base.Strings;
 import org.apache.drill.exec.ExecTest;
+import org.apache.drill.jdbc.test.JdbcAssert;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
 
-public class JdbcTest extends ExecTest{
+public class JdbcTest extends ExecTest {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JdbcTest.class);
+
+  @Rule
+  public final TestRule watcher = new TestWatcher() {
+    @Override
+    protected void failed(Throwable e, Description description) {
+      reset();
+    }
+  };
+
+  private static CachingConnectionFactory factory;
+
+  @BeforeClass
+  public static void setUp() {
+    factory = new SingleConnectionCachingFactory(new ConnectionFactory() {
+      @Override
+      public Connection createConnection(ConnectionInfo info) throws Exception {
+        Class.forName("org.apache.drill.jdbc.Driver");
+        return DriverManager.getConnection(info.getUrl(), info.getParamsAsProperties());
+      }
+    });
+    JdbcAssert.setFactory(factory);
+  }
+
+  /**
+   * Creates a {@link java.sql.Connection connection} using default parameters.
+   * @param url connection URL
+   * @throws Exception if connection fails
+   */
+  protected static Connection connect(String url) throws Exception {
+    return connect(url, JdbcAssert.getDefaultProperties());
+  }
+
+
+  /**
+   * Creates a {@link java.sql.Connection connection} using the given parameters.
+   * @param url connection URL
+   * @param info connection info
+   * @throws Exception if connection fails
+   */
+  protected static Connection connect(String url, Properties info) throws Exception {
+    final Connection conn = factory.createConnection(new ConnectionInfo(url, info));
+    changeSchemaIfSupplied(conn, info);
+    return conn;
+  }
+
+  /**
+   * Changes schema of the given connection if the field "schema" is present in {@link java.util.Properties
info}.
+   * Does nothing otherwise.
+   */
+  protected static void changeSchemaIfSupplied(Connection conn, Properties info) {
+    final String schema = info.getProperty("schema", null);
+    if (!Strings.isNullOrEmpty(schema)) {
+      changeSchema(conn, schema);
+    }
+  }
+
+  protected static void changeSchema(Connection conn, String schema) {
+    final String query = String.format("use %s", schema);
+    try {
+      Statement s = conn.createStatement();
+      ResultSet r = s.executeQuery(query);
+    } catch (SQLException e) {
+      throw new RuntimeException("unable to change schema", e);
+    }
+  }
+
+  /**
+   * Resets the factory closing all of the active connections.
+   */
+  protected static void reset() {
+    try {
+      factory.close();
+    } catch (SQLException e) {
+      throw new RuntimeException("error while closing connection factory", e);
+    }
+  }
+
+  @AfterClass
+  public static void clearUp() throws Exception {
+    factory.close();
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/MultiConnectionCachingFactory.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/MultiConnectionCachingFactory.java
b/exec/jdbc/src/test/java/org/apache/drill/jdbc/MultiConnectionCachingFactory.java
new file mode 100644
index 0000000..189942d
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/MultiConnectionCachingFactory.java
@@ -0,0 +1,65 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A connection factory that caches connections based on given {@link org.apache.drill.jdbc.ConnectionInfo}.
+ */
+public class MultiConnectionCachingFactory implements CachingConnectionFactory {
+  private static final Logger logger = LoggerFactory.getLogger(MultiConnectionCachingFactory.class);
+
+  private final ConnectionFactory delegate;
+  private final Map<ConnectionInfo, Connection> cache = Maps.newHashMap();
+
+  public MultiConnectionCachingFactory(ConnectionFactory delegate) {
+    this.delegate = delegate;
+  }
+
+  /**
+   * Creates a {@link org.apache.drill.jdbc.NonClosableConnection connection} and caches
it.
+   *
+   * The returned {@link org.apache.drill.jdbc.NonClosableConnection connection} does not
support
+   * {@link java.sql.Connection#close()}. Consumer must call {#close} to close the cached
connections.
+   */
+  @Override
+  public Connection createConnection(ConnectionInfo info) throws Exception {
+    Connection conn = cache.get(info);
+    if (conn == null) {
+      conn = delegate.createConnection(info);
+      cache.put(info, conn);
+    }
+    return new NonClosableConnection(conn);
+  }
+
+  /**
+   * Closes all active connections in the cache.
+   */
+  public void close() throws SQLException {
+    for (Connection conn:cache.values()) {
+      conn.close();
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/NonClosableConnection.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/NonClosableConnection.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/NonClosableConnection.java
new file mode 100644
index 0000000..1e37700
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/NonClosableConnection.java
@@ -0,0 +1,272 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Executor;
+
+import parquet.Preconditions;
+
+/**
+ * A connection decorator that ignores {@link java.sql.Connection#close} calls.
+ *
+ * All other calls are delegated to inner {@link java.sql.Connection connection}.
+ */
+public final class NonClosableConnection implements Connection {
+  private final Connection delegate;
+
+  public NonClosableConnection(final Connection delegate) {
+    this.delegate = Preconditions.checkNotNull(delegate, "delegate cannot be null");
+  }
+
+  public static NonClosableConnection of(final Connection inner) {
+    return new NonClosableConnection(inner);
+  }
+
+  public <T> T unwrap(Class<T> iface) throws SQLException {
+    return delegate.unwrap(iface);
+  }
+
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    return delegate.isWrapperFor(iface);
+  }
+
+  public Statement createStatement() throws SQLException {
+    return delegate.createStatement();
+  }
+
+  public PreparedStatement prepareStatement(String sql) throws SQLException {
+    return delegate.prepareStatement(sql);
+  }
+
+  public CallableStatement prepareCall(String sql) throws SQLException {
+    return delegate.prepareCall(sql);
+  }
+
+  public String nativeSQL(String sql) throws SQLException {
+    return delegate.nativeSQL(sql);
+  }
+
+  public void setAutoCommit(boolean autoCommit) throws SQLException {
+    delegate.setAutoCommit(autoCommit);
+  }
+
+  public boolean getAutoCommit() throws SQLException {
+    return delegate.getAutoCommit();
+  }
+
+  public void commit() throws SQLException {
+    delegate.commit();
+  }
+
+  public void rollback() throws SQLException {
+    delegate.rollback();
+  }
+
+  public void close() throws SQLException {
+    // noop here. this instance is non-closable.
+  }
+
+  public boolean isClosed() throws SQLException {
+    return delegate.isClosed();
+  }
+
+  public DatabaseMetaData getMetaData() throws SQLException {
+    return delegate.getMetaData();
+  }
+
+  public void setReadOnly(boolean readOnly) throws SQLException {
+    delegate.setReadOnly(readOnly);
+  }
+
+  public boolean isReadOnly() throws SQLException {
+    return delegate.isReadOnly();
+  }
+
+  public void setCatalog(String catalog) throws SQLException {
+    delegate.setCatalog(catalog);
+  }
+
+  public String getCatalog() throws SQLException {
+    return delegate.getCatalog();
+  }
+
+  public void setTransactionIsolation(int level) throws SQLException {
+    delegate.setTransactionIsolation(level);
+  }
+
+  public int getTransactionIsolation() throws SQLException {
+    return delegate.getTransactionIsolation();
+  }
+
+  public SQLWarning getWarnings() throws SQLException {
+    return delegate.getWarnings();
+  }
+
+  public void clearWarnings() throws SQLException {
+    delegate.clearWarnings();
+  }
+
+  public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
{
+    return delegate.createStatement(resultSetType, resultSetConcurrency);
+  }
+
+  public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
+    return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency);
+  }
+
+  public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
+    return delegate.prepareCall(sql, resultSetType, resultSetConcurrency);
+  }
+
+  public Map<String, Class<?>> getTypeMap() throws SQLException {
+    return delegate.getTypeMap();
+  }
+
+  public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+    delegate.setTypeMap(map);
+  }
+
+  public void setHoldability(int holdability) throws SQLException {
+    delegate.setHoldability(holdability);
+  }
+
+  public int getHoldability() throws SQLException {
+    return delegate.getHoldability();
+  }
+
+  public Savepoint setSavepoint() throws SQLException {
+    return delegate.setSavepoint();
+  }
+
+  public Savepoint setSavepoint(String name) throws SQLException {
+    return delegate.setSavepoint(name);
+  }
+
+  public void rollback(Savepoint savepoint) throws SQLException {
+    delegate.rollback(savepoint);
+  }
+
+  public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+    delegate.releaseSavepoint(savepoint);
+  }
+
+  public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
+    return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+  }
+
+  public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
+    return delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+  }
+
+  public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
+    return delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+  }
+
+  public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
{
+    return delegate.prepareStatement(sql, autoGeneratedKeys);
+  }
+
+  public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
{
+    return delegate.prepareStatement(sql, columnIndexes);
+  }
+
+  public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
{
+    return delegate.prepareStatement(sql, columnNames);
+  }
+
+  public Clob createClob() throws SQLException {
+    return delegate.createClob();
+  }
+
+  public Blob createBlob() throws SQLException {
+    return delegate.createBlob();
+  }
+
+  public NClob createNClob() throws SQLException {
+    return delegate.createNClob();
+  }
+
+  public SQLXML createSQLXML() throws SQLException {
+    return delegate.createSQLXML();
+  }
+
+  public boolean isValid(int timeout) throws SQLException {
+    return delegate.isValid(timeout);
+  }
+
+  public void setClientInfo(String name, String value) throws SQLClientInfoException {
+    delegate.setClientInfo(name, value);
+  }
+
+  public void setClientInfo(Properties properties) throws SQLClientInfoException {
+    delegate.setClientInfo(properties);
+  }
+
+  public String getClientInfo(String name) throws SQLException {
+    return delegate.getClientInfo(name);
+  }
+
+  public Properties getClientInfo() throws SQLException {
+    return delegate.getClientInfo();
+  }
+
+  public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+    return delegate.createArrayOf(typeName, elements);
+  }
+
+  public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+    return delegate.createStruct(typeName, attributes);
+  }
+
+  public void setSchema(String schema) throws SQLException {
+    delegate.setSchema(schema);
+  }
+
+  public String getSchema() throws SQLException {
+    return delegate.getSchema();
+  }
+
+  public void abort(Executor executor) throws SQLException {
+    delegate.abort(executor);
+  }
+
+  public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
{
+    delegate.setNetworkTimeout(executor, milliseconds);
+  }
+
+  public int getNetworkTimeout() throws SQLException {
+    return delegate.getNetworkTimeout();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/SingleConnectionCachingFactory.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/SingleConnectionCachingFactory.java
b/exec/jdbc/src/test/java/org/apache/drill/jdbc/SingleConnectionCachingFactory.java
new file mode 100644
index 0000000..88fb4c6
--- /dev/null
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/SingleConnectionCachingFactory.java
@@ -0,0 +1,53 @@
+/**
+ * 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.drill.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * A connection factory that creates and caches a single connection instance.
+ *
+ * Not thread safe.
+ */
+public class SingleConnectionCachingFactory implements CachingConnectionFactory {
+
+  private final ConnectionFactory delegate;
+  private Connection connection;
+
+  public SingleConnectionCachingFactory(ConnectionFactory delegate) {
+    this.delegate = delegate;
+  }
+
+  @Override
+  public Connection createConnection(ConnectionInfo info) throws Exception {
+    if (connection == null) {
+      connection = delegate.createConnection(info);
+    } else {
+      JdbcTest.changeSchemaIfSupplied(connection, info.getParamsAsProperties());
+    }
+    return new NonClosableConnection(connection);
+  }
+
+  @Override
+  public void close() throws SQLException {
+    if (connection != null) {
+      connection.close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java
index 49d7c11..b88d880 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java
@@ -18,7 +18,6 @@
 package org.apache.drill.jdbc.test;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -36,6 +35,9 @@ import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.logical.LogicalPlan;
 import org.apache.drill.common.logical.data.LogicalOperator;
 import org.apache.drill.common.util.Hook;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.jdbc.ConnectionFactory;
+import org.apache.drill.jdbc.ConnectionInfo;
 import org.junit.Assert;
 
 import com.google.common.base.Function;
@@ -48,21 +50,38 @@ import com.google.common.collect.Iterables;
  * Fluent interface for writing JDBC and query-planning tests.
  */
 public class JdbcAssert {
-  public static ModelAndSchema withModel(String model, String schema) {
-    final Properties info = new Properties();
+
+  private static ConnectionFactory factory = null;
+
+  public static void setFactory(ConnectionFactory factory) {
+    JdbcAssert.factory = factory;
+  }
+
+  /**
+   * Returns default bag of properties that is passed to JDBC connection.
+   * By default, includes an option to turn off the web server.
+   */
+  public static Properties getDefaultProperties() {
+    final Properties properties = new Properties();
+    properties.setProperty(ExecConstants.HTTP_ENABLE, "false");
+    return properties;
+  }
+
+  public static ModelAndSchema withModel(final String model, final String schema) {
+    final Properties info = getDefaultProperties();
     info.setProperty("schema", schema);
     info.setProperty("model", "inline:" + model);
-    return new ModelAndSchema(info);
+    return new ModelAndSchema(info, factory);
   }
 
-  public static ModelAndSchema withFull(String schema) {
-    final Properties info = new Properties();
+  public static ModelAndSchema withFull(final String schema) {
+    final Properties info = getDefaultProperties();
     info.setProperty("schema", schema);
-    return new ModelAndSchema(info);
+    return new ModelAndSchema(info, factory);
   }
 
   public static ModelAndSchema withNoDefaultSchema() {
-    return new ModelAndSchema();
+    return new ModelAndSchema(getDefaultProperties(), factory);
   }
 
   static String toString(ResultSet resultSet, int expectedRecordCount) throws SQLException
{
@@ -135,30 +154,25 @@ public class JdbcAssert {
 
   public static class ModelAndSchema {
     private final Properties info;
-    private final ConnectionFactory connectionFactory;
-
-    public ModelAndSchema() {
-      this(null);
-    }
+    private final ConnectionFactoryAdapter adapter;
 
-    public ModelAndSchema(Properties info) {
+    public ModelAndSchema(final Properties info, final ConnectionFactory factory) {
       this.info = info;
-      this.connectionFactory = new ConnectionFactory() {
+      this.adapter = new ConnectionFactoryAdapter() {
         public Connection createConnection() throws Exception {
-          Class.forName("org.apache.drill.jdbc.Driver");
-          return DriverManager.getConnection("jdbc:drill:zk=local", ModelAndSchema.this.info);
+          return factory.createConnection(new ConnectionInfo("jdbc:drill:zk=local", ModelAndSchema.this.info));
         }
       };
     }
 
     public TestDataConnection sql(String sql) {
-      return new TestDataConnection(connectionFactory, sql);
+      return new TestDataConnection(adapter, sql);
     }
 
     public <T> T withConnection(Function<Connection, T> function) throws Exception
{
       Connection connection = null;
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         return function.apply(connection);
       } finally {
         if (connection != null) {
@@ -169,11 +183,11 @@ public class JdbcAssert {
   }
 
   public static class TestDataConnection {
-    private final ConnectionFactory connectionFactory;
+    private final ConnectionFactoryAdapter adapter;
     private final String sql;
 
-    TestDataConnection(ConnectionFactory connectionFactory, String sql) {
-      this.connectionFactory = connectionFactory;
+    TestDataConnection(ConnectionFactoryAdapter adapter, String sql) {
+      this.adapter = adapter;
       this.sql = sql;
     }
 
@@ -184,7 +198,7 @@ public class JdbcAssert {
       Connection connection = null;
       Statement statement = null;
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         statement = connection.createStatement();
         ResultSet resultSet = statement.executeQuery(sql);
         expected = expected.trim();
@@ -209,7 +223,7 @@ public class JdbcAssert {
       Connection connection = null;
       Statement statement = null;
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         statement = connection.createStatement();
         ResultSet resultSet = statement.executeQuery(sql);
         Set<String> result = JdbcAssert.toStringSet(resultSet);
@@ -238,7 +252,7 @@ public class JdbcAssert {
       Connection connection = null;
       Statement statement = null;
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         statement = connection.createStatement();
         ResultSet resultSet = statement.executeQuery(sql);
         Assert.assertEquals(unsortedList(Arrays.asList(expecteds)), unsortedList(JdbcAssert.toStrings(resultSet)));
@@ -260,7 +274,7 @@ public class JdbcAssert {
       Connection connection = null;
       Statement statement = null;
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         statement = connection.createStatement();
         ResultSet resultSet = statement.executeQuery(sql);
         System.out.println(JdbcAssert.toString(resultSet, recordCount));
@@ -296,7 +310,7 @@ public class JdbcAssert {
         }
       });
       try {
-        connection = connectionFactory.createConnection();
+        connection = adapter.createConnection();
         statement = connection.prepareStatement(sql);
         statement.close();
         final String plan = plan0[0].trim();
@@ -332,9 +346,10 @@ public class JdbcAssert {
     }
   }
 
-  private static interface ConnectionFactory {
+  private static interface ConnectionFactoryAdapter {
     Connection createConnection() throws Exception;
   }
+
 }
 
 // End JdbcAssert.java

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcTestQueryBase.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcTestQueryBase.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcTestQueryBase.java
index 64e1f02..4fec567 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcTestQueryBase.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcTestQueryBase.java
@@ -48,10 +48,10 @@ public class JdbcTestQueryBase extends JdbcTest {
 
   protected void testQuery(String sql) throws Exception{
     boolean success = false;
-    try (Connection c = DriverManager.getConnection("jdbc:drill:zk=local", null);) {
+    try (Connection conn = connect("jdbc:drill:zk=local")) {
       for (int x = 0; x < 1; x++) {
         Stopwatch watch = new Stopwatch().start();
-        Statement s = c.createStatement();
+        Statement s = conn.createStatement();
         ResultSet r = s.executeQuery(sql);
         System.out.println(String.format("QueryId: %s", ((DrillResultSet) r).getQueryId()));
         boolean first = true;

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestAggregateFunctionsQuery.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestAggregateFunctionsQuery.java
b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestAggregateFunctionsQuery.java
index f6295bc..aa68e9f 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestAggregateFunctionsQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestAggregateFunctionsQuery.java
@@ -21,11 +21,12 @@ import java.nio.file.Paths;
 import java.sql.Date;
 
 import org.apache.drill.jdbc.Driver;
+import org.apache.drill.jdbc.JdbcTest;
 import org.joda.time.chrono.ISOChronology;
 import org.junit.Test;
 
 
-public class TestAggregateFunctionsQuery {
+public class TestAggregateFunctionsQuery extends JdbcTest {
 
   public static final String WORKING_PATH;
   static{

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java
index 705152e..2c1738c 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveScalarUDFs.java
@@ -20,11 +20,12 @@ package org.apache.drill.jdbc.test;
 
 
 import org.apache.drill.exec.store.hive.HiveTestDataGenerator;
+import org.apache.drill.jdbc.JdbcTest;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
-public class TestHiveScalarUDFs {
+public class TestHiveScalarUDFs extends JdbcTest {
 
   @BeforeClass
   public static void generateHive() throws Exception{

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java
index 86359e0..2c41e12 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestHiveStorage.java
@@ -52,7 +52,7 @@ public class TestHiveStorage extends JdbcTestQueryBase{
     testQuery("SELECT * FROM hive_test.`default`.readtest");
 
     /*
-    JdbcAssert.withFull("hive_test.default")
+    JdbcAssert.withFull("hive_test.`default`")
         .sql("SELECT * FROM readtest")
         .returns(
             "binary_field=[B@7005f08f; " + // know issues with binary display
@@ -86,7 +86,7 @@ public class TestHiveStorage extends JdbcTestQueryBase{
 
   @Test
   public void testOrderByOnHiveTable() throws Exception {
-    JdbcAssert.withFull("hive_test.default")
+    JdbcAssert.withFull("hive_test.`default`")
         .sql("SELECT * FROM kv ORDER BY `value` DESC")
         .returns(
             "key=5; value= key_5\n" +

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
index c52eafd..93925fe 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
@@ -75,7 +75,7 @@ public class TestMetadataDDL extends JdbcTestQueryBase {
 
   @Test
   public void testShowTables() throws Exception{
-    JdbcAssert.withFull("hive_test.default")
+    JdbcAssert.withFull("hive_test.`default`")
         .sql("SHOW TABLES")
         .returnsSet(ImmutableSet.of(
             "TABLE_SCHEMA=hive_test.default; TABLE_NAME=readtest",

http://git-wip-us.apache.org/repos/asf/drill/blob/4ed0a8d6/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index 28fa4a7..0f9e25e 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -335,7 +335,7 @@ public class TestViews extends JdbcTestQueryBase {
 
   @Test
   public void testInfoSchemaWithHiveView() throws Exception {
-    JdbcAssert.withFull("hive_test.default")
+    JdbcAssert.withFull("hive_test.`default`")
         .sql("SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'hiveview'")
         .returns("TABLE_CATALOG=DRILL; TABLE_SCHEMA=hive_test.default; TABLE_NAME=hiveview;
" +
             "VIEW_DEFINITION=SELECT `kv`.`key`, `kv`.`value` FROM `default`.`kv`");


Mime
View raw message