/** * Create or update an entry * @param path path * @param data data * @param acl ACL for path -used when creating a new entry * @param overwrite enable overwrite * @throws IOException * @return true if the entry was created, false if it was simply updated. */ public boolean zkSet(String path, CreateMode mode, byte[] data, List<ACL> acl, boolean overwrite) throws IOException { Preconditions.checkArgument(data != null, "null data"); checkServiceLive(); if (!zkPathExists(path)) { zkCreate(path, mode, data, acl); return true; } else { if (overwrite) { zkUpdate(path, data); return false; } else { throw new FileAlreadyExistsException(path); } } }
/** * Create or update an entry. * * @param path path * @param data data * @param acl ACL for path -used when creating a new entry * @param overwrite enable overwrite * @return true if the entry was created, false if it was simply updated. * @throws IOException */ public boolean zkSet(String path, CreateMode mode, byte[] data, List<ACL> acl, boolean overwrite) throws IOException { Preconditions.checkArgument(data != null, "null data"); checkServiceLive(); if (!zkPathExists(path)) { zkCreate(path, mode, data, acl); return true; } else { if (overwrite) { zkUpdate(path, data); return false; } else { throw new FileAlreadyExistsException(path); } } }
@Test(expected = PathNotFoundException.class) public void testUpdateMissing() throws Throwable { curatorService.zkUpdate("/testupdatemissing", getTestBuffer()); }
@Test(expected = PathNotFoundException.class) public void testUpdateMissing() throws Throwable { curatorService.zkUpdate("/testupdatemissing", getTestBuffer()); }
@Test public void testCreateUpdate() throws Throwable { byte[] buffer = getTestBuffer(); curatorService.zkCreate("/testcreateupdate", CreateMode.PERSISTENT, buffer, rootACL ); curatorService.zkUpdate("/testcreateupdate", buffer); }
@Test public void testUpdateDirectory() throws Throwable { mkPath("/testupdatedirectory", CreateMode.PERSISTENT); curatorService.zkUpdate("/testupdatedirectory", getTestBuffer()); }
@Test public void testCreateUpdate() throws Throwable { byte[] buffer = getTestBuffer(); curatorService.zkCreate("/testcreateupdate", CreateMode.PERSISTENT, buffer, rootACL ); curatorService.zkUpdate("/testcreateupdate", buffer); }
@Test public void testUpdateDirectory() throws Throwable { mkPath("/testupdatedirectory", CreateMode.PERSISTENT); curatorService.zkUpdate("/testupdatedirectory", getTestBuffer()); }
@Test public void testUpdateDirectorywithChild() throws Throwable { mkPath("/testupdatedirectorywithchild", CreateMode.PERSISTENT); mkPath("/testupdatedirectorywithchild/child", CreateMode.PERSISTENT); curatorService.zkUpdate("/testupdatedirectorywithchild", getTestBuffer()); }
@Test public void testUpdateDirectorywithChild() throws Throwable { mkPath("/testupdatedirectorywithchild", CreateMode.PERSISTENT); mkPath("/testupdatedirectorywithchild/child", CreateMode.PERSISTENT); curatorService.zkUpdate("/testupdatedirectorywithchild", getTestBuffer()); }