public void ShouldBackoffRequestOnMultipleFailures(ErrorResponseCode errorCode) { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()) .Returns(x => CreateMetadataResponse(errorCode), x => CreateMetadataResponse(errorCode), x => CreateMetadataResponse(errorCode), x => CreateMetadataResponse(ErrorResponseCode.NoError)); using (var provider = new KafkaMetadataProvider(_log)) { var response = provider.Get(new[] { conn }, new[] { "Test" }); } Received.InOrder(() => { conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); _log.WarnFormat("Backing off metadata request retry. Waiting for {0}ms.", 100); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); _log.WarnFormat("Backing off metadata request retry. Waiting for {0}ms.", 400); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); _log.WarnFormat("Backing off metadata request retry. Waiting for {0}ms.", 900); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); }); }
public async Task NewlyCreatedTopicShouldRetryUntilBrokerIsAssigned() { var expectedTopic = Guid.NewGuid().ToString(); var repo = new KafkaMetadataProvider(_options.Log); var response = repo.Get(new[] { GetKafkaConnection() }, new[] { expectedTopic }); var topic = (await response).Topics.FirstOrDefault(); Assert.That(topic, Is.Not.Null); Assert.That(topic.Name, Is.EqualTo(expectedTopic)); Assert.That(topic.ErrorCode, Is.EqualTo((int)ErrorResponseCode.NoError)); }
public async Task ShouldThrowExceptionWhenNotARetriableErrorCode(ErrorResponseCode errorCode) { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()).Returns(x => CreateMetadataResponse(errorCode)); using (var provider = new KafkaMetadataProvider(_log)) { var response = await provider.Get(new[] { conn }, new[] { "Test" }); } }
public async Task ShouldThrowExceptionWhenPortIsMissing(int port) { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()).Returns(x => CreateMetadataResponse(1, "123", port)); using (var provider = new KafkaMetadataProvider(_log)) { var response = await provider.Get(new[] { conn }, new[] { "Test" }); } }
public void ShouldThrowExceptionWhenHostIsMissing(string host) { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()).Returns(x => CreateMetadataResponse(1, host, 1)); using (var provider = new KafkaMetadataProvider(_log)) { var response = provider.Get(new[] { conn }, new[] { "Test" }); } }
public void ShouldReturnWhenNoErrorReceived() { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()) .Returns(x => CreateMetadataResponse(ErrorResponseCode.NoError)); using (var provider = new KafkaMetadataProvider(_log)) { var response = provider.Get(new[] { conn }, new[] { "Test" }); } conn.Received(1).SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); }
public async Task ShouldRetryWhenReceiveBrokerIdNegativeOne() { var conn = Substitute.For <IKafkaConnection>(); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()) .Returns(x => CreateMetadataResponse(-1, "123", 1), x => CreateMetadataResponse(ErrorResponseCode.NoError)); using (var provider = new KafkaMetadataProvider(_log)) { var response = await provider.Get(new[] { conn }, new[] { "Test" }); } Received.InOrder(() => { conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); _log.WarnFormat("Backing off metadata request retry. Waiting for {0}ms.", 100); conn.SendAsync(Arg.Any <IKafkaRequest <MetadataResponse> >()); }); }