Ejemplo n.º 1
0
        public void WhenBrokerIsRemovedZkBrokerPartitionInfoUpdatesBrokersList()
        {
            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))
                {
                    WaitUntillIdle(client, 500);
                    brokers = brokerPartitionInfo.GetAllBrokerInfo();
                    client.CreatePersistent(brokerPath, true);
                    client.WriteData(brokerPath, "172.16.66.2-1310449279123:172.16.66.2:9092");
                    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));
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            string connStr  = "192.168.117.52:2181/test";
            var    zkClient = new ZooKeeperClient(connStr);
            await zkClient.OpenAsync();

            var n1 = await zkClient.ProxyNodeAsync("n1");

            await n1.CreateAsync(Permission.All, ignoreExists : true);

            var book = new Book {
                Name = "yellow", Price = 7.5
            };
            var nbook = await n1.ProxyJsonNodeAsync <Book>("book", true);

            await nbook.CreateAsync(book, Permission.All, ignoreExists : true);

            nbook.DataChanged += (_, e) =>
            {
                var bk = e.Data;
                Console.WriteLine($"book: [name: {bk.Name}, price: {bk.Price}]");
            };

            var props = new Dictionary <string, string>
            {
                { "zkclient", "good" },
                { "zooproxy", "better" }
            };
            var n2 = await zkClient.ProxyPropertyNodeAsync("n2");

            await n2.CreateAsync(props, Permission.All, Mode.Ephemeral, true);

            Console.WriteLine("done!");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        //[zk: localhost(CONNECTED) 12] get /brokers/topics/mvlogs
        //{"version":1,"partitions":{"1":[3,2],"0":[2,3]}}
        public static Dictionary <int, int[]> GetTopicMetadataInzookeeper(ZooKeeperClient zkClient, string topic)
        {
            var treturn = new Dictionary <int, int[]>();

            try
            {
                var data = zkClient.ReadData <string>(string.Format("/brokers/topics/{0}", topic), true);
                var ctx  = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(data);
                var ty   = ctx["partitions"].GetType();
                //Logger.InfoFormat("The type for partitions :{0}", ty.FullName);
                var tpartitons = (Dictionary <string, object>)ctx["partitions"];

                foreach (var kv in tpartitons)
                {
                    var partitionID = Convert.ToInt32(kv.Key);
                    //Logger.InfoFormat("The type for partitions value :{0}", kv.Value.GetType().FullName);
                    var rep = (ArrayList)kv.Value;
                    var partitionReplicas = new int[rep.Count];

                    for (var i = 0; i < rep.Count; i++)
                    {
                        partitionReplicas[i] = Convert.ToInt32(rep[i]);
                    }
                    treturn.Add(partitionID, partitionReplicas);
                }
                Logger.InfoFormat("Get topic data directly from zookeeper Topic:{0} Data:{1} Partition count:{2}",
                                  topic, data, treturn.Count);
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to get topic " + topic + " data directly from zookeeper: " + ex.FormatException());
            }

            return(treturn);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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)));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private async Task <ZooKeeperClient> CreateAndOpenZkClient(TaskCompletionSource <Void> tcs)
        {
            var options  = _options.CurrentValue;
            var zkClient = new ZooKeeperClient(
                options.ConnectionString,
                options.SessionTimeout,
                options.ConnectionTimeout);
            await zkClient.OpenAsync();

            zkClient.FirstConnected += (_, __) =>
            {
                _logger.LogInformation("Connect to zookeeper server successfully.");
            };
            zkClient.ReConnected += (_, __) =>
            {
                _logger.LogInformation("Reconnect to zookeeper server successfully.");
            };
            zkClient.Disconnected += (_, __) =>
            {
                _logger.LogInformation("Lost connection to zookeeper server.");
            };
            zkClient.SessionExpired += (_, __) =>
            {
                tcs.SetException(new UnhealthyException(
                                     "Session of this zookeeper connection is expired.",
                                     new KeeperException.SessionExpiredException()));
            };
            return(zkClient);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void WhenNewTopicIsAddedZkBrokerPartitionInfoUpdatesMappings()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            IDictionary <string, SortedSet <Partition> > mappings;
            string topicPath = ZooKeeperClient.DefaultBrokerTopicsPath + "/" + CurrentTestTopic;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.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();
                    WaitUntillIdle(client, 500);
                    client.DeleteRecursive(topicPath);
                }
            }

            Assert.NotNull(mappings);
            Assert.Greater(mappings.Count, 0);
            Assert.IsTrue(mappings.ContainsKey(CurrentTestTopic));
        }
