use of org.apache.hadoop.hive.metastore.txn.AcidOpenTxnsCounterService in project hive by apache.
the class TestTxnCommands2 method testOpenTxnsCounter.
@Test
public void testOpenTxnsCounter() throws Exception {
hiveConf.setIntVar(HiveConf.ConfVars.HIVE_MAX_OPEN_TXNS, 3);
hiveConf.setTimeVar(HiveConf.ConfVars.HIVE_COUNT_OPEN_TXNS_INTERVAL, 10, TimeUnit.MILLISECONDS);
OpenTxnsResponse openTxnsResponse = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost"));
AcidOpenTxnsCounterService openTxnsCounterService = new AcidOpenTxnsCounterService();
openTxnsCounterService.setConf(hiveConf);
// will update current number of open txns to 3
openTxnsCounterService.run();
MetaException exception = null;
// This should fail once it finds out the threshold has been reached
try {
txnHandler.openTxns(new OpenTxnRequest(1, "you", "localhost"));
} catch (MetaException e) {
exception = e;
}
Assert.assertNotNull("Opening new transaction shouldn't be allowed", exception);
Assert.assertTrue(exception.getMessage().equals("Maximum allowed number of open transactions has been reached. See hive.max.open.txns."));
// new transactions should be allowed to open
for (long txnid : openTxnsResponse.getTxn_ids()) {
txnHandler.commitTxn(new CommitTxnRequest(txnid));
}
// will update current number of open txns back to 0
openTxnsCounterService.run();
exception = null;
try {
txnHandler.openTxns(new OpenTxnRequest(1, "him", "localhost"));
} catch (MetaException e) {
exception = e;
}
Assert.assertNull(exception);
}
Aggregations