Пример #1
0
        public void DefautlValue()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new StreamConfig();
            var serdes           = new MockAvroSerDes(mockSchemaClient);

            config.ApplicationId                  = "test-workflow-avroserdes";
            config.DefaultKeySerDes               = new StringSerDes();
            config.DefaultValueSerDes             = serdes;
            config.SchemaRegistryMaxCachedSchemas = null;
            config.SchemaRegistryRequestTimeoutMs = null;

            var builder = new StreamBuilder();

            builder
            .Stream <string, Person>("person")
            .Filter((k, v) => v.age >= 18)
            .MapValues((v) => v.age)
            .To <StringSerDes, Int32SerDes>("person-major");

            var topo = builder.Build();

            using (var driver = new TopologyTestDriver(topo, config))
            {
                var input  = driver.CreateInputTopic <string, Person>("person");
                var output = driver.CreateOuputTopic <string, int, StringSerDes, Int32SerDes>("person-major");
                input.PipeInput("test1", new Person {
                    age = 23, firstName = "f", lastName = "l"
                });
                var record = output.ReadKeyValue();
                Assert.IsNotNull(record);
                Assert.AreEqual("test1", record.Message.Key);
                Assert.AreEqual(23, record.Message.Value);
            }
        }
Пример #2
0
        public void IncorrectConfigurationInterface()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new Mock <IStreamConfig>();
            var serdes           = new MockAvroSerDes(mockSchemaClient);

            Assert.Throws <StreamConfigException>(() => serdes.Initialize(new Net.SerDes.SerDesContext(config.Object)));
        }
Пример #3
0
        public void DefaultSchemaRegistryConfig()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new StreamConfig();

            var serdes = new MockAvroSerDes(mockSchemaClient);

            serdes.Initialize(new Net.SerDes.SerDesContext(config));

            Assert.AreEqual(100, mockSchemaClient.MaxCachedSchemas);
            Assert.AreEqual(30000, mockSchemaClient.RequestTimeoutMs);
        }
Пример #4
0
        public void SerializeOK()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new StreamConfig();
            var serdes           = new MockAvroSerDes(mockSchemaClient);

            serdes.Initialize(new Net.SerDes.SerDesContext(config));
            var person = new Person {
                age = 18, firstName = "TEST", lastName = "TEST"
            };
            var bytes = serdes.Serialize(person, new Confluent.Kafka.SerializationContext(Confluent.Kafka.MessageComponentType.Value, topic));

            Assert.IsNotNull(bytes);
            Assert.IsTrue(bytes.Length > 0);
        }
Пример #5
0
        public void SchemaRegistryConfig()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new StreamConfig();

            config.AutoRegisterSchemas            = true;
            config.SchemaRegistryMaxCachedSchemas = 1;
            config.SchemaRegistryRequestTimeoutMs = 30;
            config.SubjectNameStrategy            = SubjectNameStrategy.TopicRecord;

            var serdes = new MockAvroSerDes(mockSchemaClient);

            serdes.Initialize(new Net.SerDes.SerDesContext(config));

            Assert.AreEqual(1, mockSchemaClient.MaxCachedSchemas);
            Assert.AreEqual(30, mockSchemaClient.RequestTimeoutMs);
        }
Пример #6
0
        public void DeserializeOK()
        {
            var mockSchemaClient = new MockSchemaRegistryClient();
            var config           = new StreamConfig();
            var serdes           = new MockAvroSerDes(mockSchemaClient);

            serdes.Initialize(new Net.SerDes.SerDesContext(config));
            var person = new Person {
                age = 18, firstName = "TEST", lastName = "TEST"
            };
            var bytes = serdes.Serialize(person, new Confluent.Kafka.SerializationContext(Confluent.Kafka.MessageComponentType.Value, topic));
            var pbis  = serdes.Deserialize(bytes, new Confluent.Kafka.SerializationContext(Confluent.Kafka.MessageComponentType.Value, topic));

            Assert.AreEqual(18, pbis.age);
            Assert.AreEqual("TEST", pbis.firstName);
            Assert.AreEqual("TEST", pbis.lastName);
        }