Exemplo n.º 1
0
        public async Task ThrowsOnUnrecognizedWireFormat(byte[] encoding)
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <int>(
                registryClientMock.Object);

            var context = new SerializationContext(MessageComponentType.Value, "test_topic");

            await Assert.ThrowsAsync <InvalidEncodingException>(() =>
                                                                deserializer.DeserializeAsync(encoding, encoding.Length == 0, context));
        }
Exemplo n.º 2
0
        public async Task ReturnsTombstone()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <object>(
                registryClientMock.Object,
                tombstoneBehavior: TombstoneBehavior.Strict);

            var encoding = Array.Empty <byte>();
            var context  = new SerializationContext(MessageComponentType.Value, "test_topic");

            Assert.Null(await deserializer.DeserializeAsync(encoding, encoding.Length == 0, context));
        }
Exemplo n.º 3
0
        public async Task ThrowsOnInvalidTombstoneComponent()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <object>(
                registryClientMock.Object,
                tombstoneBehavior: TombstoneBehavior.Strict);

            var encoding = Array.Empty <byte>();
            var context  = new SerializationContext(MessageComponentType.Key, "test_topic");

            await Assert.ThrowsAsync <InvalidEncodingException>(() =>
                                                                deserializer.DeserializeAsync(encoding, encoding.Length == 0, context));
        }
Exemplo n.º 4
0
        public async Task HandlesConfluentWireFormatBytesCase()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <byte[]>(
                registryClientMock.Object);

            var data     = new byte[] { 0x02 };
            var encoding = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 };
            var context  = new SerializationContext(MessageComponentType.Value, "test_topic");

            registryClientMock
            .Setup(c => c.GetSchemaAsync(0, null))
            .ReturnsAsync(new Schema("\"bytes\"", SchemaType.Avro));

            Assert.Equal(data, await deserializer.DeserializeAsync(encoding, false, context));
        }
Exemplo n.º 5
0
        public async Task ProvidesDefaultDeserializationComponents()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <int>(
                registryClientMock.Object);

            var data     = 4;
            var encoding = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x04, 0x08 };
            var context  = new SerializationContext(MessageComponentType.Value, "test_topic");

            registryClientMock
            .Setup(c => c.GetSchemaAsync(4, null))
            .ReturnsAsync(new Schema("\"int\"", SchemaType.Avro));

            Assert.Equal(
                data,
                await deserializer.DeserializeAsync(encoding, encoding.Length == 0, context));
        }
Exemplo n.º 6
0
        public async Task CachesGeneratedDeserializers()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <object>(
                registryClientMock.Object);

            var encoding = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            var context  = new SerializationContext(MessageComponentType.Value, "test_topic");

            registryClientMock
            .Setup(c => c.GetSchemaAsync(0, null))
            .ReturnsAsync(new Schema("\"null\"", SchemaType.Avro));

            await Task.WhenAll(Enumerable.Range(0, 5).Select(i =>
                                                             deserializer.DeserializeAsync(encoding, encoding.Length == 0, context)));

            registryClientMock
            .Verify(c => c.GetSchemaAsync(0, null), Times.Once());
        }
Exemplo n.º 7
0
        public async Task DoesNotCacheSchemaRegistryFailures()
        {
            var deserializer = new AsyncSchemaRegistryDeserializer <object>(
                registryClientMock.Object);

            var encoding = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            var context  = new SerializationContext(MessageComponentType.Value, "test_topic");

            registryClientMock
            .Setup(c => c.GetSchemaAsync(0, null))
            .ThrowsAsync(new HttpRequestException());

            await Assert.ThrowsAsync <HttpRequestException>(() =>
                                                            deserializer.DeserializeAsync(encoding, encoding.Length == 0, context));

            registryClientMock
            .Setup(c => c.GetSchemaAsync(0, null))
            .ReturnsAsync(new Schema("\"null\"", SchemaType.Avro));

            await deserializer.DeserializeAsync(encoding, encoding.Length == 0, context);
        }