use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.
the class HiveSessionImpl method getTableTypes.
@Override
public OperationHandle getTableTypes() throws HiveSQLException {
acquire(true, true);
OperationManager operationManager = getOperationManager();
GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession());
OperationHandle opHandle = operation.getHandle();
try {
addOpHandle(opHandle);
operation.run();
return opHandle;
} catch (HiveSQLException e) {
removeOpHandle(opHandle);
operationManager.closeOperation(opHandle);
throw e;
} finally {
release(true, true);
}
}
use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.
the class TestSessionGlobalInitFile method doTestSessionGlobalInitFile.
/**
* create session, and fetch the property set in global init file. Test if
* the global init file .hiverc is loaded correctly by checking the expected
* setting property.
*/
private void doTestSessionGlobalInitFile() throws Exception {
OperationManager operationManager = service.getService().getSessionManager().getOperationManager();
SessionHandle sessionHandle = client.openSession(null, null, null);
// ensure there is no operation related object leak
Assert.assertEquals("Verifying all operations used for init file are closed", 0, operationManager.getOperations().size());
verifyInitProperty("a", "1", sessionHandle);
verifyInitProperty("b", "1", sessionHandle);
verifyInitProperty("c", "1", sessionHandle);
verifyInitProperty("hivevar:c", "1", sessionHandle);
verifyInitProperty("d", "1", sessionHandle);
/**
* TODO: client.executeStatement do not support listing resources command
* (beeline> list jar)
*/
// Assert.assertEquals("expected uri", api.getAddedResource("jar"));
Assert.assertEquals("Verifying all operations used for checks are closed", 0, operationManager.getOperations().size());
client.closeSession(sessionHandle);
}
use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.
the class TestSessionManagerMetrics method testActiveSessionTimeMetrics.
@Test
public void testActiveSessionTimeMetrics() throws Exception {
final CyclicBarrier ready = new CyclicBarrier(2);
CyclicBarrier completed = new CyclicBarrier(2);
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
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);
long sessionActivateTime = System.currentTimeMillis();
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_AVG_ACTIVE_SESSION_TIME, (double) System.currentTimeMillis() - sessionActivateTime, 100d);
completed.await(2, TimeUnit.SECONDS);
ready.await(2, TimeUnit.SECONDS);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
}
use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.
the class TestHiveSessionImpl method testLeakOperationHandle.
/**
* Verifying OperationManager.closeOperation(opHandle) is invoked when
* get HiveSQLException during sync query
* @throws HiveSQLException
*/
@Test
public void testLeakOperationHandle() throws HiveSQLException {
// create HiveSessionImpl object
TProtocolVersion protocol = TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2;
String username = "";
String password = "";
HiveConf serverhiveConf = new HiveConf();
String ipAddress = null;
HiveSessionImpl session = new HiveSessionImpl(null, protocol, username, password, serverhiveConf, ipAddress, null) {
@Override
protected synchronized void acquire(boolean userAccess, boolean isOperation) {
}
@Override
protected synchronized void release(boolean userAccess, boolean isOperation) {
}
};
// mock operationManager for session
OperationManager operationManager = Mockito.mock(OperationManager.class);
session.setOperationManager(operationManager);
// mock operation and opHandle for operationManager
ExecuteStatementOperation operation = Mockito.mock(ExecuteStatementOperation.class);
OperationHandle opHandle = Mockito.mock(OperationHandle.class);
Mockito.when(operation.getHandle()).thenReturn(opHandle);
Map<String, String> confOverlay = new HashMap<String, String>();
String hql = "drop table if exists table_not_exists";
Mockito.when(operationManager.newExecuteStatementOperation(same(session), eq(hql), (Map<String, String>) Mockito.any(), eq(true), eq(0L))).thenReturn(operation);
try {
// Running a normal async query with no exceptions,then no need to close opHandle
session.open(new HashMap<String, String>());
session.executeStatementAsync(hql, confOverlay);
Mockito.verify(operationManager, Mockito.times(0)).closeOperation(opHandle);
// Throw an HiveSqlException when do async calls
Mockito.doThrow(new HiveSQLException("Fail for clean up test")).when(operation).run();
session.executeStatementAsync(hql, confOverlay);
Assert.fail("HiveSqlException expected.");
} catch (HiveSQLException e) {
if (!"Fail for clean up test".equals(e.getMessage())) {
Assert.fail("unexpected exception:" + Arrays.toString(e.getStackTrace()));
}
// operationManager.closeOperation() is expected to be invoked once
Mockito.verify(operationManager, Mockito.times(1)).closeOperation(opHandle);
}
}
use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.
the class HiveSessionImpl method getPrimaryKeys.
@Override
public OperationHandle getPrimaryKeys(String catalog, String schema, String table) throws HiveSQLException {
acquire(true, true);
OperationManager operationManager = getOperationManager();
GetPrimaryKeysOperation operation = operationManager.newGetPrimaryKeysOperation(getSession(), catalog, schema, table);
OperationHandle opHandle = operation.getHandle();
try {
addOpHandle(opHandle);
operation.run();
return opHandle;
} catch (HiveSQLException e) {
removeOpHandle(opHandle);
operationManager.closeOperation(opHandle);
throw e;
} finally {
release(true, true);
}
}
Aggregations