Search in sources :

Example 6 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestMiniHS2StateWithNoZookeeper method openSessionAndClose.

@Test
public void openSessionAndClose() throws Exception {
    CLIServiceClient client = miniHS2.getServiceClient();
    SessionHandle sessionHandle = client.openSession(null, null, null);
    client.closeSession(sessionHandle);
    Thread.sleep(100);
    Assert.assertEquals(Service.STATE.STARTED, miniHS2.getState());
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Example 7 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestHs2Metrics method testClosedScopes.

@Test
public void testClosedScopes() throws Exception {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    // this should error at analyze scope
    Exception expectedException = null;
    try {
        serviceClient.executeStatement(sessHandle, "select aaa", confOverlay);
    } catch (Exception e) {
        expectedException = e;
    }
    Assert.assertNotNull("Expected semantic exception", expectedException);
    // verify all scopes were recorded
    CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
    String json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_parse", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_semanticAnalyze", 1);
    // verify all scopes are closed.
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_parse", 0);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_semanticAnalyze", 0);
    serviceClient.closeSession(sessHandle);
}
Also used : CodahaleMetrics(org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics) CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) SessionHandle(org.apache.hive.service.cli.SessionHandle) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) Test(org.junit.Test)

Example 8 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestHs2Metrics method testMetrics.

@Test
public void testMetrics() throws Exception {
    String tableName = "testMetrics";
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    // Block on semantic analysis to check 'active_calls'
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + tableName + " (id INT)", confOverlay);
    // check that all calls were recorded.
    CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
    String json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_hs2_operation_INITIALIZED", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_hs2_operation_PENDING", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_hs2_operation_RUNNING", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "hs2_completed_operation_FINISHED", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_hs2_sql_operation_PENDING", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.TIMER, "api_hs2_sql_operation_RUNNING", 1);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "hs2_completed_sql_operation_FINISHED", 1);
    // but there should be no more active calls.
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_semanticAnalyze", 0);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_compile", 0);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_hs2_operation_RUNNING", 0);
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.COUNTER, "active_calls_api_hs2_sql_operation_RUNNING", 0);
    serviceClient.closeSession(sessHandle);
}
Also used : CodahaleMetrics(org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics) CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Example 9 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestHiveServer2 method testConnection.

/**
 * Open a new session and run a test query
 * @throws Exception
 */
@Test
public void testConnection() throws Exception {
    String tableName = "TestHiveServer2TestConnection";
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + tableName + " (id INT)", confOverlay);
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "SHOW TABLES", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertFalse(rowSet.numRows() == 0);
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
    serviceClient.closeSession(sessHandle);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 10 with CLIServiceClient

use of org.apache.hive.service.cli.CLIServiceClient in project hive by apache.

the class TestHiveServer2SessionTimeout method testConnection.

@Test
public void testConnection() throws Exception {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    OperationHandle handle = serviceClient.executeStatement(sessHandle, "SELECT 1", confOverlay);
    Thread.sleep(7000);
    try {
        serviceClient.closeOperation(handle);
        fail("Operation should have been closed by timeout!");
    } catch (HiveSQLException e) {
        assertTrue(StringUtils.stringifyException(e), e.getMessage().contains("Invalid OperationHandle"));
    }
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Aggregations

CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)11 SessionHandle (org.apache.hive.service.cli.SessionHandle)11 Test (org.junit.Test)8 OperationHandle (org.apache.hive.service.cli.OperationHandle)6 RowSet (org.apache.hive.service.cli.RowSet)5 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)2 ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)2 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UtilsForTest (org.apache.hadoop.hive.UtilsForTest)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1 BeeLine (org.apache.hive.beeline.BeeLine)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1