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(); }
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 async Task BrokerRouterUsesFactoryToAddNewBrokers() { var router = new BrokerRouter(new KafkaOptions { KafkaServerUri = new List <Uri> { new Uri("http://localhost:1") }, KafkaConnectionFactory = _mockKafkaConnectionFactory.Object }); _mockKafkaConnection1.Setup(x => x.SendAsync(It.IsAny <IKafkaRequest <MetadataResponse> >())) .Returns(() => Task.Run(async() => new List <MetadataResponse> { await BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers() })); await router.RefreshMissingTopicMetadata(TestTopic); var topics = router.GetTopicMetadataFromLocalCache(TestTopic); _mockKafkaConnectionFactory.Verify(x => x.Create(It.Is <KafkaEndpoint>(e => e.Endpoint.Port == 2), It.IsAny <TimeSpan>(), It.IsAny <IKafkaLog>(), It.IsAny <int>(), It.IsAny <TimeSpan?>(), It.IsAny <StatisticsTrackerOptions>()), Times.Once()); }
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(); }