You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2016/04/12 08:29:57 UTC
hive git commit: HIVE-11615 : Create test for max thrift message
setting (Jason Dere via Ashutosh Chauhan)
Repository: hive
Updated Branches:
refs/heads/master 4eef55b94 -> dc010a362
HIVE-11615 : Create test for max thrift message setting (Jason Dere via Ashutosh Chauhan)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/dc010a36
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/dc010a36
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/dc010a36
Branch: refs/heads/master
Commit: dc010a362a69f0ae29b20397cbfda76468beceec
Parents: 4eef55b
Author: Jason Dere <jd...@hortonworks.com>
Authored: Thu Aug 20 18:16:00 2015 -0800
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Mon Apr 11 23:28:53 2016 -0700
----------------------------------------------------------------------
.../thrift/ThriftCliServiceMessageSizeTest.java | 140 +++++++++++++++++++
1 file changed, 140 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/dc010a36/itests/hive-unit/src/test/java/org/apache/hive/service/cli/thrift/ThriftCliServiceMessageSizeTest.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/service/cli/thrift/ThriftCliServiceMessageSizeTest.java b/itests/hive-unit/src/test/java/org/apache/hive/service/cli/thrift/ThriftCliServiceMessageSizeTest.java
new file mode 100644
index 0000000..fedc992
--- /dev/null
+++ b/itests/hive-unit/src/test/java/org/apache/hive/service/cli/thrift/ThriftCliServiceMessageSizeTest.java
@@ -0,0 +1,140 @@
+package org.apache.hive.service.cli.thrift;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hadoop.hive.metastore.MetaStoreUtils;
+import org.apache.hive.service.Service;
+import org.apache.hive.service.auth.HiveAuthFactory.AuthTypes;
+import org.apache.hive.service.cli.SessionHandle;
+import org.apache.hive.service.server.HiveServer2;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ThriftCliServiceMessageSizeTest {
+ protected static int port;
+ protected static String host = "localhost";
+ protected static HiveServer2 hiveServer2;
+ protected static ThriftCLIServiceClient client;
+ protected static HiveConf hiveConf;
+ protected static String USERNAME = "anonymous";
+ protected static String PASSWORD = "anonymous";
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ // Find a free port
+ port = MetaStoreUtils.findFreePort();
+ hiveServer2 = new HiveServer2();
+ hiveConf = new HiveConf();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ protected static void startHiveServer2WithConf(HiveServer2 hiveServer2, HiveConf hiveConf)
+ throws Exception {
+ hiveServer2.init(hiveConf);
+ // Start HiveServer2 with given config
+ // Fail if server doesn't start
+ try {
+ hiveServer2.start();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail();
+ }
+ // Wait for startup to complete
+ Thread.sleep(2000);
+ System.out.println("HiveServer2 started on port " + port);
+ }
+
+ protected static void stopHiveServer2(HiveServer2 hiveServer2) throws Exception {
+ if (hiveServer2 != null) {
+ hiveServer2.stop();
+ }
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+
+ }
+
+ @Test
+ public void testMessageSize() throws Exception {
+ String transportMode = "binary";
+
+ hiveConf.setBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS, false);
+ hiveConf.setVar(ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST, host);
+ hiveConf.setIntVar(ConfVars.HIVE_SERVER2_THRIFT_PORT, port);
+ hiveConf.setVar(ConfVars.HIVE_SERVER2_AUTHENTICATION, AuthTypes.NONE.toString());
+ hiveConf.setVar(ConfVars.HIVE_SERVER2_TRANSPORT_MODE, transportMode);
+
+ HiveServer2 hiveServer2 = new HiveServer2();
+ String url = "jdbc:hive2://localhost:" + port + "/default";
+ Class.forName("org.apache.hive.jdbc.HiveDriver");
+
+ try {
+ // First start HS2 with high message size limit. This should allow connections
+ hiveConf.setIntVar(ConfVars.HIVE_SERVER2_THRIFT_MAX_MESSAGE_SIZE, 100*1024*1024);
+ startHiveServer2WithConf(hiveServer2, hiveConf);
+
+ System.out.println("Started Thrift CLI service with message size limit "
+ + hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_MAX_MESSAGE_SIZE));
+
+ // With the high message size limit this connection should work
+ Connection connection = DriverManager.getConnection(url, "hiveuser", "hive");
+ Statement stmt = connection.createStatement();
+ assertNotNull("Statement is null", stmt);
+ stmt.execute("set hive.support.concurrency = false");
+ connection.close();
+ stopHiveServer2(hiveServer2);
+
+ // Now start HS2 with low message size limit. This should prevent any connections
+ hiveConf.setIntVar(ConfVars.HIVE_SERVER2_THRIFT_MAX_MESSAGE_SIZE, 1);
+ hiveServer2 = new HiveServer2();
+ startHiveServer2WithConf(hiveServer2, hiveConf);
+ System.out.println("Started Thrift CLI service with message size limit "
+ + hiveConf.getIntVar(ConfVars.HIVE_SERVER2_THRIFT_MAX_MESSAGE_SIZE));
+
+ Exception caughtException = null;
+ try {
+ // This should fail
+ connection = DriverManager.getConnection(url, "hiveuser", "hive");
+ } catch (Exception err) {
+ caughtException = err;
+ }
+ // Verify we hit an error while connecting
+ assertNotNull(caughtException);
+ } finally {
+ stopHiveServer2(hiveServer2);
+ hiveServer2 = null;
+ }
+ }
+}