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 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))); }
public void WhenStateChangedToExpiredStateAndSessionListenersFire() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { client.Subscribe(this); client.Connect(); WaitUntillIdle(client, 500); client.Process(new WatchedEvent(KeeperState.Expired, EventType.None, null)); WaitUntillIdle(client, 3000); } Assert.AreEqual(4, this.events.Count); ZooKeeperEventArgs e = this.events[1]; Assert.AreEqual(ZooKeeperEventTypes.StateChanged, e.Type); Assert.IsInstanceOf <ZooKeeperStateChangedEventArgs>(e); Assert.AreEqual(((ZooKeeperStateChangedEventArgs)e).State, KeeperState.Expired); e = this.events[2]; Assert.AreEqual(ZooKeeperEventTypes.SessionCreated, e.Type); Assert.IsInstanceOf <ZooKeeperSessionCreatedEventArgs>(e); e = this.events[3]; Assert.AreEqual(ZooKeeperEventTypes.StateChanged, e.Type); Assert.IsInstanceOf <ZooKeeperStateChangedEventArgs>(e); Assert.AreEqual(((ZooKeeperStateChangedEventArgs)e).State, KeeperState.SyncConnected); }
public void WhenStateChangedToConnectedStateListenerFires() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { client.Subscribe(this); client.Connect(); WaitUntillIdle(client, 500); } Assert.AreEqual(1, this.events.Count); ZooKeeperEventArgs e = this.events[0]; Assert.AreEqual(ZooKeeperEventTypes.StateChanged, e.Type); Assert.IsInstanceOf <ZooKeeperStateChangedEventArgs>(e); Assert.AreEqual(((ZooKeeperStateChangedEventArgs)e).State, KeeperState.SyncConnected); }
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); }
/// <summary> /// Enqueues new event from ZooKeeper in events queue /// </summary> /// <param name="e"> /// The event from ZooKeeper. /// </param> private void Enqueue(ZooKeeperEventArgs e) { Logger.Debug("New event queued: " + e); this.eventsQueue.Enqueue(e); }