public void WhenBrokerIsRemovedBrokerTopicsListenerUpdatesBrokersList() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; IDictionary<string, SortedSet<Partition>> mappings; IDictionary<int, Broker> brokers; string brokerPath = ZooKeeperClient.DefaultBrokerIdsPath + "/" + 2345; using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.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); using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { client.Connect(); WaitUntillIdle(client, 500); var brokerTopicsListener = new BrokerTopicsListener(client, mappings, brokers, null); client.Subscribe(ZooKeeperClient.DefaultBrokerIdsPath, brokerTopicsListener); client.CreatePersistent(brokerPath, true); client.WriteData(brokerPath, "192.168.1.39-1310449279123:192.168.1.39:9102"); WaitUntillIdle(client, 500); Assert.IsTrue(brokers.ContainsKey(2345)); client.DeleteRecursive(brokerPath); WaitUntillIdle(client, 500); Assert.IsFalse(brokers.ContainsKey(2345)); } }
public void WhenBrokerIsRemovedZKBrokerPartitionInfoUpdatesBrokersList() { var producerConfig = new ProducerConfig(clientConfig); IDictionary<int, Broker> brokers; string brokerPath = ZooKeeperClient.DefaultBrokerIdsPath + "/" + 2345; using (IZooKeeperClient client = new ZooKeeperClient( producerConfig.ZkConnect, producerConfig.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { using (var brokerPartitionInfo = new ZKBrokerPartitionInfo(client)) { brokers = brokerPartitionInfo.GetAllBrokerInfo(); client.CreatePersistent(brokerPath, true); client.WriteData(brokerPath, "192.168.1.39-1310449279123:192.168.1.39:9102"); WaitUntillIdle(client, 500); Assert.NotNull(brokers); Assert.Greater(brokers.Count, 0); Assert.IsTrue(brokers.ContainsKey(2345)); client.DeleteRecursive(brokerPath); WaitUntillIdle(client, 500); } } Assert.NotNull(brokers); Assert.Greater(brokers.Count, 0); Assert.IsFalse(brokers.ContainsKey(2345)); }
public void WhenNewTopicIsAddedZKBrokerPartitionInfoUpdatesMappings() { var producerConfig = new ProducerConfig(clientConfig); IDictionary<string, SortedSet<Partition>> mappings; string topicPath = ZooKeeperClient.DefaultBrokerTopicsPath + "/" + CurrentTestTopic; using (IZooKeeperClient client = new ZooKeeperClient( producerConfig.ZkConnect, producerConfig.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { using (var brokerPartitionInfo = new ZKBrokerPartitionInfo(client)) { mappings = ReflectionHelper.GetInstanceField<IDictionary<string, SortedSet<Partition>>>( "topicBrokerPartitions", brokerPartitionInfo); client.CreatePersistent(topicPath, true); WaitUntillIdle(client, 500); client.UnsubscribeAll(); client.DeleteRecursive(topicPath); } } Assert.NotNull(mappings); Assert.Greater(mappings.Count, 0); Assert.IsTrue(mappings.ContainsKey(CurrentTestTopic)); }
public void WhenNewBrokerInTopicIsAddedZKBrokerPartitionInfoUpdatesMappings() { var producerConfig = new ProducerConfig(clientConfig); IDictionary<string, SortedSet<Partition>> mappings; IDictionary<int, Broker> brokers; string brokerPath = ZooKeeperClient.DefaultBrokerIdsPath + "/" + 2345; string topicPath = ZooKeeperClient.DefaultBrokerTopicsPath + "/" + CurrentTestTopic; string topicBrokerPath = topicPath + "/" + 2345; 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); client.CreatePersistent(brokerPath, true); client.WriteData(brokerPath, "192.168.1.39-1310449279123:192.168.1.39:9102"); client.CreatePersistent(topicPath, true); WaitUntillIdle(client, 500); Assert.IsTrue(brokers.ContainsKey(2345)); Assert.IsTrue(mappings.ContainsKey(CurrentTestTopic)); client.CreatePersistent(topicBrokerPath, true); client.WriteData(topicBrokerPath, 5); WaitUntillIdle(client, 500); client.UnsubscribeAll(); client.DeleteRecursive(brokerPath); client.DeleteRecursive(topicPath); } } Assert.NotNull(brokers); Assert.Greater(brokers.Count, 0); Assert.NotNull(mappings); Assert.Greater(mappings.Count, 0); Assert.IsTrue(brokers.ContainsKey(2345)); Assert.IsTrue(mappings.Keys.Contains(CurrentTestTopic)); Assert.AreEqual(5, mappings[CurrentTestTopic].Count); }
public void WhenNewTopicIsAddedBrokerTopicsListenerCreatesNewMapping() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; IDictionary<string, SortedSet<Partition>> mappings; IDictionary<int, Broker> brokers; string topicPath = ZooKeeperClient.DefaultBrokerTopicsPath + "/" + CurrentTestTopic; using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.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); using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { client.Connect(); WaitUntillIdle(client, 500); var brokerTopicsListener = new BrokerTopicsListener(client, mappings, brokers, null); client.Subscribe(ZooKeeperClient.DefaultBrokerTopicsPath, brokerTopicsListener); client.CreatePersistent(topicPath, true); WaitUntillIdle(client, 500); client.UnsubscribeAll(); WaitUntillIdle(client, 500); client.DeleteRecursive(topicPath); } Assert.IsTrue(mappings.ContainsKey(CurrentTestTopic)); }
public void WhenNewBrokerIsAddedZkBrokerPartitionInfoUpdatesBrokersList() { var prodConfig = this.ZooKeeperBasedSyncProdConfig; IDictionary<int, Broker> brokers; string brokerPath = ZooKeeperClient.DefaultBrokerIdsPath + "/" + 2345; using (IZooKeeperClient client = new ZooKeeperClient( prodConfig.ZooKeeper.ZkConnect, prodConfig.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer)) { using (var brokerPartitionInfo = new ZKBrokerPartitionInfo(client)) { brokers = brokerPartitionInfo.GetAllBrokerInfo(); client.CreatePersistent(brokerPath, true); client.WriteData(brokerPath, "192.168.1.39-1310449279123:192.168.1.39:9102"); WaitUntillIdle(client, 500); client.UnsubscribeAll(); WaitUntillIdle(client, 500); client.DeleteRecursive(brokerPath); } } Assert.NotNull(brokers); Assert.Greater(brokers.Count, 0); Assert.IsTrue(brokers.ContainsKey(2345)); Assert.AreEqual("192.168.1.39", brokers[2345].Host); Assert.AreEqual(9102, brokers[2345].Port); Assert.AreEqual(2345, brokers[2345].Id); }