示例#1
0
        public void ShouldNotUpdateInfoWhenErrorResponse()
        {
            var pool               = new Mock <ISyncProducerPool>();
            var producer           = new Mock <ISyncProducer>();
            var partitionMetadatas = new List <PartitionMetadata>()
            {
                new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty <Broker>(),
                                      Enumerable.Empty <Broker>())
            };
            var metadatas = new List <TopicMetadata>()
            {
                new TopicMetadata("test", partitionMetadatas, ErrorMapping.LeaderNotAvailableCode)
            };

            producer.Setup(p => p.Send(It.IsAny <TopicMetadataRequest>())).Returns(() => metadatas);

            var producerConfig = new SyncProducerConfiguration(new ProducerConfiguration((IList <BrokerConfiguration>)null), 0, "host1", 1234);

            producer.Setup(p => p.Config).Returns(producerConfig);
            pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List <ISyncProducer>()
            {
                producer.Object
            });
            var info = new BrokerPartitionInfo(pool.Object);

            info.GetBrokerPartitionInfo(1, "test", 1, "test");
        }
示例#2
0
        public void UpdateInfoUpdatesCache()
        {
            var pool               = new Mock <ISyncProducerPool>();
            var producer           = new Mock <ISyncProducer>();
            var partitionMetadatas = new List <PartitionMetadata>()
            {
                new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty <Broker>(),
                                      Enumerable.Empty <Broker>())
            };
            var metadatas = new List <TopicMetadata>()
            {
                new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError)
            };

            producer.Setup(p => p.Send(It.IsAny <TopicMetadataRequest>())).Returns(() => metadatas);
            pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List <ISyncProducer>()
            {
                producer.Object
            });
            var cache = new Dictionary <string, TopicMetadata>();
            var info  = new BrokerPartitionInfo(pool.Object, cache, new Dictionary <string, DateTime> {
                { "test", DateTime.MinValue }
            }, 1, null);

            info.GetBrokerPartitionInfo(1, "test", 1, "test");
            cache.ContainsKey("test").Should().BeTrue();
            var data = cache["test"];

            data.PartitionsMetadata.Count().Should().Be(1);
            data.PartitionsMetadata.First().Leader.Id.Should().Be(0);
        }
示例#3
0
        public void ShouldUpdateInfoWhenBrokerNotFound()
        {
            var pool               = new Mock <ISyncProducerPool>();
            var producer           = new Mock <ISyncProducer>();
            var partitionMetadatas = new List <PartitionMetadata>()
            {
                new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty <Broker>(),
                                      Enumerable.Empty <Broker>())
            };
            var metadatas = new List <TopicMetadata>()
            {
                new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError)
            };

            producer.Setup(p => p.Send(It.IsAny <TopicMetadataRequest>())).Returns(() => metadatas);
            pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List <ISyncProducer>()
            {
                producer.Object
            });
            var info       = new BrokerPartitionInfo(pool.Object);
            var partitions = info.GetBrokerPartitionInfo(1, "test", 1, "test");

            partitions.Count.Should().Be(1);
            var partition = partitions.First();

            partition.Topic.Should().Be("test");
            partition.Leader.BrokerId.Should().Be(0);
        }
        public void ShouldNotUpdateInfoWhenErrorResponse()
        {
            var pool = new Mock<ISyncProducerPool>();
            var producer = new Mock<ISyncProducer>();
            var partitionMetadatas = new List<PartitionMetadata>()
            {
                new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty<Broker>(),
                    Enumerable.Empty<Broker>())
            };
            var metadatas = new List<TopicMetadata>() { new TopicMetadata("test", partitionMetadatas, ErrorMapping.LeaderNotAvailableCode) };
            producer.Setup(p => p.Send(It.IsAny<TopicMetadataRequest>())).Returns(() => metadatas);

            var producerConfig = new SyncProducerConfiguration(new ProducerConfiguration((IList<BrokerConfiguration>)null), 0, "host1", 1234);
            producer.Setup(p => p.Config).Returns(producerConfig);
            pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List<ISyncProducer>() { producer.Object });
            var info = new BrokerPartitionInfo(pool.Object);
            info.GetBrokerPartitionInfo(1, "test", 1, "test");
        }
 public void ShouldUpdateInfoWhenBrokerNotFound()
 {
     var pool = new Mock<ISyncProducerPool>();
     var producer = new Mock<ISyncProducer>();
     var partitionMetadatas = new List<PartitionMetadata>()
     {
         new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty<Broker>(),
             Enumerable.Empty<Broker>())
     };
     var metadatas = new List<TopicMetadata>() { new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError) };
     producer.Setup(p => p.Send(It.IsAny<TopicMetadataRequest>())).Returns(() => metadatas);
     pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List<ISyncProducer>() { producer.Object });
     var info = new BrokerPartitionInfo(pool.Object);
     var partitions = info.GetBrokerPartitionInfo(1, "test", 1, "test");
     partitions.Count.Should().Be(1);
     var partition = partitions.First();
     partition.Topic.Should().Be("test");
     partition.Leader.BrokerId.Should().Be(0);
 }
