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; } });
@Override public void execute(byte[] data) throws Exception { zk.create("/create_test", data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); } });
private static void createZNode(ZooKeeper zk, String path, String data) throws KeeperException, InterruptedException { try{ zk.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { } }
private void verifyCreateFails(String path, ZooKeeper zk) throws Exception { try { zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (IllegalArgumentException e) { // this is good return; } Assert.fail("bad path \"" + path + "\" not caught"); }
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)); }
@Test public void testAuth() throws Exception { ZooKeeper zk = createClient(); try { zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); Thread.sleep(1000); } finally { zk.close(); } }
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; }
public void verifyCreateFailure_NoNode() { rc = Code.NONODE; name = null; path = path + "/bar"; zk.create(path, data, acl, flags, this, toString()); verify(); }
public void verifyCreateFailure_NoNode() { rc = Code.NONODE; name = null; stat = null; path = path + "/bar"; zk.create(path, data, acl, flags, this, toString()); verify(); }
@Test public void testSetReqs() throws Exception { final String path = "/set_test"; zk.create(path, new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); testRequests(new ClientOp() { @Override public void execute(byte[] data) throws Exception { zk.setData(path, data, -1); } }); }
@Test public void testAuthFail() { try (ZooKeeper zk = createClient()) { zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); Assert.fail("Should have gotten exception."); } catch (Exception e) { // ok, exception as expected. LOG.info("Got exception as expected: " + e); } }
@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)); }
@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); }
public void verifyCreateFailure_NoChildForEphemeral() { new StringCB(zk).verifyCreateEphemeral(); rc = Code.NOCHILDRENFOREPHEMERALS; name = null; stat = null; path = path + "/bar"; zk.create(path, data, acl, flags, this, toString()); verify(); }
public void verifyCreateFailure_NodeExists() { new Create2CB(zk).verifyCreate(); rc = Code.NODEEXISTS; name = null; stat = null; zk.create(path, data, acl, flags, this, toString()); verify(); }
@Test public void testStartup() throws Exception { final String path = "/test_node"; zk.create(path, new byte[TEST_MAXBUFFER - 60], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.setData(path, new byte[TEST_MAXBUFFER - 50], -1); stopServer(); startServer(); }
public void verifyCreateFailure_NodeExists() { new StringCB(zk).verifyCreate(); rc = Code.NODEEXISTS; name = null; zk.create(path, data, acl, flags, this, toString()); verify(); }
public void verifyCreateFailure_NoChildForEphemeral() { new StringCB(zk).verifyCreateEphemeral(); rc = Code.NOCHILDRENFOREPHEMERALS; name = null; path = path + "/bar"; zk.create(path, data, acl, flags, this, toString()); verify(); }
@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); }