public void TestMessageAreSent_GlobalBatching() { var node = new Mock <INode>(); node.Setup(n => n.Post(It.IsAny <IBatchByTopicByPartition <ProduceMessage> >())).Returns(true); var cluster = new Mock <ICluster>(); cluster.Setup(c => c.RequireNewRoutingTable()) .Returns(() => Task.FromResult(new RoutingTable(new Dictionary <string, Partition[]> { { "toto", new[] { new Partition { Id = 0, Leader = node.Object } } } }))); var producer = new ProduceRouter(cluster.Object, new Configuration { BatchStrategy = BatchStrategy.Global, ProduceBatchSize = 2, ProduceBufferingTime = TimeSpan.FromDays(2), // To make sure there's no race on batch tick TaskScheduler = new CurrentThreadTaskScheduler() }, Pool); producer.Route("toto", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(42)); // The second Route will tick a batch. All of this is done on the test thread thanks // to CurrentThreadScheduler and large ProduceBufferingTime. producer.Route("toto", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(42)); producer.Route("toto", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(42)); node.Verify(n => n.Post(It.Is <IBatchByTopicByPartition <ProduceMessage> >(b => b.Count == 2))); }
public void TestFilterMinInSyncEnough() { var node = new Mock <INode>(); node.Setup(n => n.Produce(It.IsAny <ProduceMessage>())).Returns(true); var cluster = new Mock <ICluster>(); cluster.Setup(c => c.RequireNewRoutingTable()) .Returns(() => Task.FromResult(new RoutingTable(new Dictionary <string, Partition[]> { { "toto", new[] { new Partition { Id = 0, Leader = node.Object, NbIsr = 2 } } } }))); var producer = new ProduceRouter(cluster.Object, new Configuration { TaskScheduler = new CurrentThreadTaskScheduler(), SerializationConfig = new SerializationConfig { SerializeOnProduce = true }, MinInSyncReplicas = 2 }, Pool); var key = new byte[] { 65, 66 }; // 'A', 'B' var value = new byte[] { 67, 68 }; // 'C', 'D' producer.Route("toto", new Message { Key = key, Value = value }, Partitions.Any, DateTime.UtcNow.AddMinutes(42)); node.Verify(n => n.Produce(It.IsAny <ProduceMessage>()), Times.Once()); }
private async Task TestMessagesAreSentCommon() { _produceRouter.Route("test1p", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); _produceRouter.Route("test1p", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); _produceRouter.Route("test2p", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); _produceRouter.Route("test2p", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); _produceRouter.Route("testallp", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); _produceRouter.Route("testallp", new Message(), Partitions.Any, DateTime.UtcNow.AddMinutes(5)); await _produceRouter.Stop(); Assert.AreEqual(2, _messagesSentByTopic["test1p"]); Assert.AreEqual(2, _messagesSentByTopic["test2p"]); Assert.AreEqual(2, _messagesSentByTopic["testallp"]); CheckCounters(expectedMessagesEnqueued: 6, expectedMessagesReEnqueued: 0, expectedMessagesRouted: 6, expectedMessagesExpired: 0, expectedRoutingTableRequired: 1); }