Process() 공개 메소드

Processes ZooKeeper event
Requires installed watcher
public Process ( ZooKeeperNet.WatchedEvent e ) : void
e ZooKeeperNet.WatchedEvent /// The event data. ///
리턴 void
예제 #1
0
        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);
        }
예제 #2
0
        public void WhenSessionIsExpiredListenerRecreatesEphemeralNodes()
        {
            {
                var producerConfig = new ProducerConfig(clientConfig);
                IDictionary<string, SortedSet<Partition>> mappings;
                IDictionary<int, Broker> brokers;
                IDictionary<string, SortedSet<Partition>> mappings2;
                IDictionary<int, Broker> brokers2;
                using (IZooKeeperClient client = new ZooKeeperClient(
                    producerConfig.ZkConnect,
                    producerConfig.ZkSessionTimeoutMs,
                    ZooKeeperStringSerializer.Serializer))
                {
                    using (var brokerPartitionInfo = new ZKBrokerPartitionInfo(client))
                    {
                        brokers = brokerPartitionInfo.GetAllBrokerInfo();
                        mappings =
                            ReflectionHelper.GetInstanceField<IDictionary<string, SortedSet<Partition>>>(
                                "topicBrokerPartitions", brokerPartitionInfo);
                        Assert.NotNull(brokers);
                        Assert.Greater(brokers.Count, 0);
                        Assert.NotNull(mappings);
                        Assert.Greater(mappings.Count, 0);
                        client.Process(new WatchedEvent(KeeperState.Expired, EventType.None, null));
                        WaitUntillIdle(client, 3000);
                        brokers2 = brokerPartitionInfo.GetAllBrokerInfo();
                        mappings2 =
                            ReflectionHelper.GetInstanceField<IDictionary<string, SortedSet<Partition>>>(
                                "topicBrokerPartitions", brokerPartitionInfo);
                    }
                }

                Assert.NotNull(brokers2);
                Assert.Greater(brokers2.Count, 0);
                Assert.NotNull(mappings2);
                Assert.Greater(mappings2.Count, 0);
                Assert.AreEqual(brokers.Count, brokers2.Count);
                Assert.AreEqual(mappings.Count, mappings2.Count);
            }
        }
예제 #3
0
        public void WhenSessionExpiredClientReconnects()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            IZooKeeperConnection conn1;
            IZooKeeperConnection conn2;
            using (IZooKeeperClient client = new ZooKeeperClient(
                prodConfig.ZooKeeper.ZkConnect,
                prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                conn1 = ReflectionHelper.GetInstanceField<ZooKeeperConnection>("connection", client);
                client.Process(new WatchedEvent(KeeperState.Expired, EventType.None, null));
                WaitUntillIdle(client, 1000);
                conn2 = ReflectionHelper.GetInstanceField<ZooKeeperConnection>("connection", client);
            }

            Assert.AreNotEqual(conn1, conn2);
        }
예제 #4
0
        public void WhenStateChangedToDisconnectedStateListenerFires()
        {
            var producerConfig = new ProducerConfig(clientConfig);
            using (IZooKeeperClient client = new ZooKeeperClient(producerConfig.ZkConnect, producerConfig.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer))
            {
                client.Subscribe(this);
                client.Connect();
                WaitUntillIdle(client, 500);
                client.Process(new WatchedEvent(KeeperState.Disconnected, EventType.None, null));
                WaitUntillIdle(client, 500);
            }

            Assert.AreEqual(2, this.events.Count);
            ZooKeeperEventArgs e = this.events[1];
            Assert.AreEqual(ZooKeeperEventTypes.StateChanged, e.Type);
            Assert.IsInstanceOf<ZooKeeperStateChangedEventArgs>(e);
            Assert.AreEqual(((ZooKeeperStateChangedEventArgs)e).State, KeeperState.Disconnected);
        }