Ejemplo n.º 1
0
        public void DeserializerUnexpectedConfigParam()
        {
            var avroDeserializer = new AvroDeserializer <int>(schemaRegistryClient);

            var config = new Dictionary <string, object>
            {
                { "avro.serializer.auto.register.schemas", false }
            };

            Assert.Throws <ArgumentException>(() => { avroDeserializer.Configure(config, true); });
        }
Ejemplo n.º 2
0
        public void DeserializerDoubleConfigureSchemaRegistry()
        {
            var avroDeserializer = new AvroDeserializer <int>(schemaRegistryClient);

            var config = new Dictionary <string, object>
            {
                { "schema.registry.url", "localhost:8081" }
            };

            Assert.Throws <ArgumentException>(() => { avroDeserializer.Configure(config, true); });
        }
        public void DeserializerConfigure()
        {
            var avroDeserializer = new AvroDeserializer <int>(schemaRegistryClient);

            var config = new Dictionary <string, string> {
            };

            var modifiedConfig = avroDeserializer.Configure(config, true);

            Assert.Equal(0, modifiedConfig.Count());
        }
        public void StringSerDe()
        {
            var avroSerializer = new AvroSerializer <string>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, object>(), false);
            var avroDeserializer = new AvroDeserializer <string>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, object>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, "abc");
            Assert.Equal("abc", avroDeserializer.Deserialize(testTopic, bytes));
        }
        public void Incompatible()
        {
            var avroSerializer = new AvroSerializer <string>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, object>(), false);
            var avroDeserializer = new AvroDeserializer <int>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, object>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, "Hello world");
            Assert.Throws <global::Avro.AvroException>(() => avroDeserializer.Deserialize(testTopic, bytes));
        }
        public void BytesSerDe()
        {
            var avroSerializer = new AvroSerializer <byte[]>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, object>(), false);
            var avroDeserializer = new AvroDeserializer <byte[]>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, object>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, new byte[] { 2, 3, 4 });
            Assert.Equal(new byte[] { 2, 3, 4 }, avroDeserializer.Deserialize(testTopic, bytes));
        }
        public void DoubleSerDe()
        {
            var avroSerializer = new AvroSerializer <double>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, object>(), false);
            var avroDeserializer = new AvroDeserializer <double>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, object>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, 123d);
            Assert.Equal(123d, avroDeserializer.Deserialize(testTopic, bytes));
        }
Ejemplo n.º 8
0
        public void BoolSerDe()
        {
            var avroSerializer = new AvroSerializer <bool>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, string>(), false);
            var avroDeserializer = new AvroDeserializer <bool>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, string>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, true);
            Assert.Equal(true, avroDeserializer.Deserialize(testTopic, bytes, false));
        }
Ejemplo n.º 9
0
        public void NullSerDe()
        {
            var avroSerializer = new AvroSerializer <Null>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, string>(), false);
            var avroDeserializer = new AvroDeserializer <Null>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, string>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, null);
            Assert.Null(avroDeserializer.Deserialize(testTopic, bytes, false));
        }
Ejemplo n.º 10
0
        public void FloatSerDe()
        {
            var avroSerializer = new AvroSerializer <float>(schemaRegistryClient);

            avroSerializer.Configure(new Dictionary <string, string>(), false);
            var avroDeserializer = new AvroDeserializer <float>(schemaRegistryClient);

            avroDeserializer.Configure(new Dictionary <string, string>(), false);
            byte[] bytes;
            bytes = avroSerializer.Serialize(testTopic, 123f);
            Assert.Equal(123f, avroDeserializer.Deserialize(testTopic, bytes, false));
        }
Ejemplo n.º 11
0
        public void DeserializerIgnoresUnrelated()
        {
            var avroDeserializer = new AvroDeserializer <int>(schemaRegistryClient);

            var config = new Dictionary <string, object>
            {
                { "some.random.config.param", false }
            };

            var modifiedConfig = avroDeserializer.Configure(config, true);

            Assert.Equal(1, modifiedConfig.Count());
        }
        public void ISpecificRecord()
        {
            var user = new User
            {
                favorite_color  = "blue",
                favorite_number = 100,
                name            = "awesome"
            };
            var serializer = new AvroSerializer <User>(schemaRegistryClient);

            serializer.Configure(new Dictionary <string, object>(), false);
            var deserializer = new AvroDeserializer <User>(schemaRegistryClient);

            deserializer.Configure(new Dictionary <string, object>(), false);

            var bytes  = serializer.Serialize("topic", user);
            var result = deserializer.Deserialize("topic", bytes);

            Assert.Equal(user.name, result.name);
            Assert.Equal(user.favorite_color, result.favorite_color);
            Assert.Equal(user.favorite_number, result.favorite_number);
        }