Пример #1
0
        public async Task testChrootSynchronous()
        {
            ZooKeeper zk1 = await createClient();

            await zk1.createAsync("/ch1", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            await zk1.closeAsync();

            ZooKeeper zk2 = await createClient("/ch1");

            Assert.assertEquals("/ch2", await zk2.createAsync("/ch2", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));

            await zk2.closeAsync();

            zk1 = await createClient();

            zk2 = await createClient("/ch1");

            // check get
            MyWatcher w1 = new MyWatcher("/ch1");

            Assert.assertNotNull(await zk1.existsAsync("/ch1", w1));
            MyWatcher w2 = new MyWatcher("/ch1/ch2");

            Assert.assertNotNull(await zk1.existsAsync("/ch1/ch2", w2));

            MyWatcher w3 = new MyWatcher("/ch2");

            Assert.assertNotNull(await zk2.existsAsync("/ch2", w3));

            // set watches on child
            MyWatcher w4 = new MyWatcher("/ch1");
            await zk1.getChildrenAsync("/ch1", w4);

            MyWatcher w5 = new MyWatcher("/");
            await zk2.getChildrenAsync("/", w5);

            // check set
            await zk1.setDataAsync("/ch1", "1".UTF8getBytes(), -1);

            await zk2.setDataAsync("/ch2", "2".UTF8getBytes(), -1);

            // check watches
            Assert.assertTrue(await w1.matches());
            Assert.assertTrue(await w2.matches());
            Assert.assertTrue(await w3.matches());

            // check exceptions
            try
            {
                await zk2.setDataAsync("/ch3", "3".UTF8getBytes(), -1);
            }
            catch (KeeperException.NoNodeException e)
            {
                Assert.assertEquals("/ch3", e.getPath());
            }

            Assert.assertEquals("1".UTF8getBytes(), (await zk1.getDataAsync("/ch1", false)).Data);
            Assert.assertEquals("2".UTF8getBytes(), (await zk1.getDataAsync("/ch1/ch2", false)).Data);
            Assert.assertEquals("2".UTF8getBytes(), (await zk2.getDataAsync("/ch2", false)).Data);

            // check delete
            await zk2.deleteAsync("/ch2", -1);

            Assert.assertTrue(await w4.matches());
            Assert.assertTrue(await w5.matches());

            await zk1.deleteAsync("/ch1", -1);

            Assert.assertNull(await zk1.existsAsync("/ch1", false));
            Assert.assertNull(await zk1.existsAsync("/ch1/ch2", false));
            Assert.assertNull(await zk2.existsAsync("/ch2", false));
        }
Пример #2
0
        public void testChrootSynchronous()
        {
            ZooKeeper zk1 = createClient();

            try
            {
                zk1.create("/ch1", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            }
            finally
            {
                if (zk1 != null)
                {
                    zk1.close();
                }
            }
            ZooKeeper zk2 = createClient("/ch1");

            try
            {
                Assert.assertEquals("/ch2", zk2.create("/ch2", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
            }
            finally
            {
                if (zk2 != null)
                {
                    zk2.close();
                }
            }

            zk1 = createClient();
            zk2 = createClient("/ch1");
            try
            {
                // check get
                MyWatcher w1 = new MyWatcher("/ch1");
                Assert.assertNotNull(zk1.exists("/ch1", w1));
                MyWatcher w2 = new MyWatcher("/ch1/ch2");
                Assert.assertNotNull(zk1.exists("/ch1/ch2", w2));

                MyWatcher w3 = new MyWatcher("/ch2");
                Assert.assertNotNull(zk2.exists("/ch2", w3));

                // set watches on child
                MyWatcher w4 = new MyWatcher("/ch1");
                zk1.getChildren("/ch1", w4);
                MyWatcher w5 = new MyWatcher("/");
                zk2.getChildren("/", w5);

                // check set
                zk1.setData("/ch1", "1".getBytes(), -1);
                zk2.setData("/ch2", "2".getBytes(), -1);

                // check watches
                Assert.assertTrue(w1.matches());
                Assert.assertTrue(w2.matches());
                Assert.assertTrue(w3.matches());

                // check exceptions
                try
                {
                    zk2.setData("/ch3", "3".getBytes(), -1);
                }
                catch (KeeperException.NoNodeException e)
                {
                    Assert.assertEquals("/ch3", e.getPath());
                }

                Assert.assertEquals("1".getBytes(), zk1.getData("/ch1", false, null));
                Assert.assertEquals("2".getBytes(), zk1.getData("/ch1/ch2", false, null));
                Assert.assertEquals("2".getBytes(), zk2.getData("/ch2", false, null));

                // check delete
                zk2.delete("/ch2", -1);
                Assert.assertTrue(w4.matches());
                Assert.assertTrue(w5.matches());

                zk1.delete("/ch1", -1);
                Assert.assertNull(zk1.exists("/ch1", false));
                Assert.assertNull(zk1.exists("/ch1/ch2", false));
                Assert.assertNull(zk2.exists("/ch2", false));
            }
            finally
            {
                if (zk1 != null)
                {
                    zk1.close();
                }
                if (zk2 != null)
                {
                    zk2.close();
                }
            }
        }