HBASE-8509 ZKUtil#createWithParents won't set data during znode creation when parent folder doesn't exit (Jefferey and Ted)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1480623 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-05-09 13:28:34 +00:00
parent 832a6efa17
commit 695535c657
2 changed files with 25 additions and 3 deletions

View File

@ -1231,7 +1231,7 @@ public class ZKUtil {
return;
} catch(KeeperException.NoNodeException nne) {
createWithParents(zkw, getParent(znode));
createWithParents(zkw, znode);
createWithParents(zkw, znode, data);
} catch(InterruptedException ie) {
zkw.interruptedException(ie);
}

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
@ -282,8 +283,29 @@ public class TestZooKeeper {
}
/**
* Create a bunch of znodes in a hierarchy, try deleting one that has childs
* (it will fail), then delete it recursively, then delete the last znode
* Create a znode with data
* @throws Exception
*/
@Test
public void testCreateWithParents() throws Exception {
ZooKeeperWatcher zkw =
new ZooKeeperWatcher(new Configuration(TEST_UTIL.getConfiguration()),
TestZooKeeper.class.getName(), null);
byte[] expectedData = new byte[] { 1, 2, 3 };
ZKUtil.createWithParents(zkw, "/l1/l2/l3/l4/testCreateWithParents", expectedData);
byte[] data = ZKUtil.getData(zkw, "/l1/l2/l3/l4/testCreateWithParents");
assertTrue(Bytes.equals(expectedData, data));
ZKUtil.deleteNodeRecursively(zkw, "/l1");
ZKUtil.createWithParents(zkw, "/testCreateWithParents", expectedData);
data = ZKUtil.getData(zkw, "/testCreateWithParents");
assertTrue(Bytes.equals(expectedData, data));
ZKUtil.deleteNodeRecursively(zkw, "/testCreateWithParents");
}
/**
* Create a bunch of znodes in a hierarchy, try deleting one that has childs (it will fail), then
* delete it recursively, then delete the last znode
* @throws Exception
*/
@Test