Ejemplo n.º 10
0
        public void Should_locate_registered_ServiceBeacon_service_with_custom_path_escaper()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            ZooKeeperClient.Create("/service-discovery/v2/ZGVmYXVsdA==", CreateMode.Persistent);

            using (var beacon = new ServiceBeacon(
                       ZooKeeperClient,
                       replica,
                       new ServiceBeaconSettings
            {
                IterationPeriod = 60.Seconds(),
                MinimumTimeBetweenIterations = 100.Milliseconds(),
                ZooKeeperNodesPathEscaper = new CustomPathEscaper()
            },
                       Log))
            {
                beacon.Start();
                WaitNodeExists("/service-discovery/v2/ZGVmYXVsdA==/dm9zdG9r/aHR0cHM6Ly9naXRodWIuY29tL3Zvc3Rvaw==");

                using (var locator = new ServiceLocator(
                           ZooKeeperClient,
                           new ServiceLocatorSettings
                {
                    ZooKeeperNodesPathEscaper = new CustomPathEscaper()
                },
                           Log))
                {
                    ShouldLocateImmediately(locator, replica.Environment, replica.Application, replica.Replica);
                }
            }
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="log"></param>
 /// <param name="connectionString"></param>
 /// <param name="proxy"></param>
 /// <param name="SessionTimeout">默认20(秒)</param>
 /// <param name="addNodeDel"></param>
 /// <param name="deleteNodeDel"></param>
 public ZooKeeperHelper(string connectionString, string proxy, double SessionTimeout = 20, CodisWatcher.AddNodeDel addNodeDel = null, CodisWatcher.DeleteNodeDel deleteNodeDel = null)
 {
     _zk                = new ZooKeeperClient(connectionString, SessionTimeout);
     this.addNodeDel    = addNodeDel;
     this.deleteNodeDel = deleteNodeDel;
     codiswatcher       = new CodisWatcher(_zk, proxy, addNodeDel, deleteNodeDel);
     codiswatcher.ProcessWatched();
 }
        private static async Task VerifyNodeDeleted(ZooKeeperClient client, string path)
        {
            var node = await client.ExistsAsync(path);

            node.EnsureSuccess();

            node.Exists.Should().BeFalse();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DataChangedEventItem"/> class.
        /// </summary>
        /// <param name="logger">
        /// The logger.
        /// </param>
        /// <param name="changedHandler">
        /// The changed handler.
        /// </param>
        /// <param name="deletedHandler">
        /// The deleted handler.
        /// </param>
        /// <remarks>
        /// Should use external logger to keep same format of all event logs
        /// </remarks>
        public DataChangedEventItem(

            ZooKeeperClient.ZooKeeperEventHandler<ZooKeeperDataChangedEventArgs> changedHandler,
            ZooKeeperClient.ZooKeeperEventHandler<ZooKeeperDataChangedEventArgs> deletedHandler)
        {
            this.DataChanged += changedHandler;
            this.DataDeleted += deletedHandler;
        }
 public BrokerPartitionInfo(ISyncProducerPool syncProducerPool, IDictionary <string, TopicMetadata> cache, IDictionary <string, DateTime> lastUpdateTime, int topicMetaDataRefreshIntervalMS, ZooKeeperClient zkClient)
 {
     this.syncProducerPool   = syncProducerPool;
     this.topicPartitionInfo = cache;
     this.topicPartitionInfoLastUpdateTime = lastUpdateTime;
     this.topicMetaDataRefreshIntervalMS   = topicMetaDataRefreshIntervalMS;
     this.zkClient = zkClient;
 }
Ejemplo n.º 15
0
        internal static void Run(ProduceSimpleHelperOption produceOptions)
        {
            failedMessageCount               = 0;
            successMessageCount              = 0;
            sentBatchCount                   = 0;
            produceMessagePerPartition       = new Dictionary <int, int>();
            produceMessagePerPartitionExpect = new Dictionary <int, int>();

            PrepareSentMessages(produceOptions);

            kafkaSimpleManagerConfig = new KafkaSimpleManagerConfiguration()
            {
                Zookeeper        = produceOptions.Zookeeper,
                MaxMessageSize   = SyncProducerConfiguration.DefaultMaxMessageSize,
                PartitionerClass = produceOptions.PartitionerClass
            };
            kafkaSimpleManagerConfig.Verify();
            producerConfigTemplate = new ProducerConfiguration(
                new List <BrokerConfiguration>()
            {
            })                                             //The Brokers will be replaced inside of KafkaSimpleManager
            {
                ForceToPartition        = -1,
                PartitionerClass        = kafkaSimpleManagerConfig.PartitionerClass,
                TotalNumPartitions      = 0,
                RequiredAcks            = produceOptions.RequiredAcks,
                AckTimeout              = produceOptions.AckTimeout,
                SendTimeout             = produceOptions.SendTimeout,
                ReceiveTimeout          = produceOptions.ReceiveTimeout,
                CompressionCodec        = KafkaNetLibraryExample.ConvertToCodec(produceOptions.Compression.ToString()),
                BufferSize              = produceOptions.BufferSize,
                SyncProducerOfOneBroker = produceOptions.SyncProducerOfOneBroker, //Actually it's sync producer socket count of one partition
                MaxMessageSize          = Math.Max(SyncProducerConfiguration.DefaultMaxMessageSize, produceOptions.MessageSize)
            };

            using (ZooKeeperClient zkClient = new ZooKeeperClient(produceOptions.Zookeeper,
                                                                  ZooKeeperConfiguration.DefaultSessionTimeout, ZooKeeperStringSerializer.Serializer))
            {
                zkClient.Connect();
                Dictionary <int, int[]> topicDataInZookeeper = ZkUtils.GetTopicMetadataInzookeeper(zkClient, produceOptions.Topic);

                // -2  by default or customized partitioner class. (you need specify PartitionerClass by -l)
                if (produceOptions.PartitionId == -2)
                {
                    if (string.IsNullOrEmpty(kafkaSimpleManagerConfig.PartitionerClass))
                    {
                        throw new ArgumentException("The partitioer class must not be empty if you want to  send to partition by partitioner.");
                    }
                    //if (producerConfigTemplate.TotalNumPartitions <= 0)
                    //    throw new ArgumentException(string.Format("Please also specify the TotalNumPartitions  if you want to  send to partition by partitioner."));
                    ProduceByPartitionerClass(produceOptions, topicDataInZookeeper.Count);
                }
                else
                {
                    ProduceToRandomOrSpecificPartition(produceOptions);
                }
            }
        }
Ejemplo n.º 16
0
        static void Main2(string[] args)
        {
            var zk   = new ZooKeeperClient("192.168.4.77:2181");
            var data = zk.client.ExistsAsync("/jodis");

            Console.WriteLine(data.Result);

            Console.ReadKey();
        }
        private static async Task VerifyNodeCreated(ZooKeeperClient client, string path)
        {
            var node = await client.GetDataAsync(path);

            node.EnsureSuccess();

            node.Path.Should().Be(path);
            node.Stat.Version.Should().Be(0);
        }
Ejemplo n.º 18
0
 public ZookeeperClient(string zkConnect)
 {
     _client = new ZooKeeperClient(
         zkConnect,
         ZooKeeperConfiguration.DefaultSessionTimeout,
         ZooKeeperStringSerializer.Serializer
         );
     _client.Connect();
 }
        //{"controller_epoch":4,"leader":2,"version":1,"leader_epoch":5,"isr":[2]}
        internal static ArrayList GetIsr(ZooKeeperClient zkClient, string topic, int partition)
        {
            string data = zkClient.ReadData <string>(string.Format("/brokers/topics/{0}/partitions/{1}/state"
                                                                   , topic, partition), true);
            Dictionary <string, object> ctx = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(data);
            Type ty = ctx["isr"].GetType();

            return((ArrayList)ctx["isr"]);
        }
Ejemplo n.º 20
0
        public void WhenNewBrokerInTopicIsAddedBrokerTopicsListenerUpdatesMappings()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            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(
                       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.Subscribe(ZooKeeperClient.DefaultBrokerTopicsPath, brokerTopicsListener);
                client.CreatePersistent(brokerPath, true);
                client.WriteData(brokerPath, "172.16.66.2-1310449279123:172.16.66.2:9092");
                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();
                WaitUntillIdle(client, 500);
                client.DeleteRecursive(brokerPath);
                client.DeleteRecursive(topicPath);
            }

            Assert.IsTrue(brokers.ContainsKey(2345));
            Assert.IsTrue(mappings.Keys.Contains(CurrentTestTopic));
            Assert.AreEqual(5, mappings[CurrentTestTopic].Count);
        }
