Ejemplo n.º 1
0
        private List <OpResult> doOperation(AtomicBoolean firstTime)
        {
            bool localFirstTime = firstTime.getAndSet(false);

            if (!localFirstTime)
            {
            }

            List <OpResult> opResults = client.getZooKeeper().multi(transaction);

            if (opResults.Count > 0)
            {
                OpResult firstResult = opResults[0];
                if (firstResult is OpResult.ErrorResult)
                {
                    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);
        }
Ejemplo n.º 2
0
        private async Task multiHavingErrors(ZooKeeper zk, List <Op> ops, List <KeeperException.Code> expectedResultCodes)
        {
            try
            {
                await multiAsync(zk, ops);

                Assert.fail("Shouldn't have validated in ZooKeeper client!");
            }
            catch (KeeperException e)
            {
                var results = e.getResults();
                for (int i = 0; i < results.Count; i++)
                {
                    OpResult opResult = results[i];
                    Assert.assertTrue("Did't recieve proper error response", opResult is OpResult.ErrorResult);
                    OpResult.ErrorResult errRes = (OpResult.ErrorResult)opResult;
                    Assert.assertEquals("Did't recieve proper error code", expectedResultCodes[i], errRes.getErr());
                }
            }
        }
Ejemplo n.º 3
0
        public async Task TestGetResults()
        {
            var zk = await createClient();

            /* Delete of a node folowed by an update of the (now) deleted node */
            var ops = Arrays.asList(
                Op.create("/multi", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
                Op.delete("/multi", 0),
                Op.setData("/multi", "Y".UTF8getBytes(), 0),
                Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
                );
            List <OpResult> results = null;

            try
            {
                await zk.multiAsync(ops);

                Assert.fail("/multi should have been deleted so setData should have failed");
            }
            catch (KeeperException e)
            {
                // '/multi' should never have been created as entire op should fail
                Assert.assertNull(await zk.existsAsync("/multi", null));
                results = e.getResults();
            }

            Assert.assertNotNull(results);
            foreach (OpResult r in results)
            {
                LOG.info("RESULT==> " + r);
                if (r is OpResult.ErrorResult)
                {
                    OpResult.ErrorResult er = (OpResult.ErrorResult)r;
                    LOG.info("ERROR RESULT: " + er + " ERR=>" + EnumUtil <KeeperException.Code> .DefinedCast(er.getErr()));
                }
            }
        }
Ejemplo n.º 4
0
        public void TestGetResults()
        {
            /* Delete of a node folowed by an update of the (now) deleted node */
            try
            {
                zk.multi(Arrays.asList(Op.create("/multi", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.delete("/multi", 0), Op.setData("/multi", "Y".getBytes(), 0), Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)));
                Assert.fail("/multi should have been deleted so setData should have failed");
            }
            catch (KeeperException e)
            {
                // '/multi' should never have been created as entire op should fail
                Assert.assertNull(zk.exists("/multi", null));

                foreach (OpResult r in e.getResults())
                {
                    LOG.info("RESULT==> " + r);
                    if (r is OpResult.ErrorResult)
                    {
                        OpResult.ErrorResult er = (OpResult.ErrorResult)r;
                        LOG.info("ERROR RESULT: " + er + " ERR=>" + EnumUtil <KeeperException.Code> .DefinedCast(er.getErr()));
                    }
                }
            }
        }