use of org.apache.accumulo.fate.Fate in project accumulo by apache.
the class FateIT method testTransactionStatus.
@Test(timeout = 30000)
public void testTransactionStatus() throws Exception {
ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, "secret");
zk.mkdirs(ZK_ROOT + Constants.ZFATE);
zk.mkdirs(ZK_ROOT + Constants.ZTABLE_LOCKS);
zk.mkdirs(ZK_ROOT + Constants.ZNAMESPACES + "/" + NS.canonical());
zk.mkdirs(ZK_ROOT + Constants.ZTABLE_STATE + "/" + TID.canonical());
zk.mkdirs(ZK_ROOT + Constants.ZTABLES + "/" + TID.canonical());
ZooStore<Manager> zooStore = new ZooStore<Manager>(ZK_ROOT + Constants.ZFATE, zk);
final AgeOffStore<Manager> store = new AgeOffStore<Manager>(zooStore, 1000 * 60 * 60 * 8, System::currentTimeMillis);
Manager manager = createMock(Manager.class);
ServerContext sctx = createMock(ServerContext.class);
expect(manager.getContext()).andReturn(sctx).anyTimes();
expect(sctx.getZooKeeperRoot()).andReturn(ZK_ROOT).anyTimes();
expect(sctx.getZooReaderWriter()).andReturn(zk).anyTimes();
replay(manager, sctx);
Fate<Manager> fate = new Fate<Manager>(manager, store, TraceRepo::toLogString);
try {
ConfigurationCopy config = new ConfigurationCopy();
config.set(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE, "2");
config.set(Property.MANAGER_FATE_THREADPOOL_SIZE, "1");
fate.startTransactionRunners(config);
// Wait for the transaction runner to be scheduled.
UtilWaitThread.sleep(3000);
callStarted = new CountDownLatch(1);
finishCall = new CountDownLatch(1);
long txid = fate.startTransaction();
assertEquals(TStatus.NEW, getTxStatus(zk, txid));
fate.seedTransaction(txid, new TestOperation(NS, TID), true, "Test Op");
assertEquals(TStatus.SUBMITTED, getTxStatus(zk, txid));
// wait for call() to be called
callStarted.await();
assertEquals(TStatus.IN_PROGRESS, getTxStatus(zk, txid));
// tell the op to exit the method
finishCall.countDown();
// Check that it transitions to SUCCESSFUL
TStatus s = getTxStatus(zk, txid);
while (s != TStatus.SUCCESSFUL) {
s = getTxStatus(zk, txid);
Thread.sleep(10);
}
// Check that it gets removed
boolean errorSeen = false;
while (!errorSeen) {
try {
s = getTxStatus(zk, txid);
Thread.sleep(10);
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.NONODE) {
errorSeen = true;
} else {
fail("Unexpected error thrown: " + e.getMessage());
}
}
}
} finally {
fate.shutdown();
}
}
Aggregations