private byte[] getKey(ZooKeeperServer zks) { ZKDatabase db = zks.getZKDatabase(); if (db != null) { try { Stat stat = new Stat(); return db.getData("/key", stat, null); } catch (NoNodeException e) { LOG.error("getData failed", e); } } return null; }
private void utestGet(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++) { Stat stat = new Stat(); zk.getData("/" + i, true, stat); } zk.close(); }
public Stat statNode(String path, Watcher watcher) throws KeeperException.NoNodeException { Stat stat = new Stat(); DataNode n = nodes.get(path); if (watcher != null) { dataWatches.addWatch(path, watcher); } if (n == null) { throw new KeeperException.NoNodeException(); } synchronized (n) { n.copyStat(stat); return stat; } }
public void deserialize(InputArchive a_, String tag) throws java.io.IOException { a_.startRecord(tag); stat= new org.apache.zookeeper.data.Stat(); a_.readRecord(stat,"stat"); a_.endRecord(tag); } public String toString() {
public void deserialize(InputArchive a_, String tag) throws java.io.IOException { a_.startRecord(tag); stat= new org.apache.zookeeper.data.Stat(); a_.readRecord(stat,"stat"); a_.endRecord(tag); } public String toString() {
private Stat create2EmptyNode(TestableZooKeeper zkClient, String path) throws Exception { Stat stat = new Stat(); zkClient.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, stat); return stat; }
public void deserialize(InputArchive a_, String tag) throws java.io.IOException { a_.startRecord(tag); stat= new org.apache.zookeeper.data.Stat(); a_.readRecord(stat,"stat"); a_.endRecord(tag); } public String toString() {
public void deserialize(InputArchive a_, String tag) throws java.io.IOException { a_.startRecord(tag); path=a_.readString("path"); stat= new org.apache.zookeeper.data.Stat(); a_.readRecord(stat,"stat"); a_.endRecord(tag); } public String toString() {
public void deserialize(InputArchive a_, String tag) throws java.io.IOException { a_.startRecord(tag); data=a_.readBuffer("data"); stat= new org.apache.zookeeper.data.Stat(); a_.readRecord(stat,"stat"); a_.endRecord(tag); } public String toString() {
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(expected = KeeperException.UnimplementedException.class) public void testDisabled() throws KeeperException, InterruptedException { // note, setUp() enables this test based on the test name zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, new Stat(), 100); }
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; }
@Test public void testSetAndGetACL() throws Exception { create2EmptyNode(zkClient, PARENT_PATH); Assert.assertEquals( String.format("%s Node has open ACL", serverState), Ids.OPEN_ACL_UNSAFE, zkClient.getACL(PARENT_PATH, new Stat())); zkClient.setACL(PARENT_PATH, Ids.READ_ACL_UNSAFE, -1); Assert.assertEquals( String.format("%s Node has world read-only ACL", serverState), Ids.READ_ACL_UNSAFE, zkClient.getACL(PARENT_PATH, new Stat())); }
private boolean reconfigPort() throws KeeperException, InterruptedException { List<String> joiningServers = new ArrayList<String>(); int leaderId = 1; while (qu.getPeer(leaderId).peer.leader == null) leaderId++; int followerId = leaderId == 1 ? 2 : 1; joiningServers.add("server." + followerId + "=localhost:" + qu.getPeer(followerId).peer.getQuorumAddress().getPort() /*quorum port*/ + ":" + qu.getPeer(followerId).peer.getElectionAddress().getPort() /*election port*/ + ":participant;localhost:" + PortAssignment.unique()/* new client port */); zkAdmin.reconfigure(joiningServers, null, null, -1, new Stat()); return true; } }
private boolean reconfigPort() throws KeeperException, InterruptedException { List<String> joiningServers = new ArrayList<String>(); int leaderId = 1; while (qu.getPeer(leaderId).peer.leader == null) leaderId++; int followerId = leaderId == 1 ? 2 : 1; joiningServers.add("server." + followerId + "=localhost:" + qu.getPeer(followerId).peer.getQuorumAddress().getPort() /*quorum port*/ + ":" + qu.getPeer(followerId).peer.getElectionAddress().getPort() /*election port*/ + ":participant;localhost:" + PortAssignment.unique()/* new client port */); zkAdmin.reconfigure(joiningServers, null, null, -1, new Stat()); return true; } }
@Test public void testCreate() throws KeeperException, InterruptedException { Stat stat = new Stat(); zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100); Assert.assertEquals(0, stat.getEphemeralOwner()); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false)); }
@Test public void testCreate() throws KeeperException, InterruptedException { Stat stat = new Stat(); zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100); Assert.assertEquals(0, stat.getEphemeralOwner()); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false)); }
@Test public void testCreateSequential() throws KeeperException, InterruptedException { Stat stat = new Stat(); String path = zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, stat, 100); Assert.assertEquals(0, stat.getEphemeralOwner()); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists(path, false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists(path, false)); }
public void testRoundTrip() throws IOException { MultiResponse response = new MultiResponse(); response.add(new OpResult.CheckResult()); response.add(new OpResult.CreateResult("foo-bar")); response.add(new OpResult.DeleteResult()); Stat s = new Stat(); s.setCzxid(546); response.add(new OpResult.SetDataResult(s)); MultiResponse decodedResponse = codeDecode(response); Assert.assertEquals(response, decodedResponse); Assert.assertEquals(response.hashCode(), decodedResponse.hashCode()); }