Example #1
0
 public void SetUp()
 {
     if (!Ensemble.IsRunning)
     {
         Ensemble.Start();
     }
     ZooKeeperClient.Delete(new ServiceBeaconSettings().ZooKeeperNodesPrefix);
 }
Example #2
0
        public void WhenZNodeIsDeletedChildAndDataDeletedListenersFire()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            string myPath = "/" + Guid.NewGuid();

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                client.CreatePersistent(myPath, true);
                WaitUntillIdle(client, 500);
                client.Subscribe(myPath, this as IZooKeeperChildListener);
                client.Subscribe(myPath, this as IZooKeeperDataListener);
                client.Delete(myPath);
                WaitUntillIdle(client, 500);
            }

            Assert.AreEqual(2, this.events.Count);
            ZooKeeperEventArgs e = this.events[0];

            Assert.AreEqual(ZooKeeperEventTypes.ChildChanged, e.Type);
            Assert.IsInstanceOf <ZooKeeperChildChangedEventArgs>(e);
            Assert.AreEqual(((ZooKeeperChildChangedEventArgs)e).Path, myPath);
            Assert.IsNull(((ZooKeeperChildChangedEventArgs)e).Children);
            e = this.events[1];
            Assert.AreEqual(ZooKeeperEventTypes.DataChanged, e.Type);
            Assert.IsInstanceOf <ZooKeeperDataChangedEventArgs>(e);
            Assert.AreEqual(((ZooKeeperDataChangedEventArgs)e).Path, myPath);
            Assert.IsNull(((ZooKeeperDataChangedEventArgs)e).Data);
        }
Example #3
0
        public void WhenChildIsDeletedChildListenerOnParentFires()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            string myPath = "/" + Guid.NewGuid();

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                client.CreatePersistent(myPath, true);
                WaitUntillIdle(client, 500);
                client.Subscribe("/", this as IZooKeeperChildListener);
                client.Delete(myPath);
                WaitUntillIdle(client, 500);
            }

            Assert.AreEqual(1, this.events.Count);
            ZooKeeperEventArgs e = this.events[0];

            Assert.AreEqual(ZooKeeperEventTypes.ChildChanged, e.Type);
            Assert.IsInstanceOf <ZooKeeperChildChangedEventArgs>(e);
            Assert.AreEqual(((ZooKeeperChildChangedEventArgs)e).Path, "/");
            Assert.Greater(((ZooKeeperChildChangedEventArgs)e).Children.Count, 0);
            Assert.IsFalse(((ZooKeeperChildChangedEventArgs)e).Children.Contains(myPath.Replace("/", string.Empty)));
        }
Example #4
0
 protected override void DoUnregister(ServiceMetadata metadata)
 {
     try
     {
         _zkClient.Delete(metadata.FullPath);
     }
     catch (Exception ex)
     {
         var message = string.Format("Fail to unregister metadata[{0}] to zookeeper, cause : {1}", metadata, ex.Message);
         throw new Exception(message, ex);
     }
 }
Example #5
0
        public void ZooKeeperClientCreatesANewPathAndDeletesIt()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                string myPath = "/" + Guid.NewGuid();
                client.CreatePersistent(myPath, false);
                Assert.IsTrue(client.Exists(myPath));
                client.Delete(myPath);
                Assert.IsFalse(client.Exists(myPath));
            }
        }
Example #6
0
        public void ZooKeeperClientCreatesAChildAndGetsChildren()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                string child  = Guid.NewGuid().ToString();
                string myPath = "/" + child;
                client.CreatePersistent(myPath, false);
                IList <string> children      = client.GetChildren("/", false);
                int            countChildren = client.CountChildren("/");
                Assert.Greater(children.Count, 0);
                Assert.AreEqual(children.Count, countChildren);
                Assert.IsTrue(children.Contains(child));
                client.Delete(myPath);
            }
        }
        public new void SetUp()
        {
            client = GetClient();

            for (var attempt = 0; attempt < 3; attempt++)
            {
                try
                {
                    client.Delete(new DeleteRequest("/watch")
                    {
                        DeleteChildrenIfNeeded = true
                    }).EnsureSuccess();
                    client.Create(new CreateRequest("/watch/a/b/c", CreateMode.Persistent)).EnsureSuccess();
                    client.Create(new CreateRequest("/watch/a/b/d", CreateMode.Persistent)).EnsureSuccess();
                    client.Create(new CreateRequest("/watch/a/e", CreateMode.Persistent)).EnsureSuccess();
                }
                catch (Exception e)
                {
                    Log.Error(e, "Failed to SetUp initial tree.");
                }
            }
        }
Example #8
0
        public void WhenDataChangedDataListenerFires()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            string myPath     = "/" + Guid.NewGuid();
            string sourceData = "my test data";
            string resultData;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                client.CreatePersistent(myPath, true);
                WaitUntillIdle(client, 500);
                client.Subscribe(myPath, this as IZooKeeperDataListener);
                client.Subscribe(myPath, this as IZooKeeperChildListener);
                client.WriteData(myPath, sourceData);
                WaitUntillIdle(client, 500);
                client.UnsubscribeAll();
                resultData = client.ReadData <string>(myPath);
                client.Delete(myPath);
            }

            Assert.IsTrue(!string.IsNullOrEmpty(resultData));
            Assert.AreEqual(sourceData, resultData);
            Assert.AreEqual(1, this.events.Count);
            ZooKeeperEventArgs e = this.events[0];

            Assert.AreEqual(ZooKeeperEventTypes.DataChanged, e.Type);
            Assert.IsInstanceOf <ZooKeeperDataChangedEventArgs>(e);
            Assert.AreEqual(((ZooKeeperDataChangedEventArgs)e).Path, myPath);
            Assert.IsNotNull(((ZooKeeperDataChangedEventArgs)e).Data);
            Assert.AreEqual(((ZooKeeperDataChangedEventArgs)e).Data, sourceData);
        }
Example #9
0
        static void SubscribeChildrenListener(ZooKeeperClient client)
        {
            var rootPath = "/cluster/calc";

            client.CreatePersistent(rootPath, new byte[0]);

            var childrenListener = new DebugChildrenSubscriber(rootPath);

            client.SubscribeChildListener(childrenListener);

            // create child
            for (int i = 11; i <= 15; i++)
            {
                client.CreatePersistent("/cluster/calc/" + i, new byte[0]);
                Thread.Sleep(1000);
            }

            // delete child
            for (int i = 11; i <= 15; i++)
            {
                client.Delete("/cluster/calc/" + i);
                Thread.Sleep(1000);
            }
        }
 public new void SetUp()
 {
     client.Delete(new DeleteRequest("/watch")
     {
         DeleteChildrenIfNeeded = true
     });
     client.Create(new CreateRequest("/watch/a/b/c", CreateMode.Persistent)).EnsureSuccess();
     client.Create(new CreateRequest("/watch/a/b/d", CreateMode.Persistent)).EnsureSuccess();
     client.Create(new CreateRequest("/watch/a/e", CreateMode.Persistent)).EnsureSuccess();
 }
        public void Exists_should_add_watch_triggered_by_Deleted()
        {
            var path    = "/watch/a/e";
            var watcher = new TestWatcher();

            client.Exists(new ExistsRequest(path)
            {
                Watcher = watcher
            }).EnsureSuccess();
            client.Delete(new DeleteRequest(path)).EnsureSuccess();
            watcher.ShouldBeTriggeredBy(NodeChangedEventType.Deleted, path);
        }