Ejemplo n.º 21
0
        public void CheckNodePath()
        {
            var zk   = new ZooKeeperClient("");
            var node = zk.ProxyNodeAsync("a").Result
                       .ProxyNodeAsync("b").Result
                       .ProxyNodeAsync("c").Result;

            Assert.Equal("/a/b/c", node.Path);
            Assert.Equal("c", node.Name);
        }
Ejemplo n.º 22
0
        public ZooKeeperRegistery(ZooKeeperClient zkClient)
        {
            _zkListeners = new ConcurrentDictionary <string, ConcurrentDictionary <INotifyListener, ChildListener> >();

            _zkStateListener = new StateListener();
            _zkStateListener.OnReconnected += this.Recover;

            _zkClient = zkClient;
            _zkClient.EnsurePath(ROOT_PATH);
            _zkClient.SubscribeStateListener(_zkStateListener);
        }
Ejemplo n.º 23
0
        protected ServiceBeacon GetServiceBeacon(ReplicaInfo replica, ZooKeeperClient client = null, Func <bool> registrationAllowedProvider = null)
        {
            client = client ?? ZooKeeperClient;
            var settings = new ServiceBeaconSettings
            {
                IterationPeriod = 60.Seconds(),
                MinimumTimeBetweenIterations = 100.Milliseconds(),
                RegistrationAllowedProvider  = registrationAllowedProvider
            };

            return(new ServiceBeacon(client, replica, settings, Log));
        }
