You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by pv...@apache.org on 2018/08/28 09:23:38 UTC
hive git commit: HIVE-20396: Test HS2 open_connection metrics (Laszlo
Pinter via Peter Vary)
Repository: hive
Updated Branches:
refs/heads/master 004ec3cef -> 7cf1d0045
HIVE-20396: Test HS2 open_connection metrics (Laszlo Pinter via Peter Vary)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/7cf1d004
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/7cf1d004
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/7cf1d004
Branch: refs/heads/master
Commit: 7cf1d0045b3756da1e4e896f2ede158045bcfa7f
Parents: 004ec3c
Author: Laszlo Pinter <lp...@cloudera.com>
Authored: Tue Aug 28 11:22:58 2018 +0200
Committer: Peter Vary <pv...@cloudera.com>
Committed: Tue Aug 28 11:22:58 2018 +0200
----------------------------------------------------------------------
.../hive/jdbc/miniHS2/Hs2ConnectionMetrics.java | 64 +++++++++++
.../miniHS2/TestHs2ConnectionMetricsBinary.java | 79 +++++++++++++
.../miniHS2/TestHs2ConnectionMetricsHttp.java | 111 +++++++++++++++++++
3 files changed, 254 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/7cf1d004/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/Hs2ConnectionMetrics.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/Hs2ConnectionMetrics.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/Hs2ConnectionMetrics.java
new file mode 100644
index 0000000..06c279e
--- /dev/null
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/Hs2ConnectionMetrics.java
@@ -0,0 +1,64 @@
+/*
+ * 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.hive.jdbc.miniHS2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.metrics.MetricsTestUtils;
+import org.apache.hadoop.hive.common.metrics.common.MetricsConstant;
+import org.apache.hadoop.hive.conf.HiveConf;
+
+/**
+ * Abstract class for connection metrics tests. Implementors of this class are
+ * {@link TestHs2ConnectionMetricsBinary} and {@link TestHs2ConnectionMetricsBinary}. These two
+ * classes are responsible for testing the connection metrics either in binary or in http mode.
+ */
+
+public abstract class Hs2ConnectionMetrics {
+
+ protected static MiniHS2 miniHS2;
+ protected static Map<String, String> confOverlay = new HashMap<>();
+
+ protected static final String USERNAME = System.getProperty("user.name");
+ protected static final String PASSWORD = "foo";
+
+ public static void setup() throws Exception {
+ miniHS2 = new MiniHS2(new HiveConf());
+
+ confOverlay.put(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
+ confOverlay.put(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname,
+ TestHs2Metrics.MetricCheckingHook.class.getName());
+ confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED.varname, "true");
+
+ miniHS2.start(confOverlay);
+ }
+
+ protected void verifyConnectionMetrics(String metricsJson, int expectedOpenConnections,
+ int expectedCumulativeConnections) throws Exception {
+ MetricsTestUtils.verifyMetricsJson(metricsJson, MetricsTestUtils.COUNTER,
+ MetricsConstant.OPEN_CONNECTIONS, expectedOpenConnections);
+ MetricsTestUtils.verifyMetricsJson(metricsJson, MetricsTestUtils.COUNTER,
+ MetricsConstant.CUMULATIVE_CONNECTION_COUNT, expectedCumulativeConnections);
+ }
+
+ public static void tearDown() {
+ miniHS2.stop();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/7cf1d004/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsBinary.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsBinary.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsBinary.java
new file mode 100644
index 0000000..c823cb3
--- /dev/null
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsBinary.java
@@ -0,0 +1,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
+ *
+ * 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.hive.jdbc.miniHS2;
+
+import java.io.IOException;
+
+import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
+import org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.beeline.BeeLine;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the connection metrics using BeeLine client, when HS2 is started in binary mode.
+ */
+public class TestHs2ConnectionMetricsBinary extends Hs2ConnectionMetrics {
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ confOverlay.clear();
+ confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_TRANSPORT_MODE.varname, "binary");
+ confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS.varname, "false");
+ Hs2ConnectionMetrics.setup();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ Hs2ConnectionMetrics.tearDown();
+ }
+
+
+ @Test
+ public void testOpenConnectionMetrics() throws Exception {
+
+ CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
+ String[] beelineArgs = {
+ "-u", miniHS2.getBaseJdbcURL() + "default",
+ "-n", USERNAME,
+ "-p", PASSWORD,
+ "-e", "show tables;"};
+ BeeLine beeLine = openBeeLineConnection(beelineArgs);
+
+ verifyConnectionMetrics(metrics.dumpJson(), 1, 1);
+ beeLine.close();
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 1);
+
+ beeLine = openBeeLineConnection(beelineArgs);
+ verifyConnectionMetrics(metrics.dumpJson(), 1, 2);
+ beeLine.close();
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 2);
+
+
+ }
+
+ private BeeLine openBeeLineConnection(String[] beelineArgs) throws IOException {
+ BeeLine beeLine = new BeeLine();
+ beeLine.begin(beelineArgs, null);
+ return beeLine;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/7cf1d004/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsHttp.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsHttp.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsHttp.java
new file mode 100644
index 0000000..1e29363
--- /dev/null
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHs2ConnectionMetricsHttp.java
@@ -0,0 +1,111 @@
+/*
+ * 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.hive.jdbc.miniHS2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
+import org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hive.jdbc.HttpBasicAuthInterceptor;
+import org.apache.hive.service.rpc.thrift.TCLIService;
+import org.apache.hive.service.rpc.thrift.TCloseSessionReq;
+import org.apache.hive.service.rpc.thrift.TOpenSessionReq;
+import org.apache.hive.service.rpc.thrift.TOpenSessionResp;
+import org.apache.hive.service.rpc.thrift.TSessionHandle;
+import org.apache.http.client.CookieStore;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.THttpClient;
+import org.apache.thrift.transport.TTransport;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the connection metrics using an HttpClient, when HS2 is start in http mode.
+ */
+public class TestHs2ConnectionMetricsHttp extends Hs2ConnectionMetrics {
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ confOverlay.clear();
+ confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_TRANSPORT_MODE.varname, "http");
+ confOverlay.put(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_HTTP_PATH.varname, "cliservice");
+ Hs2ConnectionMetrics.setup();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ Hs2ConnectionMetrics.tearDown();
+ }
+
+ @Test
+ public void testOpenConnectionMetrics() throws Exception {
+ CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
+
+ TCLIService.Client httpClient = getHttpClient();
+ TOpenSessionReq openSessionReq = new TOpenSessionReq();
+ TOpenSessionResp tOpenSessionResp = httpClient.OpenSession(openSessionReq);
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 1);
+ TSessionHandle sessionHandle = tOpenSessionResp.getSessionHandle();
+
+ TCloseSessionReq closeSessionReq = new TCloseSessionReq(sessionHandle);
+ httpClient.CloseSession(closeSessionReq);
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 2);
+
+ tOpenSessionResp = httpClient.OpenSession(openSessionReq);
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 3);
+ sessionHandle = tOpenSessionResp.getSessionHandle();
+
+ closeSessionReq = new TCloseSessionReq(sessionHandle);
+ httpClient.CloseSession(closeSessionReq);
+ verifyConnectionMetrics(metrics.dumpJson(), 0, 4);
+
+ }
+
+ private TCLIService.Client getHttpClient() throws Exception {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+
+ Map<String, String> headers = new HashMap<>();
+ headers.put("Connection", "close");
+ httpClient.addRequestInterceptor(new BasicHttpRequestInterceptor(USERNAME, PASSWORD, null,
+ null, false, headers));
+
+ TTransport transport = new THttpClient(getHttpUrl(), httpClient);
+ TProtocol protocol = new TBinaryProtocol(transport);
+ return new TCLIService.Client(protocol);
+ }
+
+ private String getHttpUrl() {
+ return "http://" + miniHS2.getHost() + ":" + miniHS2.getHttpPort() + "/cliservice/";
+
+ }
+
+ private class BasicHttpRequestInterceptor extends HttpBasicAuthInterceptor {
+ BasicHttpRequestInterceptor(String userName, String password, CookieStore cookieStore,
+ String cn, boolean isSSL,
+ Map<String, String> additionalHeaders) {
+ super(userName, password, cookieStore, cn, isSSL, additionalHeaders, null);
+ }
+ }
+
+}