示例#1
0
        public async Task TestGetContentWaitTillCreated()
        {
            LOG.Info("--- testGetContentWaitTillCreated");
            Holder <string> contentHolder = new Holder <string>();

            Task task = new Task(() =>
            {
                ContentWatcher <string> watcher = new ContentWatcher <string>(_zkClient, FILE_NAME);
                try
                {
                    watcher.Start();
                    contentHolder.value = watcher.GetContent();
                    watcher.Stop();
                }
                catch (Exception)
                {
                }
            });

            task.Start();

            // create content after 200ms
            await Task.Delay(200);

            await _zkClient.CreatePersistentAsync(FILE_NAME, "aaa");

            // we give the thread some time to pick up the change
            await Task.Delay(1000);

            Assert.True("aaa" == contentHolder.value);
        }
        public void TestGetContent()
        {
            LOG.Info("--- testGetContent");
            ContentWatcher <string> watcher = new ContentWatcher <string>(_zkClient, FILE_NAME);

            watcher.Start();
            _zkClient.CreatePersistent(FILE_NAME, "a");
            Assert.True("a" == watcher.GetContent());

            // update the content
            _zkClient.WriteData(FILE_NAME, "b");

            string contentFromWatcher = TestUtil.WaitUntil("b", () => { return(watcher.GetContent()); }, new TimeSpan(0, 0, 0, 5));

            Assert.True("b" == contentFromWatcher);
            watcher.Stop();
        }
        public void TestHandlingNullContent()
        {
            LOG.Info("--- testHandlingNullContent");
            ContentWatcher <string> watcher = new ContentWatcher <string>(_zkClient, FILE_NAME);

            watcher.Start();
            _zkClient.CreatePersistent(FILE_NAME, null);
            Assert.True(string.IsNullOrEmpty(watcher.GetContent()));
            watcher.Stop();
        }
示例#4
0
        public async Task TestGetContent()
        {
            LOG.Info("--- testGetContent");
            ContentWatcher <string> watcher = new ContentWatcher <string>(_zkClient, FILE_NAME);

            watcher.Start();
            await _zkClient.CreatePersistentAsync(FILE_NAME, "a");

            Assert.True("a" == watcher.GetContent());

            // update the content
            await _zkClient.SetDataAsync(FILE_NAME, "b");

            string contentFromWatcher = TestUtil.WaitUntil(
                "b",
                () => { return(watcher.GetContent()); },
                TimeSpan.FromSeconds(5));

            Assert.True("b" == contentFromWatcher);
            watcher.Stop();
        }