Ejemplo n.º 24
0
        public void ZooKeeperClientFailsWhenCreatedWithWrongConnectionInfo()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       "random text",
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                Assert.Throws <FormatException>(client.Connect);
            }
        }
Ejemplo n.º 25
0
        public void ZooKeeperClientChecksIfPathExists()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperClient client = new ZooKeeperClient(
                       prodConfig.ZooKeeper.ZkConnect,
                       prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                       ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                Assert.IsTrue(client.Exists(ZooKeeperClient.DefaultBrokerTopicsPath, false));
            }
        }
Ejemplo n.º 26
0
        public void ConsumerPorformsRebalancingOnStart()
        {
            var config = this.ZooKeeperBasedConsumerConfig;

            using (var consumerConnector = new ZookeeperConsumerConnector(config, true))
            {
                var client = ReflectionHelper.GetInstanceField <ZooKeeperClient>("zkClient", consumerConnector);
                Assert.IsNotNull(client);
                client.DeleteRecursive("/consumers/group1");
                var topicCount = new Dictionary <string, int> {
                    { "test", 1 }
                };
                consumerConnector.CreateMessageStreams(topicCount);
                WaitUntillIdle(client, 1000);
                IList <string> children = client.GetChildren("/consumers", false);
                Assert.That(children, Is.Not.Null.And.Not.Empty);
                Assert.That(children, Contains.Item("group1"));
                children = client.GetChildren("/consumers/group1", false);
                Assert.That(children, Is.Not.Null.And.Not.Empty);
                Assert.That(children, Contains.Item("ids"));
                Assert.That(children, Contains.Item("owners"));
                children = client.GetChildren("/consumers/group1/ids", false);
                Assert.That(children, Is.Not.Null.And.Not.Empty);
                string consumerId = children[0];
                children = client.GetChildren("/consumers/group1/owners", false);
                Assert.That(children, Is.Not.Null.And.Not.Empty);
                Assert.That(children.Count, Is.EqualTo(1));
                Assert.That(children, Contains.Item("test"));
                children = client.GetChildren("/consumers/group1/owners/test", false);
                Assert.That(children, Is.Not.Null.And.Not.Empty);
                Assert.That(children.Count, Is.EqualTo(2));
                string partId = children[0];
                var    data   = client.ReadData <string>("/consumers/group1/owners/test/" + partId);
                Assert.That(data, Is.Not.Null.And.Not.Empty);
                Assert.That(data, Contains.Substring(consumerId));
                data = client.ReadData <string>("/consumers/group1/ids/" + consumerId);
                Assert.That(data, Is.Not.Null.And.Not.Empty);
                Assert.That(data, Is.EqualTo("{ \"test\": 1 }"));
            }

            using (var client = new ZooKeeperClient(config.ZooKeeper.ZkConnect, config.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer))
            {
                client.Connect();
                //// Should be created as ephemeral
                IList <string> children = client.GetChildren("/consumers/group1/ids");
                Assert.That(children, Is.Null.Or.Empty);
                //// Should be created as ephemeral
                children = client.GetChildren("/consumers/group1/owners/test");
                Assert.That(children, Is.Null.Or.Empty);
            }
        }
