Abstracts connection with ZooKeeper server
Наследование: IZooKeeperConnection
Пример #1
0
        public void ZooKeeperConnectionCreatesAndDeletesPath()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperConnection connection = new ZooKeeperConnection(prodConfig.ZooKeeper.ZkConnect))
            {
                connection.Connect(null);
                string pathName = "/" + Guid.NewGuid();
                connection.Create(pathName, null, CreateMode.Persistent);
                Assert.IsTrue(connection.Exists(pathName, false));
                connection.Delete(pathName);
                Assert.IsFalse(connection.Exists(pathName, false));
            }
        }
Пример #2
0
        public void ZooKeeperConnectionConnectsAndDisposes()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            IZooKeeperConnection connection;
            using (connection = new ZooKeeperConnection(prodConfig.ZooKeeper.ZkConnect))
            {
                Assert.IsNull(connection.ClientState);
                connection.Connect(null);
                Assert.NotNull(connection.Client);
                Assert.AreEqual(ZooKeeper.States.CONNECTING, connection.ClientState);
            }

            Assert.Null(connection.Client);
        }
Пример #3
0
        public void ZooKeeperConnectionCreatesAndGetsChildren()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperConnection connection = new ZooKeeperConnection(prodConfig.ZooKeeper.ZkConnect))
            {
                connection.Connect(null);
                string child = Guid.NewGuid().ToString();
                string pathName = "/" + child;
                connection.Create(pathName, null, CreateMode.Persistent);
                IList<string> children = connection.GetChildren("/", false);
                Assert.Greater(children.Count, 0);
                Assert.IsTrue(children.Contains(child));
                connection.Delete(pathName);
            }
        }
Пример #4
0
        public void ZooKeeperConnectionCreatesAndGetsCreateTime()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperConnection connection = new ZooKeeperConnection(prodConfig.ZooKeeper.ZkConnect))
            {
                connection.Connect(null);
                string pathName = "/" + Guid.NewGuid();
                connection.Create(pathName, null, CreateMode.Persistent);
                long createTime = connection.GetCreateTime(pathName);
                Assert.Greater(createTime, 0);
                connection.Delete(pathName);
            }
        }
Пример #5
0
        public void ZooKeeperConnectionWritesAndReadsData()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperConnection connection = new ZooKeeperConnection(prodConfig.ZooKeeper.ZkConnect))
            {
                connection.Connect(null);
                string child = Guid.NewGuid().ToString();
                string pathName = "/" + child;
                connection.Create(pathName, null, CreateMode.Persistent);
                var sourceData = new byte[] { 1, 2 };
                connection.WriteData(pathName, sourceData);
                byte[] resultData = connection.ReadData(pathName, null, false);
                Assert.IsNotNull(resultData);
                Assert.AreEqual(sourceData[0], resultData[0]);
                Assert.AreEqual(sourceData[1], resultData[1]);
                connection.Delete(pathName);
            }
        }