示例#6
0
        public void ShouldUpdateInfoWhenCachedErrorResponse()
        {
            var pool               = new Mock <ISyncProducerPool>();
            var producer           = new Mock <ISyncProducer>();
            var partitionMetadatas = new List <PartitionMetadata>()
            {
                new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty <Broker>(),
                                      Enumerable.Empty <Broker>())
            };
            var cachedPartitionMetadatas = new List <PartitionMetadata>()
            {
                new PartitionMetadata(1, new Broker(1, "host1", 1234), Enumerable.Empty <Broker>(),
                                      Enumerable.Empty <Broker>())
            };
            var metadatas = new List <TopicMetadata>()
            {
                new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError)
            };

            producer.Setup(p => p.Send(It.IsAny <TopicMetadataRequest>())).Returns(() => metadatas);
            pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List <ISyncProducer>()
            {
                producer.Object
            });
            var cache = new Dictionary <string, TopicMetadata>();

            cache["test"] = new TopicMetadata("test", cachedPartitionMetadatas, ErrorMapping.NotLeaderForPartitionCode);
            var info = new BrokerPartitionInfo(pool.Object, cache, new Dictionary <string, DateTime> {
                { "test", DateTime.MinValue }
            }, 1, null);
            var partitions = info.GetBrokerPartitionInfo(1, "test", 1, "test");

            partitions.Count.Should().Be(1);
            var partition = partitions.First();

            partition.Topic.Should().Be("test");
            partition.Leader.BrokerId.Should().Be(0);
        }
 public void ShouldUpdateInfoWhenCachedErrorResponse()
 {
     var pool = new Mock<ISyncProducerPool>();
     var producer = new Mock<ISyncProducer>();
     var partitionMetadatas = new List<PartitionMetadata>()
     {
         new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty<Broker>(),
             Enumerable.Empty<Broker>())
     };
     var cachedPartitionMetadatas = new List<PartitionMetadata>()
     {
         new PartitionMetadata(1, new Broker(1, "host1", 1234), Enumerable.Empty<Broker>(),
             Enumerable.Empty<Broker>())
     };
     var metadatas = new List<TopicMetadata>() { new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError) };
     producer.Setup(p => p.Send(It.IsAny<TopicMetadataRequest>())).Returns(() => metadatas);
     pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List<ISyncProducer>() { producer.Object });
     var cache = new Dictionary<string, TopicMetadata>();
     cache["test"] = new TopicMetadata("test", cachedPartitionMetadatas, ErrorMapping.NotLeaderForPartitionCode);
     var info = new BrokerPartitionInfo(pool.Object, cache, new Dictionary<string, DateTime> { { "test", DateTime.MinValue } }, 1, null);
     var partitions = info.GetBrokerPartitionInfo(1, "test", 1, "test");
     partitions.Count.Should().Be(1);
     var partition = partitions.First();
     partition.Topic.Should().Be("test");
     partition.Leader.BrokerId.Should().Be(0);
 }
 public void UpdateInfoUpdatesCache()
 {
     var pool = new Mock<ISyncProducerPool>();
     var producer = new Mock<ISyncProducer>();
     var partitionMetadatas = new List<PartitionMetadata>()
     {
         new PartitionMetadata(0, new Broker(0, "host1", 1234), Enumerable.Empty<Broker>(),
             Enumerable.Empty<Broker>())
     };
     var metadatas = new List<TopicMetadata>() { new TopicMetadata("test", partitionMetadatas, ErrorMapping.NoError) };
     producer.Setup(p => p.Send(It.IsAny<TopicMetadataRequest>())).Returns(() => metadatas);
     pool.Setup(p => p.GetShuffledProducers()).Returns(() => new List<ISyncProducer>() { producer.Object });
     var cache = new Dictionary<string, TopicMetadata>();
     var info = new BrokerPartitionInfo(pool.Object, cache, new Dictionary<string, DateTime> { { "test", DateTime.MinValue } }, 1, null);
     info.GetBrokerPartitionInfo(1, "test", 1, "test");
     cache.ContainsKey("test").Should().BeTrue();
     var data = cache["test"];
     data.PartitionsMetadata.Count().Should().Be(1);
     data.PartitionsMetadata.First().Leader.Id.Should().Be(0);
 }