public async void Sync(string path)
 {
     try
     {
         _logger.LogInformation("同步成功");
         await _zookeeper.sync(path);
     }
     catch (Exception ep)
     {
         _logger.LogError("同步失败。", ep);
     }
 }
Ejemplo n.º 2
0
        public async Task testSync()
        {
            LOG.info("Starting ZK:" + DateTime.Now);

            ZooKeeper zk = await createClient();

            LOG.info("Beginning test:" + DateTime.Now);
            for (var i = 0; i < 100; i++)
            {
                await zk.createAsync("/test" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            }
            await zk.sync("/test");

            for (var i = 0; i < 100; i++)
            {
                await zk.deleteAsync("/test" + i, 0);
            }
            for (var i = 0; i < 100; i++)
            {
                await zk.getChildrenAsync("/", false);
            }
            for (var i = 0; i < 100; i++)
            {
                await zk.getChildrenAsync("/", false);
            }
            LOG.info("Submitted all operations:" + DateTime.Now);
        }
        public Task <DataResult> GetDataAsync(string path, Watcher watcher, bool isSync)
        {
            ReConn();
            if (_zookeeper.existsAsync(path).Result == null)
            {
                _logger.LogDebug("path不存在");
                return(null);
            }
            if (isSync)
            {
                _logger.LogDebug("即将进行同步。");
                var task = Task.Run(async() => {
                    await _zookeeper.sync(path);
                });
                task.Wait();
            }


            return(_zookeeper.getDataAsync(path, watcher));
        }
Ejemplo n.º 4
0
        public void testSync()
        {
            try
            {
                LOG.info("Starting ZK:" + (DateTime.Now));
                countFinished = new ManualResetEventSlim(false);
                opsCount      = limit;
                ZooKeeper zk = createClient();

                LOG.info("Beginning test:" + (DateTime.Now));
                for (int i = 0; i < 100; i++)
                {
                    zk.createAsync("/test" + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT).
                    ContinueWith(processResult);
                }
                zk.sync("/test").ContinueWith(processResult);
                for (int i = 0; i < 100; i++)
                {
                    zk.deleteAsync("/test" + i, 0).ContinueWith(processResult);
                }
                for (int i = 0; i < 100; i++)
                {
                    zk.getChildrenAsync("/", new NullWatcher()).ContinueWith(processResult);
                }
                for (int i = 0; i < 100; i++)
                {
                    zk.getChildrenAsync("/", new NullWatcher()).ContinueWith(processResult);
                }
                LOG.info("Submitted all operations:" + (DateTime.Now));

                if (!countFinished.Wait(10000))
                {
                    Thread.MemoryBarrier();
                    Assert.fail("Haven't received all confirmations" + opsCount);
                }

                for (int i = 0; i < limit; i++)
                {
                    lock (results) {
                        Assert.assertEquals(0, results[i]);
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 5
0
 public Task Sync([NotNull] string path)
 {
     ValidateState();
     return(_zk.sync(path));
 }