Search in sources :

Example 1 with Fate

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();
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ZooStore(org.apache.accumulo.fate.ZooStore) TraceRepo(org.apache.accumulo.manager.tableOps.TraceRepo) Manager(org.apache.accumulo.manager.Manager) CountDownLatch(java.util.concurrent.CountDownLatch) Fate(org.apache.accumulo.fate.Fate) ServerContext(org.apache.accumulo.server.ServerContext) TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) AgeOffStore(org.apache.accumulo.fate.AgeOffStore) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)1 AgeOffStore (org.apache.accumulo.fate.AgeOffStore)1 Fate (org.apache.accumulo.fate.Fate)1 TStatus (org.apache.accumulo.fate.ReadOnlyTStore.TStatus)1 ZooStore (org.apache.accumulo.fate.ZooStore)1 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)1 Manager (org.apache.accumulo.manager.Manager)1 TraceRepo (org.apache.accumulo.manager.tableOps.TraceRepo)1 ServerContext (org.apache.accumulo.server.ServerContext)1 KeeperException (org.apache.zookeeper.KeeperException)1 Test (org.junit.Test)1