DistributedQueue { public byte[] remove() throws NoSuchElementException, KeeperException, InterruptedException { TreeMap<Long,String> orderedChildren; while(true){ try{ orderedChildren = orderedChildren(null); }catch(KeeperException.NoNodeException e){ throw new NoSuchElementException(); } if(orderedChildren.size() == 0) throw new NoSuchElementException(); for(String headNode : orderedChildren.values()){ String path = dir +"/"+headNode; try{ byte[] data = zookeeper.getData(path, false, null); zookeeper.delete(path, -1); return data; }catch(KeeperException.NoNodeException e){ } } } } DistributedQueue(ZooKeeper zookeeper, String dir, List<ACL> acl); byte[] element(); byte[] remove(); byte[] take(); boolean offer(byte[] data); byte[] peek(); byte[] poll();  }
@Test public void testRemove1() throws Exception{ String dir = "/testRemove1"; String testString = "Hello World"; final int num_clients = 1; ZooKeeper clients[] = new ZooKeeper[num_clients]; DistributedQueue queueHandles[] = new DistributedQueue[num_clients]; for(int i=0; i < clients.length; i++){ clients[i] = createClient(); queueHandles[i] = new DistributedQueue(clients[i], dir, null); } try{ queueHandles[0].remove(); }catch(NoSuchElementException e){ return; } Assert.assertTrue(false); }