private ContainerManager newContainerManager(final AtomicLong fakeElapsed) { return new ContainerManager(serverFactory.getZooKeeperServer() .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) { @Override protected long getElapsed(DataNode node) { return fakeElapsed.get(); } }; } }
private ContainerManager newContainerManager(final AtomicLong fakeElapsed) { return new ContainerManager(serverFactory.getZooKeeperServer() .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) { @Override protected long getElapsed(DataNode node) { return fakeElapsed.get(); } }; } }
@Test(timeout = 30000) public void testFalseEmpty() 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); ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() .getZKDatabase(), serverFactory.getZooKeeperServer().firstProcessor, 1, 100) { @Override protected Collection<String> getCandidates() { return Collections.singletonList("/foo"); } }; containerManager.checkContainers(); Thread.sleep(1000); Assert.assertNotNull("Container should have not been deleted", zk.exists("/foo", false)); }
@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(timeout = 30000) public void testCascadingDeletion() 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.CONTAINER); zk.create("/foo/bar/one", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.delete("/foo/bar/one", -1); // should cause "/foo/bar" and "/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); containerManager .checkContainers(); Thread.sleep(1000); Assert.assertNull("Container should have been deleted", zk.exists("/foo/bar", false)); Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); }
@Test(timeout = 30000) public void testSimpleDeletionAsync() throws KeeperException, InterruptedException { final CountDownLatch latch = new CountDownLatch(1); AsyncCallback.Create2Callback cb = new AsyncCallback.Create2Callback() { @Override public void processResult(int rc, String path, Object ctx, String name, Stat stat) { Assert.assertEquals(ctx, "context"); latch.countDown(); } }; zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER, cb, "context"); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); 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 testClientResponseStatsUpdate() throws IOException, InterruptedException, KeeperException { try (ZooKeeper zk = createClient()) { BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats(); assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE)); zk.create("/a", "test".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); assertThat("Last client response size should be greater than 0 after client request was performed", clientResponseStats.getLastBufferSize(), greaterThan(0)); byte[] contents = zk.getData("/a", null, null); assertArrayEquals("unexpected data", "test".getBytes(), contents); } }
@Test public void testClientResponseStatsUpdate() throws IOException, InterruptedException, KeeperException { try (ZooKeeper zk = createClient()) { BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats(); assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE)); zk.create("/a", "test".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); assertThat("Last client response size should be greater then zero after client request was performed", clientResponseStats.getLastBufferSize(), greaterThan(0)); } } }
ZooKeeperServer zks = serverFactory.getZooKeeperServer(); Map<String, Object> result = Commands.runCommand(cmdName, zks, kwargs).toMap();
final ContainerManager containerManager = new ContainerManager(serverFactory.getZooKeeperServer() .getZKDatabase(), processor, 1, 2) { @Override
@Test(timeout = 30000) public void testMultiWithContainerSimple() throws KeeperException, InterruptedException { Op createContainer = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); zk.multi(Collections.singletonList(createContainer)); DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree(); Assert.assertEquals(dataTree.getContainers().size(), 1); }
@Test(timeout = 30000) public void testMultiWithContainer() throws KeeperException, InterruptedException { Op createContainer = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); Op createChild = Op.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.multi(Arrays.asList(createContainer, createChild)); DataTree dataTree = serverFactory.getZooKeeperServer().getZKDatabase().getDataTree(); Assert.assertEquals(dataTree.getContainers().size(), 1); 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)); createContainer = Op.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.CONTAINER); createChild = Op.create("/foo/bar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Op deleteChild = Op.delete("/foo/bar", -1); zk.multi(Arrays.asList(createContainer, createChild, deleteChild)); containerManager.checkContainers(); Thread.sleep(1000); Assert.assertNull("Container should have been deleted", zk.exists("/foo", false)); }
@Test public void testServerSideThrottling() throws IOException, InterruptedException, KeeperException { try (ZooKeeper zk = createClient()) { BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats(); assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE));
.getZooKeeperServer(); FileTxnSnapLog snapLog = zooKeeperServer.getTxnLogFactory(); FileTxnSnapLog fileTxnSnapLogWithError = new FileTxnSnapLog(