/** * The asynchronous version of exists. * * @see #exists(String, boolean) */ public void exists(String path, boolean watch, StatCallback cb, Object ctx) { exists(path, watch ? watchManager.defaultWatcher : null, cb, ctx); }
public boolean execute() throws KeeperException, InterruptedException { Stat stat = zookeeper.exists(path, false); if (stat != null) { return true; } zookeeper.create(path, data, acl, flags); return true; } });
public boolean execute() throws KeeperException, InterruptedException { Stat stat = zookeeper.exists(path, false); if (stat != null) { return true; } zookeeper.create(path, data, acl, flags); return true; } });
private void utestExists(int port) throws IOException, InterruptedException, KeeperException { ZooKeeper zk = new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this); for (int i = 0; i < 10000; i++) { zk.exists("/this/path/doesnt_exist!", true); } zk.close(); }
/** * Verify the expected znodes were created and that the last znode, which * caused the roll-over, did not. */ private void checkNodes(ZooKeeper zk, int start, int count) throws Exception { LOG.info("Validating nodes {} thru {}", start, (start + count)); for (int i = start; i < start + count; i++) { Assert.assertNotNull(zk.exists("/foo" + i, false)); LOG.error("Exists zxid:{}", Long.toHexString(zk.exists("/foo" + i, false).getCzxid())); } Assert.assertNull(zk.exists("/foo" + (start + count), false)); }
private void createNoStatVerifyResult(String newName) throws KeeperException, InterruptedException { Assert.assertNull("Node existed before created", zk.exists(newName, false)); zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); Assert.assertNotNull("Node was not created as expected", zk.exists(newName, false)); }
private void createNoStatVerifyResult(String newName) throws KeeperException, InterruptedException { Assert.assertNull("Node existed before created", zk.exists(newName, false)); String path = zk.create(newName, newName.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Assert.assertEquals(path, newName); Assert.assertNotNull("Node was not created as expected", zk.exists(newName, false)); }
private Stat createWithStatVerifyResult(String newName) throws KeeperException, InterruptedException { Assert.assertNull("Node existed before created", zk.exists(newName, false)); Stat stat = new Stat(); zk.create(newName, newName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat); validateCreateStat(stat, newName); Stat referenceStat = zk.exists(newName, false); Assert.assertNotNull("Node was not created as expected", referenceStat); Assert.assertEquals(referenceStat, stat); return stat; }
@Test public void testCreateWithNullStat() throws IOException, KeeperException, InterruptedException { String name = "/foo"; Assert.assertNull(zk.exists(name, false)); Stat stat = null; // If a null Stat object is passed the create should still // succeed, but no Stat info will be returned. String path = zk.create(name, name.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); Assert.assertNull(stat); Assert.assertNotNull(zk.exists(name, false)); }
@SuppressWarnings("ConstantConditions") @Test(timeout = 30000) public void testCreateWithNullStat() throws KeeperException, InterruptedException { final String name = "/foo"; Assert.assertNull(zk.exists(name, false)); Stat stat = null; // If a null Stat object is passed the create should still // succeed, but no Stat info will be returned. zk.create(name, name.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, stat); Assert.assertNull(stat); Assert.assertNotNull(zk.exists(name, false)); }
public void verifyExistsFailure_NoNode() { rc = KeeperException.Code.NONODE; stat = null; zk.exists(path, false, this, toString()); verify(); }
private Stat createWithStatVerifyResult(String newName) throws KeeperException, InterruptedException { Assert.assertNull("Node existed before created", zk.exists(newName, false)); Stat stat = new Stat(); String path = zk.create(newName, newName.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); Assert.assertEquals(path, newName); validateCreateStat(stat, newName); Stat referenceStat = zk.exists(newName, false); Assert.assertNotNull("Node was not created as expected", referenceStat); Assert.assertEquals(referenceStat, stat); return stat; }
public static void main(String[] args) throws Exception { System.out.printf("Starting\n"); final TimeTest test = new TimeTest(); System.out.printf("After construct\n"); test.setUp(); ZooKeeper zk = test.createClient(); zk.create("/ephemeral", new byte[]{1, 2, 3}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); while (Time.currentElapsedTime() - nt0 < 100000) { System.out.printf("%d\t%s\n", discrepancy(), zk.exists("/ephemeral", watchCount.get() == 0 ? createWatcher() : null) != null); waitByYielding(500); } }
public void verifyMultiFailure_NoSideEffect() throws KeeperException, InterruptedException { List<Op> ops = Arrays.asList( Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.delete("/nonexist1", -1)); zk.multi(ops, this, null); latch_await(); Assert.assertTrue(this.opResults.get(0) instanceof OpResult.ErrorResult); Assert.assertNull(zk.exists("/multi", false)); }
@Test public void testNodeCreated() throws Exception { String path = "/test1-created"; zk1.exists(path, watcher); qu.shutdown(1); zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); qu.start(1); watcher.waitForConnected(TIMEOUT * 1000L); watcher.assertEvent(TIMEOUT, EventType.NodeCreated); }
@Test public void testCreateDelete() throws Exception { multi(zk, Arrays.asList( Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.delete("/multi", 0) )); // '/multi' should have been deleted Assert.assertNull(zk.exists("/multi", null)); }
@Test(timeout = 30000) public void testSimpleDeletion() throws KeeperException, InterruptedException { zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); zk.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.delete("/foo/bar", -1); // should cause "/foo" to get deleted when checkContainers() is called ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100); containerManager.checkContainers(); Thread.sleep(1000); Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); }
public void verifyExists() { new StringCB(zk).verifyCreate(); zk.exists(path, false, this, toString()); verify(); }
@Test public void testDeleteUpdateConflict() throws Exception { /* Delete of a node folowed by an update of the (now) deleted node */ try { multi(zk, Arrays.asList( Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.delete("/multi", 0), Op.setData("/multi", "Y".getBytes(), 0) )); Assert.fail("/multi should have been deleted so setData should have failed"); } catch (KeeperException e) { /* PASS */ } // '/multi' should never have been created as entire op should fail Assert.assertNull(zk.exists("/multi", null)) ; }
@Test public void testNodeDataChanged() throws Exception { String path = "/test-changed"; zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Stat stat1 = zk1.exists(path, watcher); qu.shutdown(1); zk2.setData(path, new byte[2], stat1.getVersion()); qu.start(1); watcher.waitForConnected(TIMEOUT); watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged); }