Exemple #1
0
        public void SerializerDoubleConfigureSchemaRegistry()
        {
            var avroSerializer = new AvroSerializer <int>(schemaRegistryClient);

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

            Assert.Throws <ArgumentException>(() => { avroSerializer.Configure(config, true); });
        }
        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 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 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));
        }
Exemple #6
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));
        }
Exemple #7
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));
        }
Exemple #8
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));
        }
Exemple #9
0
        public void SerializerIgnoresUnrelated()
        {
            var avroSerializer = new AvroSerializer <int>(schemaRegistryClient);

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

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

            Assert.Equal(1, modifiedConfig.Count());
        }
Exemple #10
0
        public void SerializerUnexpectedConfigParam()
        {
            var avroSerializer = new AvroSerializer <int>(schemaRegistryClient);

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

            Assert.Throws <ArgumentException>(() => { avroSerializer.Configure(config, true); });
        }
        public void SerializerDefaults()
        {
            var avroSerializer = new AvroSerializer <int>(schemaRegistryClient);

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

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

            Assert.Equal(0, modifiedConfig.Count());
            Assert.Equal(AvroSerializer <int> .DefaultInitialBufferSize, avroSerializer.InitialBufferSize);
            Assert.True(avroSerializer.AutoRegisterSchema);
        }
Exemple #12
0
        public void SerializerConfigure()
        {
            var avroSerializer = new AvroSerializer <int>(schemaRegistryClient);

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

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

            Assert.Equal(0, 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);
        }