/// <summary> /// Constructs a new instance of broker ingress Kafka driver. /// </summary> /// <param name="configuration"> /// The driver configuration. /// </param> /// <param name="consumerRegistry"> /// The consumer registry used to manage Kafka consumers. /// </param> /// <exception cref="ArgumentNullException"> /// One of parameters is not specified. /// </exception> /// <exception cref="ArgumentException"> /// One of required driver configuration fields is not specified. /// </exception> public BrokerIngressKafkaDriver( [NotNull] BrokerIngressKafkaDriverConfiguration configuration, [NotNull] IConsumerRegistry consumerRegistry) { _driverConfiguration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _consumerRegistry = consumerRegistry ?? throw new ArgumentNullException(nameof(consumerRegistry)); const string message = "Ingress Kafka driver configuration missing "; if (_driverConfiguration.ConsumerConfiguratorType == null) { throw new ArgumentException(message + "consumer configurator type.", nameof(configuration)); } if (_driverConfiguration.ConsumerFactoryType == null) { throw new ArgumentException(message + "consumer factory type.", nameof(configuration)); } if (_driverConfiguration.DeserializerFactoryType == null) { throw new ArgumentException(message + "deserializer factory type.", nameof(configuration)); } if (_driverConfiguration.HeaderValueCodecType == null) { throw new ArgumentException(message + "header value codec type.", nameof(configuration)); } }
public void when_consumer_configurator_set_it_should_be_set_in_configuration() { var configuration = new BrokerIngressKafkaDriverConfiguration(); var sut = new BrokerIngressKafkaDriverConfigurator(configuration); sut.WithConsumerConfigurator <StabConsumerConfigurator>().Should().BeSameAs(sut); configuration.ConsumerConfiguratorType.Should().Be <StabConsumerConfigurator>(); }
public void when_header_value_parser_set_it_should_be_set_in_configuration() { var configuration = new BrokerIngressKafkaDriverConfiguration(); var sut = new BrokerIngressKafkaDriverConfigurator(configuration); sut.WithHeaderValueCodec <StabHeaderValueCodec>().Should().BeSameAs(sut); configuration.HeaderValueCodecType.Should().Be <StabHeaderValueCodec>(); }
public void when_deserializer_factory_set_it_should_be_set_in_configuration() { var configuration = new BrokerIngressKafkaDriverConfiguration(); var sut = new BrokerIngressKafkaDriverConfigurator(configuration); sut.WithDeserializerFactory <StabDeserializerFactory>().Should().BeSameAs(sut); configuration.DeserializerFactoryType.Should().Be <StabDeserializerFactory>(); }
public void when_null_set_as_consumer_configuration_it_should_fail() { var configuration = new BrokerIngressKafkaDriverConfiguration(); var configurator = new BrokerIngressKafkaDriverConfigurator(configuration); Action sut = () => configurator.WithConsumerConfig(consumerConfig: null); sut.Should().ThrowExactly <ArgumentNullException>(); }
public void when_consumer_configuration_set_it_should_be_set_in_configuration() { var configuration = new BrokerIngressKafkaDriverConfiguration(); var sut = new BrokerIngressKafkaDriverConfigurator(configuration); var expected = new ConsumerConfig(); sut.WithConsumerConfig(expected).Should().BeSameAs(sut); configuration.ConsumerConfig.Should().BeSameAs(expected); }
private static BrokerIngressKafkaDriverConfiguration MakeDriverConfiguration() { var configuration = new BrokerIngressKafkaDriverConfiguration { ConsumerConfig = new ConsumerConfig(), ConsumerConfiguratorType = typeof(TestConsumerConfigurator), ConsumerFactoryType = typeof(TestConsumerFactory), DeserializerFactoryType = typeof(TestDeserializerFactory), HeaderValueCodecType = typeof(TestHeaderValueCodec) }; return(configuration); }
public void when_constructed_with_invalid_arguments_it_should_fail() { BrokerIngressKafkaDriverConfiguration configuration = null; var consumerRegistry = Mock.Of <IConsumerRegistry>(); // ReSharper disable once ObjectCreationAsStatement Action sut = () => new BrokerIngressKafkaDriver(configuration, consumerRegistry); sut.Should().ThrowExactly <ArgumentNullException>().Which.ParamName.Should() .Be("configuration", "null is not valid configuration"); configuration = new BrokerIngressKafkaDriverConfiguration(); consumerRegistry = null; sut.Should().ThrowExactly <ArgumentNullException>().Which.ParamName.Should() .Be("consumerRegistry", "null is not valid consumer registry"); consumerRegistry = Mock.Of <IConsumerRegistry>(); configuration = new BrokerIngressKafkaDriverConfiguration { ConsumerConfiguratorType = typeof(object), ConsumerFactoryType = typeof(object), DeserializerFactoryType = typeof(object) }; configuration.ConsumerConfiguratorType = null; sut.Should().ThrowExactly <ArgumentException>().Which.ParamName.Should() .Be("configuration", "null is not valid consumer configuration type"); configuration.ConsumerConfiguratorType = typeof(object); configuration.ConsumerFactoryType = null; sut.Should().ThrowExactly <ArgumentException>().Which.ParamName.Should() .Be("configuration", "null is not valid consumer factory type"); configuration.ConsumerFactoryType = typeof(object); configuration.DeserializerFactoryType = null; sut.Should().ThrowExactly <ArgumentException>().Which.ParamName.Should() .Be("configuration", "null is not valid deserializer factory type"); configuration.DeserializerFactoryType = typeof(object); configuration.HeaderValueCodecType = null; sut.Should().ThrowExactly <ArgumentException>().Which.ParamName.Should() .Be("configuration", "null is not valid deserializer factory type"); }