diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/CHANGELOG.md b/sdk/schemaregistry/azure-schemaregistry-avroserializer/CHANGELOG.md index ea56671d39ce..6409e633f146 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/CHANGELOG.md +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/CHANGELOG.md @@ -5,6 +5,9 @@ ### Features Added - Async version of `AvroSerializer` has been added under `azure.schemaregistry.serializer.avroserializer.aio`. +- `SchemaParseError`, `SchemaSerializationError`, and `SchemaDeserializationError` have been introduced under `azure.schemaregistry.serializer.avroserializer.exceptions` and will be raised for corresponding operations. + - `SchemaParseError` and `SchemaSerializationError` may be raised for errors when calling `serialize` on `AvroSerializer`. + - `SchemaParseError` and `SchemaDeserializationError` may be raised for errors when calling `deserialize` on `AvroSerializer`. ### Breaking Changes diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_abstract_avro_serializer.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_abstract_avro_serializer.py new file mode 100644 index 000000000000..77b0dc9bf34d --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_abstract_avro_serializer.py @@ -0,0 +1,65 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from typing import BinaryIO, TypeVar, Union +from abc import abstractmethod + +ObjectType = TypeVar("ObjectType") + +class AbstractAvroObjectSerializer(object): + """ + An Avro serializer used for serializing/deserializing an Avro RecordSchema. + """ + + @abstractmethod + def get_schema_fullname( + self, + schema, # type: str + ): + # type: (str) -> str + """ + Returns the namespace-qualified name of the provided schema. + Schema must be a Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param schema: An Avro RecordSchema + :type schema: str + :rtype: str + """ + + + @abstractmethod + def serialize( + self, + data, # type: ObjectType + schema, # type: str + ): + # type: (ObjectType, str) -> bytes + """Convert the provided value to it's binary representation and write it to the stream. + Schema must be a Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param data: An object to serialize + :type data: ObjectType + :param schema: An Avro RecordSchema + :type schema: str + :returns: Encoded bytes + :rtype: bytes + """ + + @abstractmethod + def deserialize( + self, + data, # type: Union[bytes, BinaryIO] + schema, # type: str + ): + # type: (Union[bytes, BinaryIO], str) -> ObjectType + """Read the binary representation into a specific type. + Return type will be ignored, since the schema is deduced from the provided bytes. + :param data: A stream of bytes or bytes directly + :type data: BinaryIO or bytes + :param schema: An Avro RecordSchema + :type schema: str + :returns: An instantiated object + :rtype: ObjectType + """ diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_avro_serializer.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_apache_avro_serializer.py similarity index 62% rename from sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_avro_serializer.py rename to sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_apache_avro_serializer.py index 0f40857e6e93..7f3c07345daf 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_avro_serializer.py +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_apache_avro_serializer.py @@ -1,28 +1,8 @@ -# -------------------------------------------------------------------------- -# +# -------------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. -# -# The MIT License (MIT) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the ""Software""), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -# -# -------------------------------------------------------------------------- +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + try: from functools import lru_cache except ImportError: @@ -32,10 +12,12 @@ import avro from avro.io import DatumWriter, DatumReader, BinaryDecoder, BinaryEncoder +from ._abstract_avro_serializer import AbstractAvroObjectSerializer + ObjectType = TypeVar("ObjectType") -class AvroObjectSerializer(object): +class ApacheAvroObjectSerializer(AbstractAvroObjectSerializer): def __init__(self, codec=None): """A Avro serializer using avro lib from Apache. @@ -44,13 +26,21 @@ def __init__(self, codec=None): self._writer_codec = codec @lru_cache(maxsize=128) - def _get_schema_writer(self, schema): # pylint: disable=no-self-use - schema = avro.schema.parse(schema) + def parse_schema(self, schema): # pylint: disable=no-self-use + return avro.schema.parse(schema) + + def get_schema_fullname(self, schema): + parsed_schema = self.parse_schema(schema) + return parsed_schema.fullname + + @lru_cache(maxsize=128) + def get_schema_writer(self, schema): # pylint: disable=no-self-use + schema = self.parse_schema(schema) return DatumWriter(schema) @lru_cache(maxsize=128) - def _get_schema_reader(self, schema): # pylint: disable=no-self-use - schema = avro.schema.parse(schema) + def get_schema_reader(self, schema): # pylint: disable=no-self-use + schema = self.parse_schema(schema) return DatumReader(writers_schema=schema) # pylint: disable=no-self-use @@ -66,14 +56,14 @@ def serialize( :param data: An object to serialize :type data: ObjectType :param schema: An Avro RecordSchema - :type schema: Union[str, bytes, avro.schema.Schema] + :type schema: str :returns: Encoded bytes :rtype: bytes """ if not schema: raise ValueError("Schema is required in Avro serializer.") - writer = self._get_schema_writer(str(schema)) + writer = self.get_schema_writer(schema) stream = BytesIO() with stream: @@ -93,14 +83,14 @@ def deserialize( :param data: A stream of bytes or bytes directly :type data: BinaryIO or bytes :param schema: An Avro RecordSchema - :type schema: Union[str, bytes, avro.schema.Schema] + :type schema: str :returns: An instantiated object :rtype: ObjectType """ if not hasattr(data, 'read'): data = BytesIO(data) - reader = self._get_schema_reader(str(schema)) + reader = self.get_schema_reader(schema) with data: bin_decoder = BinaryDecoder(data) diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_schema_registry_avro_serializer.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_schema_registry_avro_serializer.py index 387c9007a299..1ddf804abe35 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_schema_registry_avro_serializer.py +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_schema_registry_avro_serializer.py @@ -30,9 +30,13 @@ from io import BytesIO from typing import Any, Dict, Mapping +from .exceptions import ( + SchemaParseError, + SchemaSerializationError, + SchemaDeserializationError, +) +from ._apache_avro_serializer import ApacheAvroObjectSerializer as AvroObjectSerializer from ._constants import SCHEMA_ID_START_INDEX, SCHEMA_ID_LENGTH, DATA_START_INDEX -from ._avro_serializer import AvroObjectSerializer -from ._utils import parse_schema class AvroSerializer(object): @@ -53,19 +57,21 @@ def __init__(self, **kwargs): # type: (Any) -> None try: self._schema_group = kwargs.pop("group_name") - self._schema_registry_client = kwargs.pop("client") # type: "SchemaRegistryClient" + self._schema_registry_client = kwargs.pop( + "client" + ) # type: "SchemaRegistryClient" except KeyError as e: raise TypeError("'{}' is a required keyword.".format(e.args[0])) self._avro_serializer = AvroObjectSerializer(codec=kwargs.get("codec")) self._auto_register_schemas = kwargs.get("auto_register_schemas", False) self._auto_register_schema_func = ( - self._schema_registry_client.register_schema - if self._auto_register_schemas - else self._schema_registry_client.get_schema_properties - ) + self._schema_registry_client.register_schema + if self._auto_register_schemas + else self._schema_registry_client.get_schema_properties + ) def __enter__(self): - # type: () -> SchemaRegistryAvroSerializer + # type: () -> AvroSerializer self._schema_registry_client.__enter__() return self @@ -107,6 +113,7 @@ def _get_schema(self, schema_id, **kwargs): :param str schema_id: Schema id :return: Schema content + :rtype: str """ schema_str = self._schema_registry_client.get_schema( schema_id, **kwargs @@ -120,21 +127,45 @@ def serialize(self, value, **kwargs): denoting record format identifier. The following 32 bytes denoting schema id returned by schema registry service. The remaining bytes are the real data payload. + Schema must be an Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param value: The data to be encoded. :type value: Mapping[str, Any] :keyword schema: Required. The schema used to encode the data. :paramtype schema: str :rtype: bytes + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaParseError: + Indicates an issue with parsing schema. + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaSerializationError: + Indicates an issue with serializing data for provided schema. """ try: raw_input_schema = kwargs.pop("schema") except KeyError as e: raise TypeError("'{}' is a required keyword.".format(e.args[0])) - cached_schema = parse_schema(raw_input_schema) record_format_identifier = b"\0\0\0\0" - schema_id = self._get_schema_id(cached_schema.fullname, str(cached_schema), **kwargs) - data_bytes = self._avro_serializer.serialize(value, cached_schema) + + try: + schema_fullname = self._avro_serializer.get_schema_fullname( + raw_input_schema + ) + except Exception as e: # pylint:disable=broad-except + SchemaParseError( + "Cannot parse schema: {}".format(raw_input_schema), error=e + ).raise_with_traceback() + + schema_id = self._get_schema_id(schema_fullname, raw_input_schema, **kwargs) + try: + data_bytes = self._avro_serializer.serialize(value, raw_input_schema) + except Exception as e: # pylint:disable=broad-except + SchemaSerializationError( + "Cannot serialize value '{}' for schema: {}".format( + value, raw_input_schema + ), + error=e, + ).raise_with_traceback() stream = BytesIO() @@ -152,8 +183,15 @@ def deserialize(self, value, **kwargs): """ Decode bytes data. + Data must follow format of associated Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param bytes value: The bytes data needs to be decoded. :rtype: Dict[str, Any] + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaParseError: + Indicates an issue with parsing schema. + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaDeserializationError: + Indicates an issue with deserializing value. """ # record_format_identifier = data[0:4] # The first 4 bytes are retained for future record format identifier. schema_id = value[ @@ -161,7 +199,15 @@ def deserialize(self, value, **kwargs): ].decode("utf-8") schema_definition = self._get_schema(schema_id, **kwargs) - dict_value = self._avro_serializer.deserialize( - value[DATA_START_INDEX:], schema_definition - ) + try: + dict_value = self._avro_serializer.deserialize( + value[DATA_START_INDEX:], schema_definition + ) + except Exception as e: # pylint:disable=broad-except + SchemaDeserializationError( + "Cannot deserialize value '{}' for schema: {}".format( + value[DATA_START_INDEX], schema_definition + ), + error=e, + ).raise_with_traceback() return dict_value diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_utils.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_utils.py deleted file mode 100644 index 6a89471e996b..000000000000 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_utils.py +++ /dev/null @@ -1,13 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- -try: - from functools import lru_cache -except ImportError: - from backports.functools_lru_cache import lru_cache -import avro - -@lru_cache(maxsize=128) -def parse_schema(schema): - return avro.schema.parse(schema) diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/aio/_schema_registry_avro_serializer_async.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/aio/_schema_registry_avro_serializer_async.py index e0e9f28e43f7..77ccf296027f 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/aio/_schema_registry_avro_serializer_async.py +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/aio/_schema_registry_avro_serializer_async.py @@ -27,8 +27,12 @@ from typing import Any, Dict, Mapping from ._async_lru import alru_cache from .._constants import SCHEMA_ID_START_INDEX, SCHEMA_ID_LENGTH, DATA_START_INDEX -from .._avro_serializer import AvroObjectSerializer -from .._utils import parse_schema +from .._apache_avro_serializer import ApacheAvroObjectSerializer as AvroObjectSerializer +from ..exceptions import ( + SchemaParseError, + SchemaSerializationError, + SchemaDeserializationError, +) class AvroSerializer(object): @@ -61,7 +65,7 @@ def __init__(self, **kwargs): ) async def __aenter__(self): - # type: () -> SchemaRegistryAvroSerializer + # type: () -> AvroSerializer await self._schema_registry_client.__aenter__() return self @@ -116,21 +120,38 @@ async def serialize(self, value, **kwargs): denoting record format identifier. The following 32 bytes denoting schema id returned by schema registry service. The remaining bytes are the real data payload. + Schema must be an Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param value: The data to be encoded. :type value: Mapping[str, Any] :keyword schema: Required. The schema used to encode the data. :paramtype schema: str :rtype: bytes + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaParseError: + Indicates an issue with parsing schema. + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaSerializationError: + Indicates an issue with serializing data for provided schema. """ try: raw_input_schema = kwargs.pop("schema") except KeyError as e: raise TypeError("'{}' is a required keyword.".format(e.args[0])) - - cached_schema = parse_schema(raw_input_schema) record_format_identifier = b"\0\0\0\0" - schema_id = await self._get_schema_id(cached_schema.fullname, str(cached_schema), **kwargs) - data_bytes = self._avro_serializer.serialize(value, cached_schema) + + try: + schema_fullname = self._avro_serializer.get_schema_fullname(raw_input_schema) + except Exception as e: # pylint:disable=broad-except + SchemaParseError("Cannot parse schema: {}".format(raw_input_schema), error=e).raise_with_traceback() + + schema_id = await self._get_schema_id(schema_fullname, raw_input_schema, **kwargs) + try: + data_bytes = self._avro_serializer.serialize(value, raw_input_schema) + except Exception as e: # pylint:disable=broad-except + SchemaSerializationError( + "Cannot serialize value '{}' for schema: {}".format(value, raw_input_schema), + error=e + ).raise_with_traceback() stream = BytesIO() @@ -148,8 +169,15 @@ async def deserialize(self, value, **kwargs): """ Decode bytes data. + Data must follow format of associated Avro RecordSchema: + https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema + :param bytes value: The bytes data needs to be decoded. :rtype: Dict[str, Any] + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaParseError: + Indicates an issue with parsing schema. + :raises ~azure.schemaregistry.serializer.avroserializer.exceptions.SchemaDeserializationError: + Indicates an issue with deserializing value. """ # record_format_identifier = data[0:4] # The first 4 bytes are retained for future record format identifier. schema_id = value[ @@ -157,7 +185,13 @@ async def deserialize(self, value, **kwargs): ].decode("utf-8") schema_definition = await self._get_schema(schema_id, **kwargs) - dict_value = self._avro_serializer.deserialize( - value[DATA_START_INDEX:], schema_definition - ) + try: + dict_value = self._avro_serializer.deserialize( + value[DATA_START_INDEX:], schema_definition + ) + except Exception as e: # pylint:disable=broad-except + SchemaDeserializationError( + "Cannot deserialize value '{}' for schema: {}".format(value[DATA_START_INDEX], schema_definition), + error=e + ).raise_with_traceback() return dict_value diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/exceptions.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/exceptions.py new file mode 100644 index 000000000000..b8b19892b1cf --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/exceptions.py @@ -0,0 +1,69 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +from azure.core.exceptions import AzureError + +class SchemaParseError(AzureError): + """Error parsing a JSON schema. + :param str message: The message object stringified as 'message' attribute + :keyword error: The original exception, if any + + :ivar str message: A stringified version of the message parameter + :ivar inner_exception: The exception passed with the 'error' kwarg + :vartype inner_exception: Exception + :ivar exc_type: The exc_type from sys.exc_info() + :ivar exc_value: The exc_value from sys.exc_info() + :ivar exc_traceback: The exc_traceback from sys.exc_info() + :ivar exc_msg: A string formatting of message parameter, exc_type and exc_value + """ + + +class SchemaSerializationError(AzureError): + """Error serializing a JSON schema. + :param str message: The message object stringified as 'message' attribute + :keyword error: The original exception, if any + + :ivar str message: A stringified version of the message parameter + :ivar inner_exception: The exception passed with the 'error' kwarg + :vartype inner_exception: Exception + :ivar exc_type: The exc_type from sys.exc_info() + :ivar exc_value: The exc_value from sys.exc_info() + :ivar exc_traceback: The exc_traceback from sys.exc_info() + :ivar exc_msg: A string formatting of message parameter, exc_type and exc_value + """ + +class SchemaDeserializationError(AzureError): + """Error deserializing a JSON schema. + :param str message: The message object stringified as 'message' attribute + :keyword error: The original exception, if any + + :ivar str message: A stringified version of the message parameter + :ivar inner_exception: The exception passed with the 'error' kwarg + :vartype inner_exception: Exception + :ivar exc_type: The exc_type from sys.exc_info() + :ivar exc_value: The exc_value from sys.exc_info() + :ivar exc_traceback: The exc_traceback from sys.exc_info() + :ivar exc_msg: A string formatting of message parameter, exc_type and exc_value + """ diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml index 13f51e4c25c6..e9a0d2f6af02 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml @@ -1,8 +1,6 @@ interactions: - request: - body: '{"type": "record", "name": "User", "namespace": "example.avro", "fields": - [{"type": "string", "name": "name"}, {"type": ["int", "null"], "name": "favorite_number"}, - {"type": ["string", "null"], "name": "favorite_color"}]}' + body: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: Accept: - application/json @@ -11,7 +9,7 @@ interactions: Connection: - keep-alive Content-Length: - - '221' + - '201' Content-Type: - application/json Serialization-Type: @@ -22,18 +20,18 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:04:59 GMT + - Tue, 26 Oct 2021 00:20:00 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: @@ -72,18 +70,18 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:05:00 GMT + - Tue, 26 Oct 2021 00:20:01 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: @@ -111,21 +109,21 @@ interactions: User-Agent: - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: GET - uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview response: body: - string: '{"type":"record","name":"User","namespace":"example.avro","fields":[{"type":"string","name":"name"},{"type":["int","null"],"name":"favorite_number"},{"type":["string","null"],"name":"favorite_color"}]}' + string: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:05:00 GMT + - Tue, 26 Oct 2021 00:20:01 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml index 6ecb68a231d0..a1153f8c27e1 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml @@ -1,8 +1,6 @@ interactions: - request: - body: '{"type": "record", "name": "User", "namespace": "example.avro", "fields": - [{"type": "string", "name": "name"}, {"type": ["int", "null"], "name": "favorite_number"}, - {"type": ["string", "null"], "name": "favorite_color"}]}' + body: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: Accept: - application/json @@ -11,7 +9,7 @@ interactions: Connection: - keep-alive Content-Length: - - '221' + - '201' Content-Type: - application/json Serialization-Type: @@ -22,18 +20,18 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:05:01 GMT + - Tue, 26 Oct 2021 00:20:02 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: @@ -72,18 +70,18 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:05:02 GMT + - Tue, 26 Oct 2021 00:20:03 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: @@ -111,21 +109,21 @@ interactions: User-Agent: - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: GET - uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview response: body: - string: '{"type":"record","name":"User","namespace":"example.avro","fields":[{"type":"string","name":"name"},{"type":["int","null"],"name":"favorite_number"},{"type":["string","null"],"name":"favorite_color"}]}' + string: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: content-type: - application/json date: - - Wed, 20 Oct 2021 19:05:02 GMT + - Tue, 26 Oct 2021 00:20:03 GMT location: - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview schema-id: - - a9619ab12fb748ab9ec800c13850107e + - 17347f81cdce4953bb1680d1f7c36eb7 schema-id-location: - - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: - '1' schema-versions-location: diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_error_schema_as_record.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_error_schema_as_record.yaml new file mode 100644 index 000000000000..830686bbbd5f --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_error_schema_as_record.yaml @@ -0,0 +1,94 @@ +interactions: +- request: + body: "{\n \"name\":\"User\",\n \"namespace\":\"example.avro.error\",\n + \ \"type\":\"error\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '167' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.error.User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"abb985fa783645a0a433660fd6d51af9"}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:05 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.error.User/versions/1?api-version=2020-09-01-preview + schema-id: + - abb985fa783645a0a433660fd6d51af9 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.error.User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","namespace":"example.avro.error","type":"error","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:05 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.error.User/versions/1?api-version=2020-09-01-preview + schema-id: + - abb985fa783645a0a433660fd6d51af9 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.error.User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_record_name.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_record_name.yaml new file mode 100644 index 000000000000..1f4d15345610 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_parse_record_name.yaml @@ -0,0 +1,185 @@ +interactions: +- request: + body: "{\n \"namespace\": \"thrownaway\",\n \"name\":\"User.avro\",\n + \ \"type\":\"record\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '166' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/User.avro?api-version=2020-09-01-preview + response: + body: + string: '{"id":"ef6ab31106cc477f8b6d238d83c90f39"}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:06 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User.avro/versions/1?api-version=2020-09-01-preview + schema-id: + - ef6ab31106cc477f8b6d238d83c90f39 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User.avro/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + response: + body: + string: '{"namespace":"thrownaway","name":"User.avro","type":"record","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:06 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User.avro/versions/1?api-version=2020-09-01-preview + schema-id: + - ef6ab31106cc477f8b6d238d83c90f39 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User.avro/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +- request: + body: "{\n \"name\":\"User\",\n \"type\":\"record\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '122' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"3f9fda41a60e4196ab1a6150976ca223"}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:07 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User/versions/1?api-version=2020-09-01-preview + schema-id: + - 3f9fda41a60e4196ab1a6150976ca223 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","type":"record","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:07 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User/versions/1?api-version=2020-09-01-preview + schema-id: + - 3f9fda41a60e4196ab1a6150976ca223 + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_primitive.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_primitive.yaml new file mode 100644 index 000000000000..98329ab58e36 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_primitive.yaml @@ -0,0 +1,50 @@ +interactions: +- request: + body: '{"type": "null"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '16' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/null?api-version=2020-09-01-preview + response: + body: + string: '{"id":"587b7a7ad9304f659e8434c2edfcf08b"}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:09 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/null/versions/1?api-version=2020-09-01-preview + schema-id: + - 587b7a7ad9304f659e8434c2edfcf08b + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/587b7a7ad9304f659e8434c2edfcf08b?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/null/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_record.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_record.yaml new file mode 100644 index 000000000000..5bb31f479c60 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer.test_serialize_record.yaml @@ -0,0 +1,96 @@ +interactions: +- request: + body: "{\n \"name\":\"User\",\n \"namespace\":\"example.avro.populatedrecord\",\n + \ \"type\":\"record\",\n \"fields\":[\n {\"name\":\"name\",\"type\":\"string\"},\n + \ {\"name\":\"age\",\"type\":\"int\"},\n {\"name\":\"married\",\"type\":\"boolean\"},\n + \ {\"name\":\"height\",\"type\":\"float\"},\n {\"name\":\"randb\",\"type\":\"bytes\"}\n + \ ]\n }" + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '405' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"fee73b56d1e64c1595c97e2573b3c1ac"}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:10 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User/versions/1?api-version=2020-09-01-preview + schema-id: + - fee73b56d1e64c1595c97e2573b3c1ac + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.populatedrecord.User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","namespace":"example.avro.populatedrecord","type":"record","fields":[{"name":"name","type":"string"},{"name":"age","type":"int"},{"name":"married","type":"boolean"},{"name":"height","type":"float"},{"name":"randb","type":"bytes"}]}' + headers: + content-type: + - application/json + date: + - Tue, 26 Oct 2021 00:20:11 GMT + location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User/versions/1?api-version=2020-09-01-preview + schema-id: + - fee73b56d1e64c1595c97e2573b3c1ac + schema-id-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + schema-version: + - '1' + schema-versions-location: + - https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.populatedrecord.User/versions?api-version=2020-09-01-preview + serialization-type: + - Avro + server: + - Microsoft-HTTPAPI/2.0 + strict-transport-security: + - max-age=31536000 + transfer-encoding: + - chunked + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml index 068d169df789..39f725c8f703 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_with_auto_register_schemas.yaml @@ -18,13 +18,13 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:03 GMT + date: Tue, 26 Oct 2021 00:20:12 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -54,13 +54,13 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:03 GMT + date: Tue, 26 Oct 2021 00:20:12 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -79,16 +79,16 @@ interactions: User-Agent: - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: GET - uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview response: body: - string: '{"type":"record","name":"User","namespace":"example.avro","fields":[{"type":"string","name":"name"},{"type":["int","null"],"name":"favorite_number"},{"type":["string","null"],"name":"favorite_color"}]}' + string: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:04 GMT + date: Tue, 26 Oct 2021 00:20:13 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -98,5 +98,5 @@ interactions: status: code: 200 message: OK - url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml index a1c8635eef54..c8f3cebd27d6 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_basic_sr_avro_serializer_without_auto_register_schemas.yaml @@ -18,13 +18,13 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:05 GMT + date: Tue, 26 Oct 2021 00:20:14 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -54,13 +54,13 @@ interactions: uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.User?api-version=2020-09-01-preview response: body: - string: '{"id":"a9619ab12fb748ab9ec800c13850107e"}' + string: '{"id":"17347f81cdce4953bb1680d1f7c36eb7"}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:06 GMT + date: Tue, 26 Oct 2021 00:20:14 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -79,16 +79,16 @@ interactions: User-Agent: - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: GET - uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview response: body: - string: '{"type":"record","name":"User","namespace":"example.avro","fields":[{"type":"string","name":"name"},{"type":["int","null"],"name":"favorite_number"},{"type":["string","null"],"name":"favorite_color"}]}' + string: '{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}' headers: content-type: application/json - date: Wed, 20 Oct 2021 19:05:06 GMT + date: Tue, 26 Oct 2021 00:20:15 GMT location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2020-09-01-preview - schema-id: a9619ab12fb748ab9ec800c13850107e - schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + schema-id: 17347f81cdce4953bb1680d1f7c36eb7 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview schema-version: '1' schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.User/versions?api-version=2020-09-01-preview serialization-type: Avro @@ -98,5 +98,5 @@ interactions: status: code: 200 message: OK - url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/a9619ab12fb748ab9ec800c13850107e?api-version=2020-09-01-preview + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/17347f81cdce4953bb1680d1f7c36eb7?api-version=2020-09-01-preview version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_error_schema_as_record.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_error_schema_as_record.yaml new file mode 100644 index 000000000000..435afecc0702 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_error_schema_as_record.yaml @@ -0,0 +1,66 @@ +interactions: +- request: + body: "{\n \"name\":\"User\",\n \"namespace\":\"example.avro.error\",\n + \ \"type\":\"error\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Content-Length: + - '167' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.error.User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"abb985fa783645a0a433660fd6d51af9"}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:15 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.error.User/versions/1?api-version=2020-09-01-preview + schema-id: abb985fa783645a0a433660fd6d51af9 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.error.User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/example.avro.error.User?api-version=2020-09-01-preview +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","namespace":"example.avro.error","type":"error","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:16 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.error.User/versions/1?api-version=2020-09-01-preview + schema-id: abb985fa783645a0a433660fd6d51af9 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.error.User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/abb985fa783645a0a433660fd6d51af9?api-version=2020-09-01-preview +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_record_name.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_record_name.yaml new file mode 100644 index 000000000000..1e7079ebf411 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_parse_record_name.yaml @@ -0,0 +1,129 @@ +interactions: +- request: + body: "{\n \"namespace\": \"thrownaway\",\n \"name\":\"User.avro\",\n + \ \"type\":\"record\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Content-Length: + - '166' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/User.avro?api-version=2020-09-01-preview + response: + body: + string: '{"id":"ef6ab31106cc477f8b6d238d83c90f39"}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:17 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User.avro/versions/1?api-version=2020-09-01-preview + schema-id: ef6ab31106cc477f8b6d238d83c90f39 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User.avro/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/User.avro?api-version=2020-09-01-preview +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + response: + body: + string: '{"namespace":"thrownaway","name":"User.avro","type":"record","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:18 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User.avro/versions/1?api-version=2020-09-01-preview + schema-id: ef6ab31106cc477f8b6d238d83c90f39 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User.avro/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/ef6ab31106cc477f8b6d238d83c90f39?api-version=2020-09-01-preview +- request: + body: "{\n \"name\":\"User\",\n \"type\":\"record\",\n \"fields\":[{\"name\":\"name\",\"type\":\"string\"}]\n + \ }" + headers: + Accept: + - application/json + Content-Length: + - '122' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"3f9fda41a60e4196ab1a6150976ca223"}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:18 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User/versions/1?api-version=2020-09-01-preview + schema-id: 3f9fda41a60e4196ab1a6150976ca223 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/User?api-version=2020-09-01-preview +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","type":"record","fields":[{"name":"name","type":"string"}]}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:19 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/User/versions/1?api-version=2020-09-01-preview + schema-id: 3f9fda41a60e4196ab1a6150976ca223 + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/3f9fda41a60e4196ab1a6150976ca223?api-version=2020-09-01-preview +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_primitive.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_primitive.yaml new file mode 100644 index 000000000000..f5eab044eb77 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_primitive.yaml @@ -0,0 +1,36 @@ +interactions: +- request: + body: '{"type": "null"}' + headers: + Accept: + - application/json + Content-Length: + - '16' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/null?api-version=2020-09-01-preview + response: + body: + string: '{"id":"587b7a7ad9304f659e8434c2edfcf08b"}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:20 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/null/versions/1?api-version=2020-09-01-preview + schema-id: 587b7a7ad9304f659e8434c2edfcf08b + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/587b7a7ad9304f659e8434c2edfcf08b?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/null/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/null?api-version=2020-09-01-preview +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_record.yaml b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_record.yaml new file mode 100644 index 000000000000..382c887b8827 --- /dev/null +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/recordings/test_avro_serializer_async.test_serialize_record.yaml @@ -0,0 +1,68 @@ +interactions: +- request: + body: "{\n \"name\":\"User\",\n \"namespace\":\"example.avro.populatedrecord\",\n + \ \"type\":\"record\",\n \"fields\":[\n {\"name\":\"name\",\"type\":\"string\"},\n + \ {\"name\":\"age\",\"type\":\"int\"},\n {\"name\":\"married\",\"type\":\"boolean\"},\n + \ {\"name\":\"height\",\"type\":\"float\"},\n {\"name\":\"randb\",\"type\":\"bytes\"}\n + \ ]\n }" + headers: + Accept: + - application/json + Content-Length: + - '405' + Content-Type: + - application/json + Serialization-Type: + - Avro + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://fake_resource.servicebus.windows.net/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User?api-version=2020-09-01-preview + response: + body: + string: '{"id":"fee73b56d1e64c1595c97e2573b3c1ac"}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:21 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User/versions/1?api-version=2020-09-01-preview + schema-id: fee73b56d1e64c1595c97e2573b3c1ac + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.populatedrecord.User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/swathip-test-schema/schemas/example.avro.populatedrecord.User?api-version=2020-09-01-preview +- request: + body: null + headers: + Accept: + - text/plain; charset=utf-8 + User-Agent: + - azsdk-python-azureschemaregistry/1.0.0b3 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://fake_resource.servicebus.windows.net/$schemagroups/getSchemaById/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + response: + body: + string: '{"name":"User","namespace":"example.avro.populatedrecord","type":"record","fields":[{"name":"name","type":"string"},{"name":"age","type":"int"},{"name":"married","type":"boolean"},{"name":"height","type":"float"},{"name":"randb","type":"bytes"}]}' + headers: + content-type: application/json + date: Tue, 26 Oct 2021 00:20:21 GMT + location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.populatedrecord.User/versions/1?api-version=2020-09-01-preview + schema-id: fee73b56d1e64c1595c97e2573b3c1ac + schema-id-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/getschemabyid/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview + schema-version: '1' + schema-versions-location: https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/swathip-test-schema/schemas/example.avro.populatedrecord.User/versions?api-version=2020-09-01-preview + serialization-type: Avro + server: Microsoft-HTTPAPI/2.0 + strict-transport-security: max-age=31536000 + transfer-encoding: chunked + status: + code: 200 + message: OK + url: https://swathip-test-eventhubs.servicebus.windows.net/$schemagroups/getSchemaById/fee73b56d1e64c1595c97e2573b3c1ac?api-version=2020-09-01-preview +version: 1 diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer.py index 03cda0b26ad0..f5b4bd63b9d4 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer.py +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer.py @@ -26,13 +26,17 @@ import functools import pytest import uuid -import avro -import avro.io +import json from io import BytesIO from azure.schemaregistry import SchemaRegistryClient from azure.schemaregistry.serializer.avroserializer import AvroSerializer -from azure.schemaregistry.serializer.avroserializer._avro_serializer import AvroObjectSerializer +from azure.schemaregistry.serializer.avroserializer.exceptions import SchemaParseError, SchemaSerializationError, SchemaDeserializationError + +import avro +from avro.io import AvroTypeException +from azure.schemaregistry.serializer.avroserializer._apache_avro_serializer import ApacheAvroObjectSerializer as AvroObjectSerializer + from azure.identity import ClientSecretCredential from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError, HttpResponseError @@ -50,18 +54,18 @@ def test_raw_avro_serializer(self): raw_avro_object_serializer = AvroObjectSerializer() # encoding part - encoded_payload = raw_avro_object_serializer.serialize(dict_data, schema) + encoded_payload = raw_avro_object_serializer.serialize(dict_data, schema_str) # decoding part - decoded_data = raw_avro_object_serializer.deserialize(encoded_payload, schema) + decoded_data = raw_avro_object_serializer.deserialize(encoded_payload, schema_str) assert decoded_data["name"] == u"Ben" assert decoded_data["favorite_number"] == 7 assert decoded_data["favorite_color"] == u"red" dict_data_missing_optional_fields = {"name": u"Alice"} - encoded_payload = raw_avro_object_serializer.serialize(dict_data_missing_optional_fields, schema) - decoded_data = raw_avro_object_serializer.deserialize(encoded_payload, schema) + encoded_payload = raw_avro_object_serializer.serialize(dict_data_missing_optional_fields, schema_str) + decoded_data = raw_avro_object_serializer.deserialize(encoded_payload, schema_str) assert decoded_data["name"] == u"Alice" assert not decoded_data["favorite_number"] @@ -73,12 +77,12 @@ def test_raw_avro_serializer_negative(self): raw_avro_object_serializer = AvroObjectSerializer() dict_data_wrong_type = {"name": u"Ben", "favorite_number": u"something", "favorite_color": u"red"} - with pytest.raises(avro.io.AvroTypeException): - raw_avro_object_serializer.serialize(dict_data_wrong_type, schema) + with pytest.raises(AvroTypeException): # avro.io.AvroTypeException + raw_avro_object_serializer.serialize(dict_data_wrong_type, schema_str) dict_data_missing_required_field = {"favorite_number": 7, "favorite_color": u"red"} - with pytest.raises(avro.io.AvroTypeException): - raw_avro_object_serializer.serialize(dict_data_missing_required_field, schema) + with pytest.raises(AvroTypeException): # avro.io.AvroTypeException + raw_avro_object_serializer.serialize(dict_data_missing_required_field, schema_str) @SchemaRegistryPowerShellPreparer() def test_basic_sr_avro_serializer_with_auto_register_schemas(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): @@ -123,3 +127,302 @@ def test_basic_sr_avro_serializer_without_auto_register_schemas(self, schemaregi assert decoded_data["favorite_color"] == u"red" sr_avro_serializer.close() + + + ################################################################# + ######################### PARSE SCHEMAS ######################### + ################################################################# + + @SchemaRegistryPowerShellPreparer() + def test_parse_invalid_json_string(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + invalid_schema = { + "name":"User", + "type":"record", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + } + invalid_schema_string = "{}".format(invalid_schema) + with pytest.raises(SchemaParseError): # caught avro SchemaParseError + sr_avro_serializer.serialize({"name": u"Ben"}, schema=invalid_schema_string) + + ######################### PRIMITIVES ######################### + + @SchemaRegistryPowerShellPreparer() + def test_parse_primitive_types(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + primitive_string = "string" + with pytest.raises(SchemaParseError) as e: + sr_avro_serializer.serialize("hello", schema=primitive_string) + + ######################### type fixed ######################### + + @SchemaRegistryPowerShellPreparer() + def test_parse_fixed_types(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + # avro bug: should give warning from IgnoredLogicalType error since precision < 0 + #fixed_type_ignore_logical_type_error = """{"type": "fixed", "size": 4, "namespace":"example.avro", "name":"User", "precision": -1}""" + #sr_avro_serializer.serialize({}, schema=fixed_type_ignore_logical_type_error) + + schema_no_size = """{"type": "fixed", "name":"User"}""" + with pytest.raises(SchemaParseError): # caught AvroException + sr_avro_serializer.serialize({}, schema=schema_no_size) + + schema_no_name = """{"type": "fixed", "size": 3}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + sr_avro_serializer.serialize({}, schema=schema_no_name) + + schema_wrong_name = """{"type": "fixed", "name": 1, "size": 3}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + sr_avro_serializer.serialize({}, schema=schema_wrong_name) + + schema_wrong_namespace = """{"type": "fixed", "name": "User", "size": 3, "namespace": 1}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + sr_avro_serializer.serialize({}, schema=schema_wrong_namespace) + + ######################### type unspecified ######################### + + @SchemaRegistryPowerShellPreparer() + def test_parse_invalid_type(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_no_type = """{ + "name": "User", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): # caught avro SchemaParseError + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_type) + + schema_wrong_type_type = """{ + "name":"User", + "type":1, + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_type) + + ######################### RECORD SCHEMA ######################### + + @SchemaRegistryPowerShellPreparer() + def test_parse_record_name(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_name_has_dot = """{ + "namespace": "thrownaway", + "name":"User.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_schema = sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_name_has_dot) + schema_id = encoded_schema[4:36].decode("utf-8") + registered_schema = sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + + # ensure that namespace is saved as part of name before . in registered schema + assert decoded_registered_schema["name"] == "User.avro" + assert decoded_registered_schema["namespace"] == "thrownaway" + + schema_name_no_namespace = """{ + "name":"User", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_schema = sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_name_no_namespace) + schema_id = encoded_schema[4:36].decode("utf-8") + registered_schema = sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + + assert decoded_registered_schema["name"] == "User" + assert "namespace" not in decoded_registered_schema + + schema_invalid_fullname = """{ + "name":"abc", + "type":"record", + "namespace":"9example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_fullname) + + schema_invalid_name_in_fullname = """{ + "name":"1abc", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_name_in_fullname) + + schema_invalid_name_reserved_type = """{ + "name":"record", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_name_reserved_type) + + schema_wrong_type_name = """{ + "name":1, + "type":"record", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_name) + + schema_no_name = """{ + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_name) + + @SchemaRegistryPowerShellPreparer() + def test_parse_error_schema_as_record(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_error_type = """{ + "name":"User", + "namespace":"example.avro.error", + "type":"error", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_data = sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_error_type) + schema_id = encoded_data[4:36].decode("utf-8") + registered_schema = sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + assert decoded_registered_schema["type"] == "error" + + @SchemaRegistryPowerShellPreparer() + def test_parse_record_fields(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_no_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_fields) + + schema_wrong_type_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + "fields": "hello" + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_fields) + + schema_wrong_field_item_type = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + "fields": ["hello"] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_field_item_type) + + schema_record_field_no_name= """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_no_name) + + schema_record_field_wrong_type_name= """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name": 1, "type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_wrong_type_name) + + schema_record_field_with_invalid_order = """{ + "name":"User", + "namespace":"example.avro.order", + "type":"record", + "fields":[{"name":"name","type":"string","order":"fake_order"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_with_invalid_order) + + schema_record_duplicate_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}, {"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_duplicate_fields) + + schema_field_type_invalid = """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":1}] + }""" + with pytest.raises(SchemaParseError): + sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_field_type_invalid) + + ################################################################# + #################### SERIALIZE AND DESERIALIZE ################## + ################################################################# + + @SchemaRegistryPowerShellPreparer() + def test_serialize_primitive(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + null_type = """{"type": "null"}""" + encoded_data = sr_avro_serializer.serialize(None, schema=null_type) + assert len(encoded_data) == 36 # assert no data encoded + + @SchemaRegistryPowerShellPreparer() + def test_serialize_record(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_basic_client(SchemaRegistryClient, fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + # add below to schema fields later if needed + # {"name":"example.innerrec","type":"record","fields":[{"name":"a","type":"int"}]}, + # {"name":"innerenum","type":"enum","symbols":["FOO", "BAR"]}, + # {"name":"innerarray","type":"array","items":"int"}, + # {"name":"innermap","type":"map","values":"int"}, + # {"name":"innerfixed","type":"fixed","size":74} + schema_record = """{ + "name":"User", + "namespace":"example.avro.populatedrecord", + "type":"record", + "fields":[ + {"name":"name","type":"string"}, + {"name":"age","type":"int"}, + {"name":"married","type":"boolean"}, + {"name":"height","type":"float"}, + {"name":"randb","type":"bytes"} + ] + }""" + data = { + "name": u"Ben", + "age": 3, + "married": False, + "height": 13.5, + "randb": b"\u00FF" + } + + encoded_data = sr_avro_serializer.serialize(data, schema=schema_record) + decoded_data = sr_avro_serializer.deserialize(encoded_data) + assert decoded_data == data diff --git a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer_async.py b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer_async.py index b06e1363b46c..13e7026b2c7e 100644 --- a/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer_async.py +++ b/sdk/schemaregistry/azure-schemaregistry-avroserializer/tests/test_avro_serializer_async.py @@ -26,13 +26,16 @@ import functools import pytest import uuid -import avro -import avro.io +import json from io import BytesIO import pytest +import avro +from avro.io import AvroTypeException + from azure.schemaregistry.aio import SchemaRegistryClient from azure.schemaregistry.serializer.avroserializer.aio import AvroSerializer +from azure.schemaregistry.serializer.avroserializer.exceptions import SchemaParseError, SchemaSerializationError, SchemaDeserializationError from azure.identity.aio import ClientSecretCredential from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError, HttpResponseError @@ -93,3 +96,300 @@ async def test_basic_sr_avro_serializer_without_auto_register_schemas(self, sche assert decoded_data["name"] == u"Ben" assert decoded_data["favorite_number"] == 7 assert decoded_data["favorite_color"] == u"red" + + ################################################################# + ######################### PARSE SCHEMAS ######################### + ################################################################# + + @SchemaRegistryPowerShellPreparer() + async def test_parse_invalid_json_string(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + invalid_schema = { + "name":"User", + "type":"record", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + } + invalid_schema_string = "{}".format(invalid_schema) + with pytest.raises(SchemaParseError): # caught avro SchemaParseError + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=invalid_schema_string) + + ######################### PRIMITIVES ######################### + + @SchemaRegistryPowerShellPreparer() + async def test_parse_primitive_types(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + primitive_string = "string" + with pytest.raises(SchemaParseError) as e: + await sr_avro_serializer.serialize("hello", schema=primitive_string) + + ######################### type fixed ######################### + + @SchemaRegistryPowerShellPreparer() + async def test_parse_fixed_types(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + # avro bug: should give warning from IgnoredLogicalType error since precision < 0 + #fixed_type_ignore_logical_type_error = """{"type": "fixed", "size": 4, "namespace":"example.avro", "name":"User", "precision": -1}""" + #await sr_avro_serializer.serialize({}, schema=fixed_type_ignore_logical_type_error) + + schema_no_size = """{"type": "fixed", "name":"User"}""" + with pytest.raises(SchemaParseError): # caught AvroException + await sr_avro_serializer.serialize({}, schema=schema_no_size) + + schema_no_name = """{"type": "fixed", "size": 3}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + await sr_avro_serializer.serialize({}, schema=schema_no_name) + + schema_wrong_name = """{"type": "fixed", "name": 1, "size": 3}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + await sr_avro_serializer.serialize({}, schema=schema_wrong_name) + + schema_wrong_namespace = """{"type": "fixed", "name": "User", "size": 3, "namespace": 1}""" + with pytest.raises(SchemaParseError): # caught SchemaParseError + await sr_avro_serializer.serialize({}, schema=schema_wrong_namespace) + + ######################### type unspecified ######################### + + @SchemaRegistryPowerShellPreparer() + async def test_parse_invalid_type(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_no_type = """{ + "name": "User", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): # caught avro SchemaParseError + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_type) + + schema_wrong_type_type = """{ + "name":"User", + "type":1, + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_type) + + ######################### RECORD SCHEMA ######################### + + @SchemaRegistryPowerShellPreparer() + async def test_parse_record_name(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_name_has_dot = """{ + "namespace": "thrownaway", + "name":"User.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_schema = await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_name_has_dot) + schema_id = encoded_schema[4:36].decode("utf-8") + registered_schema = await sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + + assert decoded_registered_schema["name"] == "User.avro" + assert decoded_registered_schema["namespace"] == "thrownaway" + + schema_name_no_namespace = """{ + "name":"User", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_schema = await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_name_no_namespace) + schema_id = encoded_schema[4:36].decode("utf-8") + registered_schema = await sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + + assert decoded_registered_schema["name"] == "User" + assert "namespace" not in decoded_registered_schema + + schema_invalid_fullname = """{ + "name":"abc", + "type":"record", + "namespace":"9example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_fullname) + + schema_invalid_name_in_fullname = """{ + "name":"1abc", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_name_in_fullname) + + schema_invalid_name_reserved_type = """{ + "name":"record", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_invalid_name_reserved_type) + + schema_wrong_type_name = """{ + "name":1, + "type":"record", + "namespace":"example.avro", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_name) + + schema_no_name = """{ + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_name) + + @SchemaRegistryPowerShellPreparer() + async def test_parse_error_schema_as_record(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_error_type = """{ + "name":"User", + "namespace":"example.avro.error", + "type":"error", + "fields":[{"name":"name","type":"string"}] + }""" + encoded_data = await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_error_type) + schema_id = encoded_data[4:36].decode("utf-8") + registered_schema = await sr_client.get_schema(schema_id) + decoded_registered_schema = json.loads(registered_schema.schema_definition) + assert decoded_registered_schema["type"] == "error" + + @SchemaRegistryPowerShellPreparer() + async def test_parse_record_fields(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + schema_no_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_no_fields) + + schema_wrong_type_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + "fields": "hello" + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_type_fields) + + schema_wrong_field_item_type = """{ + "name":"User", + "namespace":"example.avro", + "type":"record" + "fields": ["hello"] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_wrong_field_item_type) + + schema_record_field_no_name= """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_no_name) + + schema_record_field_wrong_type_name= """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name": 1, "type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_wrong_type_name) + + schema_record_field_with_invalid_order = """{ + "name":"User", + "namespace":"example.avro.order", + "type":"record", + "fields":[{"name":"name","type":"string","order":"fake_order"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_field_with_invalid_order) + + schema_record_duplicate_fields = """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":"string"}, {"name":"name","type":"string"}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_record_duplicate_fields) + + schema_field_type_invalid = """{ + "name":"User", + "namespace":"example.avro", + "type":"record", + "fields":[{"name":"name","type":1}] + }""" + with pytest.raises(SchemaParseError): + await sr_avro_serializer.serialize({"name": u"Ben"}, schema=schema_field_type_invalid) + + ################################################################# + #################### SERIALIZE AND DESERIALIZE ################## + ################################################################# + + @SchemaRegistryPowerShellPreparer() + async def test_serialize_primitive(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + null_type = """{"type": "null"}""" + encoded_data = await sr_avro_serializer.serialize(None, schema=null_type) + assert len(encoded_data) == 36 # assert no data encoded + + @SchemaRegistryPowerShellPreparer() + async def test_serialize_record(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs): + sr_client = self.create_client(fully_qualified_namespace=schemaregistry_fully_qualified_namespace) + sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True) + + # add below to schema later if possible + # {"name":"example.innerrec","type":"record","fields":[{"name":"a","type":"int"}]}, + # {"name":"innerenum","type":"enum","symbols":["FOO", "BAR"]}, + # {"name":"innerarray","type":"array","items":"int"}, + # {"name":"innermap","type":"map","values":"int"}, + # {"name":"innerfixed","type":"fixed","size":74} + schema_record = """{ + "name":"User", + "namespace":"example.avro.populatedrecord", + "type":"record", + "fields":[ + {"name":"name","type":"string"}, + {"name":"age","type":"int"}, + {"name":"married","type":"boolean"}, + {"name":"height","type":"float"}, + {"name":"randb","type":"bytes"} + ] + }""" + data = { + "name": u"Ben", + "age": 3, + "married": False, + "height": 13.5, + "randb": b"\u00FF" + } + + encoded_data = await sr_avro_serializer.serialize(data, schema=schema_record) + decoded_data = await sr_avro_serializer.deserialize(encoded_data) + assert decoded_data == data