use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionHooks method testSessionHook.
@Test
public void testSessionHook() throws Exception {
// create session, test if the hook got fired by checking the expected property
SessionHandle sessionHandle = client.openSession(sessionUserName, "foobar", Collections.<String, String>emptyMap());
Assert.assertEquals(1, SessionHookTest.runCount.get());
client.closeSession(sessionHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionManagerMetrics method testActiveSessionMetrics.
@Test
public void testActiveSessionMetrics() throws Exception {
final CyclicBarrier ready = new CyclicBarrier(2);
CyclicBarrier completed = new CyclicBarrier(2);
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
final HiveSession session = sm.getSession(handle);
OperationManager operationManager = mock(OperationManager.class);
when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
session.setOperationManager(operationManager);
new Thread(new Runnable() {
@Override
public void run() {
try {
OperationHandle handle = session.getTables("catalog", "schema", "table", null);
session.closeOperation(handle);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
ready.await();
} catch (InterruptedException | BrokenBarrierException e) {
// ignore
}
}
}
}).start();
ready.await(2, TimeUnit.SECONDS);
ready.reset();
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 1);
completed.await(2, TimeUnit.SECONDS);
ready.await(2, TimeUnit.SECONDS);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIServiceTest method testExecuteStatement.
/**
* Test synchronous query execution
* @throws Exception
*/
@Test
public void testExecuteStatement() throws Exception {
Map<String, String> opConf = new HashMap<String, String>();
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessHandle, queryString, opConf);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
// Create a test table
queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
client.executeStatement(sessHandle, queryString, opConf);
// Execute another query
queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
assertNotNull(opHandle);
OperationStatus opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
OperationState state = opStatus.getState();
// Expect query to be completed now
assertEquals("Query should be finished", OperationState.FINISHED, state);
// Cleanup
queryString = "DROP TABLE TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
client.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCliServiceTestWithCookie method testExecuteStatement.
/**
* Test synchronous query execution
* @throws Exception
*/
@Test
public void testExecuteStatement() throws Exception {
Map<String, String> opConf = new HashMap<String, String>();
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessHandle, queryString, opConf);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
// Create a test table
queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
client.executeStatement(sessHandle, queryString, opConf);
// Execute another query
queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
assertNotNull(opHandle);
OperationStatus opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
OperationState state = opStatus.getState();
// Expect query to be completed now
assertEquals("Query should be finished", OperationState.FINISHED, state);
// Cleanup
queryString = "DROP TABLE TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
client.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCliServiceTestWithCookie method testOpenSession.
@Test
public void testOpenSession() throws Exception {
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
// Close client session
client.closeSession(sessHandle);
}
Aggregations