public void WhenChildIsCreatedChilListenerOnParentFires() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; string myPath = "/" + Guid.NewGuid(); using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { client.Connect(); WaitUntillIdle(client, 500); client.Subscribe("/", this as IZooKeeperChildListener); client.CreatePersistent(myPath, true); WaitUntillIdle(client, 500); client.UnsubscribeAll(); client.Delete(myPath); } 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.IsTrue(((ZooKeeperChildChangedEventArgs)e).Children.Contains(myPath.Replace("/", string.Empty))); }
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)); } }
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); }
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 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); }