public void When_No_Type_Is_Set_Should_Create_ByteArray_Listener() { var attribute = new KafkaAttribute("brokers:9092", "myTopic") { }; var factory = new KafkaProducerFactory(emptyConfiguration, new DefaultNameResolver(emptyConfiguration), NullLoggerProvider.Instance); var producer = factory.Create(attribute); Assert.NotNull(producer); Assert.IsType <KafkaProducer <Null, byte[]> >(producer); var typedProducer = (KafkaProducer <Null, byte[]>)producer; Assert.Null(typedProducer.ValueSerializer); }
public void When_Value_Type_Is_Protobuf_Should_Create_Protobuf_Listener() { var attribute = new KafkaAttribute("brokers:9092", "myTopic") { ValueType = typeof(ProtoUser) }; var factory = new KafkaProducerFactory(emptyConfiguration, new DefaultNameResolver(emptyConfiguration), NullLoggerProvider.Instance); var producer = factory.Create(attribute); Assert.NotNull(producer); Assert.IsType <KafkaProducer <Null, ProtoUser> >(producer); var typedProducer = (KafkaProducer <Null, ProtoUser>)producer; Assert.NotNull(typedProducer.ValueSerializer); Assert.IsType <ProtobufSerializer <ProtoUser> >(typedProducer.ValueSerializer); }
public void When_Avro_Schema_Is_Provided_Should_Create_GenericRecord_Listener() { var attribute = new KafkaAttribute("brokers:9092", "myTopic") { AvroSchema = "fakeAvroSchema" }; var factory = new KafkaProducerFactory(emptyConfiguration, new DefaultNameResolver(emptyConfiguration), NullLoggerProvider.Instance); var producer = factory.Create(attribute); Assert.NotNull(producer); Assert.IsType <KafkaProducer <Null, GenericRecord> >(producer); var typedProducer = (KafkaProducer <Null, GenericRecord>)producer; Assert.NotNull(typedProducer.ValueSerializer); Assert.IsType <AvroSerializer <GenericRecord> >(typedProducer.ValueSerializer); }
public void When_String_Value_Type_Is_Set_Should_Create_String_Listener() { var attribute = new KafkaAttribute("brokers:9092", "myTopic") { }; var entity = new KafkaProducerEntity() { Attribute = attribute, ValueType = typeof(string), }; var factory = new KafkaProducerFactory(emptyConfiguration, new DefaultNameResolver(emptyConfiguration), NullLoggerProvider.Instance); var producer = factory.Create(entity); Assert.NotNull(producer); Assert.IsType <KafkaProducer <Null, string> >(producer); var typedProducer = (KafkaProducer <Null, string>)producer; Assert.Null(typedProducer.ValueSerializer); }
public void When_Value_Type_Is_Specific_Record_Should_Create_SpecificRecord_Listener() { var attribute = new KafkaAttribute("brokers:9092", "myTopic") { }; var entity = new KafkaProducerEntity() { Attribute = attribute, ValueType = typeof(MyAvroRecord), AvroSchema = MyAvroRecord.SchemaText, }; var factory = new KafkaProducerFactory(emptyConfiguration, new DefaultNameResolver(emptyConfiguration), NullLoggerProvider.Instance); var producer = factory.Create(entity); Assert.NotNull(producer); Assert.IsType <KafkaProducer <Null, MyAvroRecord> >(producer); var typedProducer = (KafkaProducer <Null, MyAvroRecord>)producer; Assert.NotNull(typedProducer.ValueSerializer); Assert.IsType <AvroSerializer <MyAvroRecord> >(typedProducer.ValueSerializer); }
public KafkaProducerRepository() { producer = KafkaProducerFactory.Create(); }