public void OffsetCommitShouldStoreMetadata()
        {
            const int    partitionId = 0;
            const long   offset      = 101;
            const string metadata    = "metadata";

            var router = new BrokerRouter(Options);

            var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationTopic, partitionId);

            var commit         = CreateOffsetCommitRequest(IntegrationConfig.IntegrationConsumer, partitionId, offset, metadata);
            var commitResponse = conn.Connection.SendAsync(commit).Result.FirstOrDefault();

            Assert.That(commitResponse, Is.Not.Null);
            Assert.That(commitResponse.Error, Is.EqualTo((int)ErrorResponseCode.NoError));

            var fetch         = CreateOffsetFetchRequest(IntegrationConfig.IntegrationConsumer, partitionId);
            var fetchResponse = conn.Connection.SendAsync(fetch).Result.FirstOrDefault();

            Assert.That(fetchResponse, Is.Not.Null);
            Assert.That(fetchResponse.Error, Is.EqualTo((int)ErrorResponseCode.NoError));
            Assert.That(fetchResponse.Offset, Is.EqualTo(offset));
            Assert.That(fetchResponse.MetaData, Is.EqualTo(metadata));
            router.Dispose();
        }
        public async Task OffsetCommitShouldStoreOffsetValue()
        {
            const int  partitionId = 0;
            const long offset      = 99;

            var router = new BrokerRouter(Options);

            await router.RefreshMissingTopicMetadata(IntegrationConfig.IntegrationTopic);

            var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationTopic, partitionId);

            var commit         = CreateOffsetCommitRequest(IntegrationConfig.IntegrationConsumer, partitionId, offset);
            var commitResponse = (await conn.Connection.SendAsync(commit)).FirstOrDefault();

            Assert.That(commitResponse, Is.Not.Null);
            Assert.That(commitResponse.Error, Is.EqualTo((int)ErrorResponseCode.NoError));

            var fetch         = CreateOffsetFetchRequest(IntegrationConfig.IntegrationConsumer, partitionId);
            var fetchResponse = (await conn.Connection.SendAsync(fetch)).FirstOrDefault();

            Assert.That(fetchResponse, Is.Not.Null);
            Assert.That(fetchResponse.Error, Is.EqualTo((int)ErrorResponseCode.NoError));
            Assert.That(fetchResponse.Offset, Is.EqualTo(offset));
            router.Dispose();
        }
Beispiel #3
0
        public async Task EnsureGzipCompressedMessageCanSend()
        {
            IntegrationConfig.NoDebugLog.InfoFormat(IntegrationConfig.Highlight("start EnsureGzipCompressedMessageCanSend"));
            using (var conn = GetKafkaConnection())
            {
                conn.SendAsync(new MetadataRequest
                {
                    Topics = new List <string>(new[] { IntegrationConfig.IntegrationCompressionTopic })
                })
                .Wait(TimeSpan.FromSeconds(10));
            }

            using (var router = new BrokerRouter(_options))
            {
                IntegrationConfig.NoDebugLog.InfoFormat(IntegrationConfig.Highlight("start RefreshMissingTopicMetadata"));
                await router.RefreshMissingTopicMetadata(IntegrationConfig.IntegrationCompressionTopic);

                IntegrationConfig.NoDebugLog.InfoFormat(IntegrationConfig.Highlight("end RefreshMissingTopicMetadata"));
                var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationCompressionTopic, 0);

                var request = new ProduceRequest
                {
                    Acks      = 1,
                    TimeoutMS = 1000,
                    Payload   = new List <Payload>
                    {
                        new Payload
                        {
                            Codec     = MessageCodec.CodecGzip,
                            Topic     = IntegrationConfig.IntegrationCompressionTopic,
                            Partition = 0,
                            Messages  = new List <Message>
                            {
                                new Message("0", "1"),
                                new Message("1", "1"),
                                new Message("2", "1")
                            }
                        }
                    }
                };
                IntegrationConfig.NoDebugLog.InfoFormat(IntegrationConfig.Highlight("start SendAsync"));
                var response = conn.Connection.SendAsync(request).Result;
                IntegrationConfig.NoDebugLog.InfoFormat("end SendAsync");
                Assert.That(response.First().Error, Is.EqualTo(0));
                IntegrationConfig.NoDebugLog.InfoFormat("start dispose");
            }
            IntegrationConfig.NoDebugLog.InfoFormat(IntegrationConfig.Highlight("end EnsureGzipCompressedMessageCanSend"));
        }
        public void ConsumerMetadataRequestShouldReturnWithoutError()
        {
            using (var router = new BrokerRouter(Options))
            {
                var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationTopic);

                var request = new ConsumerMetadataRequest {
                    ConsumerGroup = IntegrationConfig.IntegrationConsumer
                };

                var response = conn.Connection.SendAsync(request).Result.FirstOrDefault();

                Assert.That(response, Is.Not.Null);
                Assert.That(response.Error, Is.EqualTo((int)ErrorResponseCode.NoError));
            }
        }
        public async Task OffsetFetchRequestOfNonExistingGroupShouldReturnNoError()
        {
            //From documentation: https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+ProtocolTests#AGuideToTheKafkaProtocol-OffsetFetchRequest
            //Note that if there is no offset associated with a topic-partition under that consumer group the broker does not set an error code
            //(since it is not really an error), but returns empty metadata and sets the offset field to -1.
            const int partitionId = 0;
            var       router      = new BrokerRouter(Options);

            var request = CreateOffsetFetchRequest(Guid.NewGuid().ToString(), partitionId);
            await router.RefreshMissingTopicMetadata(IntegrationConfig.IntegrationTopic);

            var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationTopic, partitionId);

            var response = (await conn.Connection.SendAsync(request)).FirstOrDefault();

            Assert.That(response, Is.Not.Null);
            Assert.That(response.Error, Is.EqualTo((int)ErrorResponseCode.NoError));
            Assert.That(response.Offset, Is.EqualTo(-1));
            router.Dispose();
        }