use of org.apache.hadoop.hive.ql.hooks.WriteEntity in project hive by apache.
the class TestDbTxnManager method testSingleWritePartition.
@Test
public void testSingleWritePartition() throws Exception {
WriteEntity we = addPartitionOutput(newTable(true), WriteEntity.WriteType.INSERT);
QueryPlan qp = new MockQueryPlan(this, HiveOperation.QUERY);
txnMgr.openTxn(ctx, "fred");
txnMgr.acquireLocks(qp, ctx, "fred");
List<HiveLock> locks = ctx.getHiveLocks();
Assert.assertEquals(1, locks.size());
Assert.assertEquals(1, TxnDbUtil.countLockComponents(conf, ((DbLockManager.DbHiveLock) locks.get(0)).lockId));
txnMgr.commitTxn();
locks = txnMgr.getLockManager().getLocks(false, false);
Assert.assertEquals(0, locks.size());
}
use of org.apache.hadoop.hive.ql.hooks.WriteEntity in project hive by apache.
the class TestDbTxnManager method testDDLShared.
@Test
public void testDDLShared() throws Exception {
WriteEntity we = addTableOutput(WriteEntity.WriteType.DDL_SHARED);
QueryPlan qp = new MockQueryPlan(this, HiveOperation.ALTERTABLE_EXCHANGEPARTITION);
txnMgr.openTxn(ctx, "fred");
txnMgr.acquireLocks(qp, ctx, "fred");
List<HiveLock> locks = ctx.getHiveLocks();
Assert.assertEquals(1, locks.size());
Assert.assertEquals(1, TxnDbUtil.countLockComponents(conf, ((DbLockManager.DbHiveLock) locks.get(0)).lockId));
txnMgr.commitTxn();
locks = txnMgr.getLockManager().getLocks(false, false);
Assert.assertEquals(0, locks.size());
}
use of org.apache.hadoop.hive.ql.hooks.WriteEntity in project hive by apache.
the class TestDummyTxnManager method testSingleReadTable.
/**
* Verifies the current database object is not locked if the table read is against different database
* @throws Exception
*/
@Test
public void testSingleReadTable() throws Exception {
// Setup
SessionState.get().setCurrentDatabase("db1");
List<HiveLock> expectedLocks = new ArrayList<HiveLock>();
expectedLocks.add(new ZooKeeperHiveLock("default", new HiveLockObject(), HiveLockMode.SHARED));
expectedLocks.add(new ZooKeeperHiveLock("default.table1", new HiveLockObject(), HiveLockMode.SHARED));
LockedDriverState lDrvState = new LockedDriverState();
LockedDriverState lDrvInp = new LockedDriverState();
lDrvInp.abort();
LockException lEx = new LockException(ErrorMsg.LOCK_ACQUIRE_CANCELLED.getMsg());
when(mockLockManager.lock(anyListOf(HiveLockObj.class), eq(false), eq(lDrvState))).thenReturn(expectedLocks);
when(mockLockManager.lock(anyListOf(HiveLockObj.class), eq(false), eq(lDrvInp))).thenThrow(lEx);
doNothing().when(mockLockManager).setContext(any(HiveLockManagerCtx.class));
doNothing().when(mockLockManager).close();
ArgumentCaptor<List> lockObjsCaptor = ArgumentCaptor.forClass(List.class);
when(mockQueryPlan.getInputs()).thenReturn(createReadEntities());
when(mockQueryPlan.getOutputs()).thenReturn(new HashSet<WriteEntity>());
// Execute
txnMgr.acquireLocks(mockQueryPlan, ctx, "fred", lDrvState);
// Verify
Assert.assertEquals("db1", SessionState.get().getCurrentDatabase());
List<HiveLock> resultLocks = ctx.getHiveLocks();
Assert.assertEquals(expectedLocks.size(), resultLocks.size());
Assert.assertEquals(expectedLocks.get(0).getHiveLockMode(), resultLocks.get(0).getHiveLockMode());
Assert.assertEquals(expectedLocks.get(0).getHiveLockObject().getName(), resultLocks.get(0).getHiveLockObject().getName());
Assert.assertEquals(expectedLocks.get(1).getHiveLockMode(), resultLocks.get(1).getHiveLockMode());
Assert.assertEquals(expectedLocks.get(0).getHiveLockObject().getName(), resultLocks.get(0).getHiveLockObject().getName());
verify(mockLockManager).lock(lockObjsCaptor.capture(), eq(false), eq(lDrvState));
List<HiveLockObj> lockObjs = lockObjsCaptor.getValue();
Assert.assertEquals(2, lockObjs.size());
Assert.assertEquals("default", lockObjs.get(0).getName());
Assert.assertEquals(HiveLockMode.SHARED, lockObjs.get(0).mode);
Assert.assertEquals("default/table1", lockObjs.get(1).getName());
Assert.assertEquals(HiveLockMode.SHARED, lockObjs.get(1).mode);
// Execute
try {
txnMgr.acquireLocks(mockQueryPlan, ctx, "fred", lDrvInp);
Assert.fail();
} catch (LockException le) {
Assert.assertEquals(le.getMessage(), ErrorMsg.LOCK_ACQUIRE_CANCELLED.getMsg());
}
}
Aggregations