コード例 #1
0
        public async Task VerifyABrokerStoppingAndRestartingCanBeHandledByTheConsumer()
        {
            using (var cluster = new KafkaTestCluster("server.home", 1))
            {
                var topic = "test";
                cluster.CreateTopic(topic);
                using (var brokers = new KafkaBrokers(cluster.CreateBrokerUris()))
                {
                    var producer = KafkaProducer.Create(brokers, new StringSerializer());
                    await producer.SendAsync(KeyedMessage.Create(topic, "Test"), CancellationToken.None);

                    await Task.Delay(1000);

                    cluster.StopKafkaBroker(0);
                    cluster.RestartKafkaBroker(0);

                    var consumer = KafkaConsumer.Create(topic, brokers, new StringSerializer(),
                                                        new TopicSelector {
                        Topic = topic, Partition = 0, Offset = 0
                    });
                    var result = await consumer.ReceiveAsync(CancellationToken.None);

                    Assert.That(result, Has.Count.EqualTo(1));
                    var first = result[0];

                    Assert.That(first.Value, Is.EqualTo("Test"));
                    Assert.That(first.Offset, Is.EqualTo(0));
                }
                cluster.DeleteTopic(topic);
            }
        }
コード例 #2
0
 public void TestClusterCanBeManaged()
 {
     using (var cluster = new KafkaTestCluster("server.home", 3))
     {
         cluster.CreateTopic("test", 2, 2);
         cluster.DeleteTopic("test");
     }
 }
コード例 #3
0
 public void DestroyTestCluster()
 {
     testCluster.Dispose();
     testCluster = null;
 }
コード例 #4
0
 public void BuildTestCluster()
 {
     testCluster = new KafkaTestCluster("server.home", 1);
 }