Ejemplo n.º 27
0
 public async Task khkjhfldskfjkasjdhflgfksadjfaslkj()
 {
     try
     {
         using (var client = new ZooKeeperClient("lib_zookeeper"))
         {
             await client.Client.DeleteNodeRecursively_("/home");
         }
     }
     catch (Exception e)
     {
         //
     }
 }
        public void Should_not_update_to_invalid_data()
        {
            using (var storage = GetEnvironmentsStorage())
            {
                CreateEnvironmentNode("default", "parent");

                ShouldReturnImmediately(storage, "default", new EnvironmentInfo("default", "parent", null));

                ZooKeeperClient.SetData(PathHelper.BuildEnvironmentPath("default"), new byte[] { 1, 2, 3 });

                storage.UpdateAll();
                ShouldReturnImmediately(storage, "default", new EnvironmentInfo("default", "parent", null));
            }
        }
Ejemplo n.º 29
0
 public void jlkjkfzk()
 {
     try
     {
         using (var client = new ZooKeeperClient("lib_zookeeper"))
         {
             //
         }
     }
     catch (Exception e)
     {
         //
     }
 }
Ejemplo n.º 30
0
        public void WhenClientWillNotConnectWithinGivenTimeThrows()
        {
            var prodConfig = this.ZooKeeperBasedSyncProdConfig;

            using (IZooKeeperClient client =
                       new ZooKeeperClient(
                           prodConfig.ZooKeeper.ZkConnect,
                           prodConfig.ZooKeeper.ZkSessionTimeoutMs,
                           ZooKeeperStringSerializer.Serializer,
                           1))
            {
                client.Connect();
            }
        }
Ejemplo n.º 31
0
        public SyncProducerPool(ProducerConfiguration config)
        {
            this.syncProducers = new ConcurrentDictionary <int, SyncProducerWrapper>();
            this.Config        = config;

            if (config.ZooKeeper != null)
            {
                this.zkClient = new ZooKeeperClient(config.ZooKeeper.ZkConnect, config.ZooKeeper.ZkSessionTimeoutMs,
                                                    ZooKeeperStringSerializer.Serializer);
                this.zkClient.Connect();
            }

            this.AddProducers(config);
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChildChangedEventItem"/> class.
 /// </summary>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="handler">
 /// The subscribed handler.
 /// </param>
 /// <remarks>
 /// Should use external logger to keep same format of all event logs
 /// </remarks>
 public ChildChangedEventItem(ILog logger, ZooKeeperClient.ZooKeeperEventHandler<ZooKeeperChildChangedEventArgs> handler)
 {
     this.logger = logger;
     this.ChildChanged += handler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ChildChangedEventItem"/> class.
 /// </summary>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="handler">
 /// The subscribed handler.
 /// </param>
 /// <remarks>
 /// Should use external logger to keep same format of all event logs
 /// </remarks>
 public ChildChangedEventItem(ZooKeeperClient.ZooKeeperEventHandler<ZooKeeperChildChangedEventArgs> handler)
 {
     this.ChildChanged += handler;
 }