Search in sources :

Example 21 with OpResult

use of org.apache.zookeeper.OpResult in project zookeeper by apache.

the class CreateTTLTest method testMulti.

@Test
public void testMulti() throws KeeperException, InterruptedException {
    Op createTtl = Op.create("/a", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 100);
    Op createTtlSequential = Op.create("/b", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 200);
    Op createNonTtl = Op.create("/c", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    List<OpResult> results = zk.multi(Arrays.asList(createTtl, createTtlSequential, createNonTtl));
    String sequentialPath = ((OpResult.CreateResult) results.get(1)).getPath();
    final AtomicLong fakeElapsed = new AtomicLong(0);
    ContainerManager containerManager = newContainerManager(fakeElapsed);
    containerManager.checkContainers();
    assertNotNull(zk.exists("/a", false), "node should not have been deleted yet");
    assertNotNull(zk.exists(sequentialPath, false), "node should not have been deleted yet");
    assertNotNull(zk.exists("/c", false), "node should never be deleted");
    fakeElapsed.set(110);
    containerManager.checkContainers();
    assertNull(zk.exists("/a", false), "node should have been deleted");
    assertNotNull(zk.exists(sequentialPath, false), "node should not have been deleted yet");
    assertNotNull(zk.exists("/c", false), "node should never be deleted");
    fakeElapsed.set(210);
    containerManager.checkContainers();
    assertNull(zk.exists("/a", false), "node should have been deleted");
    assertNull(zk.exists(sequentialPath, false), "node should have been deleted");
    assertNotNull(zk.exists("/c", false), "node should never be deleted");
}
Also used : Op(org.apache.zookeeper.Op) AtomicLong(java.util.concurrent.atomic.AtomicLong) OpResult(org.apache.zookeeper.OpResult) Test(org.junit.jupiter.api.Test)

Example 22 with OpResult

use of org.apache.zookeeper.OpResult in project xian by happyyangyuan.

the class CuratorTransactionImpl method doOperation.

private List<OpResult> doOperation(AtomicBoolean firstTime) throws Exception {
    boolean localFirstTime = firstTime.getAndSet(false);
    if (!localFirstTime) {
    }
    List<OpResult> opResults = client.getZooKeeper().multi(transaction);
    if (opResults.size() > 0) {
        OpResult firstResult = opResults.get(0);
        if (firstResult.getType() == ZooDefs.OpCode.error) {
            OpResult.ErrorResult error = (OpResult.ErrorResult) firstResult;
            KeeperException.Code code = KeeperException.Code.get(error.getErr());
            if (code == null) {
                code = KeeperException.Code.UNIMPLEMENTED;
            }
            throw KeeperException.create(code);
        }
    }
    return opResults;
}
Also used : OpResult(org.apache.zookeeper.OpResult) KeeperException(org.apache.zookeeper.KeeperException)

Example 23 with OpResult

use of org.apache.zookeeper.OpResult in project xian by happyyangyuan.

the class CuratorTransactionImpl method makeCuratorResult.

private CuratorTransactionResult makeCuratorResult(OpResult opResult, CuratorMultiTransactionRecord.TypeAndPath metadata) {
    String resultPath = null;
    Stat resultStat = null;
    switch(opResult.getType()) {
        default:
            {
                // NOP
                break;
            }
        case ZooDefs.OpCode.create:
            {
                OpResult.CreateResult createResult = (OpResult.CreateResult) opResult;
                resultPath = client.unfixForNamespace(createResult.getPath());
                break;
            }
        case ZooDefs.OpCode.setData:
            {
                OpResult.SetDataResult setDataResult = (OpResult.SetDataResult) opResult;
                resultStat = setDataResult.getStat();
                break;
            }
    }
    return new CuratorTransactionResult(metadata.type, metadata.forPath, resultPath, resultStat);
}
Also used : Stat(org.apache.zookeeper.data.Stat) OpResult(org.apache.zookeeper.OpResult) CuratorTransactionResult(org.apache.curator.framework.api.transaction.CuratorTransactionResult)

Example 24 with OpResult

use of org.apache.zookeeper.OpResult in project bookkeeper by apache.

the class TestZKVersionedSetOp method testAbortOpResult.

@Test(timeout = 60000)
public void testAbortOpResult() throws Exception {
    final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
    final CountDownLatch latch = new CountDownLatch(1);
    ZKVersionedSetOp versionedSetOp = new ZKVersionedSetOp(mock(Op.class), new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version r) {
        // no-op
        }

        @Override
        public void onAbort(Throwable t) {
            exception.set(t);
            latch.countDown();
        }
    });
    KeeperException ke = KeeperException.create(KeeperException.Code.SESSIONEXPIRED);
    OpResult opResult = new OpResult.ErrorResult(KeeperException.Code.NONODE.intValue());
    versionedSetOp.abortOpResult(ke, opResult);
    latch.await();
    assertTrue(exception.get() instanceof KeeperException.NoNodeException);
}
Also used : Op(org.apache.zookeeper.Op) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Transaction(org.apache.distributedlog.util.Transaction) Version(org.apache.bookkeeper.versioning.Version) OpResult(org.apache.zookeeper.OpResult) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 25 with OpResult

use of org.apache.zookeeper.OpResult in project zookeeper by apache.

the class MultiOperationTest method multi.

private List<OpResult> multi(ZooKeeper zk, Iterable<Op> ops, boolean useAsync) throws KeeperException, InterruptedException {
    if (useAsync) {
        final MultiResult res = new MultiResult();
        zk.multi(ops, new MultiCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, List<OpResult> opResults) {
                if (!ClientCnxn.isInEventThread()) {
                    throw new RuntimeException("not in event thread");
                }
                synchronized (res) {
                    res.rc = rc;
                    res.results = opResults;
                    res.finished = true;
                    res.notifyAll();
                }
            }
        }, null);
        synchronized (res) {
            while (!res.finished) {
                res.wait();
            }
        }
        // In case of only OpKind.READ operations, no exception is thrown. Errors only marked in form of ErrorResults.
        if (KeeperException.Code.OK.intValue() != res.rc && ops.iterator().next().getKind() != Op.OpKind.READ) {
            KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc));
            throw ke;
        }
        return res.results;
    } else {
        return zk.multi(ops);
    }
}
Also used : OpResult(org.apache.zookeeper.OpResult) MultiCallback(org.apache.zookeeper.AsyncCallback.MultiCallback) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

OpResult (org.apache.zookeeper.OpResult)34 KeeperException (org.apache.zookeeper.KeeperException)21 Op (org.apache.zookeeper.Op)13 MultiCallback (org.apache.zookeeper.AsyncCallback.MultiCallback)10 ErrorResult (org.apache.zookeeper.OpResult.ErrorResult)8 List (java.util.List)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 IOException (java.io.IOException)4 CreateResult (org.apache.zookeeper.OpResult.CreateResult)4 ACL (org.apache.zookeeper.data.ACL)4 Id (org.apache.zookeeper.data.Id)4 Test (org.junit.Test)4 DataStorageManagerException (herddb.storage.DataStorageManagerException)3 CheckResult (org.apache.zookeeper.OpResult.CheckResult)3 DeleteResult (org.apache.zookeeper.OpResult.DeleteResult)3 Stat (org.apache.zookeeper.data.Stat)3 LogExistsException (com.twitter.distributedlog.exceptions.LogExistsException)2 ZKException (com.twitter.distributedlog.exceptions.ZKException)2 ZKOp (com.twitter.distributedlog.zk.ZKOp)2