예제 #1
0
        public async Task testExistsSyncWObj()
        {
            SimpleWatcher w1 = new SimpleWatcher();
            SimpleWatcher w2 = new SimpleWatcher();
            SimpleWatcher w3 = new SimpleWatcher();
            SimpleWatcher w4 = new SimpleWatcher();

            IList <Watcher.Event.EventType> e2 = new List <Watcher.Event.EventType>();

            Assert.assertNull(await lsnr.existsAsync("/foo", true));
            Assert.assertNull(await lsnr.existsAsync("/foo", w1));

            Assert.assertNull(await lsnr.existsAsync("/foo/bar", w2));
            Assert.assertNull(await lsnr.existsAsync("/foo/bar", w3));
            Assert.assertNull(await lsnr.existsAsync("/foo/bar", w3));
            Assert.assertNull(await lsnr.existsAsync("/foo/bar", w4));

            await client.createAsync("/foo", "parent".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            expected.Add(Watcher.Event.EventType.NodeCreated);
            await client.createAsync("/foo/bar", "child".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            e2.Add(Watcher.Event.EventType.NodeCreated);

            lsnr_dwatch.verify(expected);
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();

            // default not registered
            Assert.assertNotNull(await lsnr.existsAsync("/foo", w1));

            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w2));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w3));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w4));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w4));

            await client.setDataAsync("/foo", "parent".UTF8getBytes(), -1);

            expected.Add(Watcher.Event.EventType.NodeDataChanged);
            await client.setDataAsync("/foo/bar", "child".UTF8getBytes(), -1);

            e2.Add(Watcher.Event.EventType.NodeDataChanged);

            lsnr_dwatch.verify(new List <Watcher.Event.EventType>());            // not reg so should = 0
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();

            Assert.assertNotNull(await lsnr.existsAsync("/foo", true));
            Assert.assertNotNull(await lsnr.existsAsync("/foo", w1));
            Assert.assertNotNull(await lsnr.existsAsync("/foo", w1));

            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w2));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w2));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w3));
            Assert.assertNotNull(await lsnr.existsAsync("/foo/bar", w4));

            await client.deleteAsync("/foo/bar", -1);

            expected.Add(Watcher.Event.EventType.NodeDeleted);
            await client.deleteAsync("/foo", -1);

            e2.Add(Watcher.Event.EventType.NodeDeleted);

            lsnr_dwatch.verify(expected);
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();
        }
예제 #2
0
        public async Task testGetChildrenSyncWObj()
        {
            SimpleWatcher w1 = new SimpleWatcher();
            SimpleWatcher w2 = new SimpleWatcher();
            SimpleWatcher w3 = new SimpleWatcher();
            SimpleWatcher w4 = new SimpleWatcher();

            IList <Watcher.Event.EventType> e2 = new List <Watcher.Event.EventType>();

            try
            {
                await lsnr.getChildrenAsync("/foo", true);

                Assert.fail();
            }
            catch (KeeperException e)
            {
                Assert.assertEquals(KeeperException.Code.NONODE, e.getCode());
                Assert.assertEquals("/foo", e.getPath());
            }
            try
            {
                await lsnr.getChildrenAsync("/foo/bar", true);

                Assert.fail();
            }
            catch (KeeperException e)
            {
                Assert.assertEquals(KeeperException.Code.NONODE, e.getCode());
                Assert.assertEquals("/foo/bar", e.getPath());
            }

            await client.createAsync("/foo", "parent".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo", true)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo", w1)).Children);

            await client.createAsync("/foo/bar", "child".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            expected.Add(Watcher.Event.EventType.NodeChildrenChanged);             // /foo
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w2)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w2)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w3)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w4)).Children);


            await client.setDataAsync("/foo", "parent".UTF8getBytes(), -1);

            await client.setDataAsync("/foo/bar", "child".UTF8getBytes(), -1);


            Assert.assertNotNull(await lsnr.existsAsync("/foo", true));
            Assert.assertNotNull(await lsnr.existsAsync("/foo", w1));
            Assert.assertNotNull(await lsnr.existsAsync("/foo", true));
            Assert.assertNotNull(await lsnr.existsAsync("/foo", w1));

            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo", true)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo", w1)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w2)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w3)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w4)).Children);
            Assert.assertNotNull((await lsnr.getChildrenAsync("/foo/bar", w4)).Children);

            await client.deleteAsync("/foo/bar", -1);

            e2.Add(Watcher.Event.EventType.NodeDeleted);               // /foo/bar childwatch
            expected.Add(Watcher.Event.EventType.NodeChildrenChanged); // /foo
            await client.deleteAsync("/foo", -1);

            expected.Add(Watcher.Event.EventType.NodeDeleted);

            lsnr_dwatch.verify(expected);
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();
        }
예제 #3
0
 public WatcherFuncTest()
 {
     client_dwatch = new SimpleWatcher();
     lsnr_dwatch   = new SimpleWatcher();
     expected      = new List <Watcher.Event.EventType>();
 }
예제 #4
0
        public void testGetDataSyncWObj()
        {
            SimpleWatcher w1 = new SimpleWatcher(null);
            SimpleWatcher w2 = new SimpleWatcher(null);
            SimpleWatcher w3 = new SimpleWatcher(null);
            SimpleWatcher w4 = new SimpleWatcher(null);

            IList <Watcher.Event.EventType> e2 = new List <Watcher.Event.EventType>();

            try
            {
                lsnr.getData("/foo", w1, null);
                Assert.fail();
            }
            catch (KeeperException e)
            {
                Assert.assertEquals(KeeperException.Code.NONODE, e.getCode());
                Assert.assertEquals("/foo", e.getPath());
            }
            try
            {
                lsnr.getData("/foo/bar", w2, null);
                Assert.fail();
            }
            catch (KeeperException e)
            {
                Assert.assertEquals(KeeperException.Code.NONODE, e.getCode());
                Assert.assertEquals("/foo/bar", e.getPath());
            }

            client.create("/foo", "parent".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            Assert.assertNotNull(lsnr.getData("/foo", true, null));
            Assert.assertNotNull(lsnr.getData("/foo", w1, null));
            client.create("/foo/bar", "child".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));

            client.setData("/foo", "parent".getBytes(), -1);
            expected.Add(Watcher.Event.EventType.NodeDataChanged);
            client.setData("/foo/bar", "child".getBytes(), -1);
            e2.Add(Watcher.Event.EventType.NodeDataChanged);

            lsnr_dwatch.verify(expected);
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();

            Assert.assertNotNull(lsnr.getData("/foo", true, null));
            Assert.assertNotNull(lsnr.getData("/foo", w1, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w2, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w3, null));
            Assert.assertNotNull(lsnr.getData("/foo/bar", w4, null));

            client.delete("/foo/bar", -1);
            expected.Add(Watcher.Event.EventType.NodeDeleted);
            client.delete("/foo", -1);
            e2.Add(Watcher.Event.EventType.NodeDeleted);

            lsnr_dwatch.verify(expected);
            w1.verify(expected);
            w2.verify(e2);
            w3.verify(e2);
            w4.verify(e2);
            expected.Clear();
            e2.Clear();
        }