You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2016/06/20 17:51:44 UTC

[2/2] phoenix git commit: PHOENIX-2998 Add test for setting RPC timeout for a connection

PHOENIX-2998 Add test for setting RPC timeout for a connection


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/56ba3738
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/56ba3738
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/56ba3738

Branch: refs/heads/4.x-HBase-1.1
Commit: 56ba3738652fd2b7f14f3ee0f3d761c64e003e7a
Parents: 137feb6
Author: James Taylor <ja...@apache.org>
Authored: Tue Jun 14 17:16:33 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Mon Jun 20 10:51:30 2016 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/QueryTimeoutIT.java  | 32 +++++++++++++++++-
 .../java/org/apache/phoenix/util/QueryUtil.java | 34 +++++++++++++++-----
 2 files changed, 57 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/56ba3738/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
index ccd6530..fd1f5db 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
@@ -21,6 +21,7 @@ package org.apache.phoenix.end2end;
 
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -36,8 +37,11 @@ import java.util.Properties;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.junit.After;
 import org.junit.BeforeClass;
@@ -51,11 +55,12 @@ public class QueryTimeoutIT extends BaseOwnClusterHBaseManagedTimeIT {
     
     @BeforeClass
     public static void doSetup() throws Exception {
-        Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
+        Map<String,String> props = Maps.newHashMapWithExpectedSize(5);
         // Must update config before starting server
         props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(700));
         props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(10000));
         props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB, Boolean.TRUE.toString());
+        props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
     
@@ -71,6 +76,31 @@ public class QueryTimeoutIT extends BaseOwnClusterHBaseManagedTimeIT {
     }
     
     @Test
+    public void testSetRPCTimeOnConnection() throws Exception {
+        Properties overriddenProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        overriddenProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+        overriddenProps.setProperty("hbase.rpc.timeout", Long.toString(100));
+        String url = QueryUtil.getConnectionUrl(overriddenProps, config, "longRunning");
+        Connection conn1 = DriverManager.getConnection(url, overriddenProps);
+        ConnectionQueryServices s1 = conn1.unwrap(PhoenixConnection.class).getQueryServices();
+        ReadOnlyProps configProps = s1.getProps();
+        assertEquals("100", configProps.get("hbase.rpc.timeout"));
+        
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+        Connection conn2 = DriverManager.getConnection(getUrl(), props);
+        ConnectionQueryServices s2 = conn2.unwrap(PhoenixConnection.class).getQueryServices();
+        assertFalse(s1 == s2);
+        Connection conn3 = DriverManager.getConnection(getUrl(), props);
+        ConnectionQueryServices s3 = conn3.unwrap(PhoenixConnection.class).getQueryServices();
+        assertTrue(s2 == s3);
+        
+        Connection conn4 = DriverManager.getConnection(url, overriddenProps);
+        ConnectionQueryServices s4 = conn4.unwrap(PhoenixConnection.class).getQueryServices();
+        assertTrue(s1 == s4);
+    }
+    
+    @Test
     public void testQueryTimeout() throws Exception {
         int nRows = 30000;
         Connection conn;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/56ba3738/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
index 48259e0..6d8e00d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/QueryUtil.java
@@ -233,39 +233,53 @@ public final class QueryUtil {
      * Create the Phoenix JDBC connection URL from the provided cluster connection details.
      */
     public static String getUrl(String zkQuorum) {
-        return getUrlInternal(zkQuorum, null, null);
+        return getUrlInternal(zkQuorum, null, null, null);
     }
 
     /**
      * Create the Phoenix JDBC connection URL from the provided cluster connection details.
      */
     public static String getUrl(String zkQuorum, int clientPort) {
-        return getUrlInternal(zkQuorum, clientPort, null);
+        return getUrlInternal(zkQuorum, clientPort, null, null);
     }
 
     /**
      * Create the Phoenix JDBC connection URL from the provided cluster connection details.
      */
     public static String getUrl(String zkQuorum, String znodeParent) {
-        return getUrlInternal(zkQuorum, null, znodeParent);
+        return getUrlInternal(zkQuorum, null, znodeParent, null);
+    }
+
+    /**
+     * Create the Phoenix JDBC connection URL from the provided cluster connection details.
+     */
+    public static String getUrl(String zkQuorum, int port, String znodeParent, String principal) {
+        return getUrlInternal(zkQuorum, port, znodeParent, principal);
     }
 
     /**
      * Create the Phoenix JDBC connection URL from the provided cluster connection details.
      */
     public static String getUrl(String zkQuorum, int port, String znodeParent) {
-        return getUrlInternal(zkQuorum, port, znodeParent);
+        return getUrlInternal(zkQuorum, port, znodeParent, null);
     }
 
     /**
      * Create the Phoenix JDBC connection URL from the provided cluster connection details.
      */
     public static String getUrl(String zkQuorum, Integer port, String znodeParent) {
-        return getUrlInternal(zkQuorum, port, znodeParent);
+        return getUrlInternal(zkQuorum, port, znodeParent, null);
+    }
+
+    /**
+     * Create the Phoenix JDBC connection URL from the provided cluster connection details.
+     */
+    public static String getUrl(String zkQuorum, Integer port, String znodeParent, String principal) {
+        return getUrlInternal(zkQuorum, port, znodeParent, principal);
     }
 
-    private static String getUrlInternal(String zkQuorum, Integer port, String znodeParent) {
-        return new PhoenixEmbeddedDriver.ConnectionInfo(zkQuorum, port, znodeParent).toUrl()
+    private static String getUrlInternal(String zkQuorum, Integer port, String znodeParent, String principal) {
+        return new PhoenixEmbeddedDriver.ConnectionInfo(zkQuorum, port, znodeParent, principal, null).toUrl()
                 + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
     }
 
@@ -328,6 +342,10 @@ public final class QueryUtil {
 
     public static String getConnectionUrl(Properties props, Configuration conf)
             throws ClassNotFoundException, SQLException {
+        return getConnectionUrl(props, conf, null);
+    }
+    public static String getConnectionUrl(Properties props, Configuration conf, String principal)
+            throws ClassNotFoundException, SQLException {
         // TODO: props is ignored!
         // read the hbase properties from the configuration
         String server = ZKConfig.getZKQuorumServersString(conf);
@@ -362,7 +380,7 @@ public final class QueryUtil {
         server = Joiner.on(',').join(servers);
         String znodeParent = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
                 HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
-        String url = getUrl(server, port, znodeParent);
+        String url = getUrl(server, port, znodeParent, principal);
         // Mainly for testing to tack on the test=true part to ensure driver is found on server
         String extraArgs = conf.get(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
         if (extraArgs.length() > 0) {