public FetcherTest() { this.cluster = new Cluster(Configs.Select(c => new Broker(c.BrokerId, "localhost", c.Port))); this.topicInfos = this.Configs.Select( c => new PartitionTopicInfo( this.topic, 0, this.queue, new AtomicLong(0), new AtomicLong(0), new AtomicInteger(0), string.Empty)) .ToList(); AdminUtils.CreateOrUpdateTopicPartitionAssignmentPathInZK( this.ZkClient, this.topic, new Dictionary <int, List <int> > { { 0, new List <int> { Configs.First().BrokerId } } }, new Dictionary <string, string>()); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, this.topic, 0, 500); this.fetcher = new ConsumerFetcherManager("consumer1", new ConsumerConfig(string.Empty, 1234, string.Empty), ZkClient); this.fetcher.StopConnections(); this.fetcher.StartConnections(this.topicInfos, this.cluster); }
public ConsumerIteratorTest() { this.cluster = new Cluster(Configs.Select(c => new Broker(c.BrokerId, "localhost", c.Port))); this.topicInfos = this.Configs.Select( c => new PartitionTopicInfo( this.topic, 0, this.queue, new AtomicLong(this.consumedOffset), new AtomicLong(0), new AtomicInteger(0), string.Empty)) .ToList(); this.consumerConfig = TestUtils.CreateConsumerProperties(this.ZkConnect, group, consumer0); AdminUtils.CreateOrUpdateTopicPartitionAssignmentPathInZK( this.ZkClient, this.topic, new Dictionary <int, List <int> > { { 0, new List <int> { Configs.First().BrokerId } } }, new Dictionary <string, string>()); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, this.topic, 0, 500); }
public void TestSendWithDeadBroker() { var config = new ProducerConfig { Serializer = typeof(StringEncoder).AssemblyQualifiedName, KeySerializer = typeof(StringEncoder).AssemblyQualifiedName, PartitionerClass = typeof(StaticPartitioner).AssemblyQualifiedName, Brokers = TestUtils.GetBrokerListFromConfigs( new List <TempKafkaConfig> { this.config1, this.config2 }), RequestRequiredAcks = 1, RequestTimeoutMs = 2000 }; var topic = "new-topic"; // create topic AdminUtils.CreateOrUpdateTopicPartitionAssignmentPathInZK( this.ZkClient, topic, new Dictionary <int, List <int> > { { 0, new List <int> { 0 } }, { 1, new List <int> { 0 } }, { 2, new List <int> { 0 } }, { 3, new List <int> { 0 } }, }, new Dictionary <string, string>()); // waiting for 1 partition is enought TestUtils.WaitUntilMetadataIsPropagated(this.servers, topic, 0, 1000); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, topic, 0, 500); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, topic, 1, 500); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, topic, 2, 500); TestUtils.WaitUntilLeaderIsElectedOrChanged(this.ZkClient, topic, 3, 500); var producer = new Producer <string, string>(config); try { // Available partition ids should be 0, 1, 2 and 3, all lead and hosted only // on broker 0 producer.Send(new KeyedMessage <string, string>(topic, "test", "test1")); } finally { Thread.Sleep(1000); // wait for server to fetch message from consumer // kill the server using (this.server1) { this.server1.Kill(); SpinWait.SpinUntil(() => this.server1.HasExited, 500); } } try { // These sends should fail since there are no available brokers producer.Send(new KeyedMessage <string, string>(topic, "test", "test1")); Assert.True(false, "Should fail since no leader exists for the partition."); } catch { } // NOTE we can rewrite rest of test as we can't do the clean shutdown producer.Dispose(); }