From 48cb91cac7309fb07b428561bbd6f41ea32a86c5 Mon Sep 17 00:00:00 2001 From: Connie Yau Date: Mon, 14 Mar 2022 19:01:57 -0700 Subject: [PATCH] Schema Registry: Change Encoder to Serializer (#27662) * Adding explicit dependency on azure-core. * Updating class name from Encoder -> Serializer. * Rename encode/decode to deserialize/serialize. * Rename playback files. * Fix README file snippets. * Fix CHANGELOG entries. --- .../CHANGELOG.md | 6 +- .../README.md | 16 ++-- .../pom.xml | 5 ++ ...> SchemaRegistryApacheAvroSerializer.java} | 76 +++++++++---------- ...aRegistryApacheAvroSerializerBuilder.java} | 32 ++++---- .../src/samples/README.md | 2 +- .../apacheavro/ReadmeSamples.java | 36 ++++----- ...maRegistryApacheAvroSerializerSample.java} | 10 +-- ...hemaRegistryAvroDeserializationSample.java | 6 +- ...yApacheAvroSerializerIntegrationTest.java} | 10 +-- ...hemaRegistryApacheAvroSerializerTest.java} | 70 ++++++++--------- ...IntegrationTest.registerAndGetSchema.json} | 0 ...erTest.serializeForwardCompatibility.json} | 0 ...roSerializerTest.serializeFromPortal.json} | 0 14 files changed, 139 insertions(+), 130 deletions(-) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/{SchemaRegistryApacheAvroEncoder.java => SchemaRegistryApacheAvroSerializer.java} (85%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/{SchemaRegistryApacheAvroEncoderBuilder.java => SchemaRegistryApacheAvroSerializerBuilder.java} (80%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/{SchemaRegistryApacheAvroEncoderSample.java => SchemaRegistryApacheAvroSerializerSample.java} (82%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/{SchemaRegistryApacheAvroEncoderIntegrationTest.java => SchemaRegistryApacheAvroSerializerIntegrationTest.java} (93%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/{SchemaRegistryApacheAvroEncoderTest.java => SchemaRegistryApacheAvroSerializerTest.java} (87%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/{SchemaRegistryApacheAvroEncoderIntegrationTest.registerAndGetSchema.json => SchemaRegistryApacheAvroSerializerIntegrationTest.registerAndGetSchema.json} (100%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/{SchemaRegistryApacheAvroEncoderTest.serializeForwardCompatibility.json => SchemaRegistryApacheAvroSerializerTest.serializeForwardCompatibility.json} (100%) rename sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/{SchemaRegistryApacheAvroEncoderTest.serializeFromPortal.json => SchemaRegistryApacheAvroSerializerTest.serializeFromPortal.json} (100%) diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/CHANGELOG.md b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/CHANGELOG.md index 583d2f24d077f..5f5b5f6a34313 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/CHANGELOG.md +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/CHANGELOG.md @@ -6,6 +6,10 @@ ### Breaking Changes +- Changed `SchemaRegistryApacheAvroEncoder` to `SchemaRegistryApacheAvroSerializer`. +- Changed `decodeMessageData` and `decodeMessageDataAsync` to `deserializeMessageData` and `deserializeMessageDataAsync`. +- Changed `encodeMessageData` and `encodeMessageDataAsync` to `serializeMessageData` and `serializeMessageDataAsync`. + ### Bugs Fixed ### Other Changes @@ -14,7 +18,7 @@ ### Features Added -- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageWithMetadata` rather than tied to a binary format +- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageWithMetadata` rather than tied to a binary format with preamble. Backwards compatibility with preamble format supported for this release. See issue #26449. ### Breaking Changes diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md index 15e55cb3f7804..8923abdd48ef5 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md @@ -72,11 +72,11 @@ SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBu #### Create `SchemaRegistryAvroSerializer` through the builder -```java readme-sample-createSchemaRegistryAvroEncoder -SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() +```java readme-sample-createSchemaRegistryAvroSerializer +SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder() .schemaRegistryAsyncClient(schemaRegistryAsyncClient) .schemaGroup("{schema-group}") - .buildEncoder(); + .buildSerializer(); ``` ## Key concepts @@ -105,13 +105,13 @@ The serializer in this library creates messages in a wire format. The format is ### Serialize Serialize a strongly-typed object into Schema Registry-compatible avro payload. -```java readme-sample-encodeSample +```java readme-sample-serializeSample PlayingCard playingCard = new PlayingCard(); playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES); playingCard.setIsFaceCard(false); playingCard.setCardValue(5); -MessageWithMetadata message = encoder.encodeMessageData(playingCard, +MessageWithMetadata message = serializer.serializeMessageData(playingCard, TypeReference.createInstance(MessageWithMetadata.class)); ``` @@ -121,10 +121,10 @@ The avro type `PlayingCard` is available in samples package ### Deserialize Deserialize a Schema Registry-compatible avro payload into a strongly-type object. -```java readme-sample-decodeSample -SchemaRegistryApacheAvroEncoder encoder = createAvroSchemaRegistryEncoder(); +```java readme-sample-deserializeSample +SchemaRegistryApacheAvroSerializer serializer = createAvroSchemaRegistrySerializer(); MessageWithMetadata message = getSchemaRegistryAvroMessage(); -PlayingCard playingCard = encoder.decodeMessageData(message, TypeReference.createInstance(PlayingCard.class)); +PlayingCard playingCard = serializer.deserializeMessageData(message, TypeReference.createInstance(PlayingCard.class)); ``` ## Troubleshooting diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/pom.xml b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/pom.xml index 4a8d72e34bc09..1576b19cd33dd 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/pom.xml +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/pom.xml @@ -44,6 +44,11 @@ + + com.azure + azure-core + 1.26.0 + com.azure azure-core-experimental diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoder.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializer.java similarity index 85% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoder.java rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializer.java index d5bb9f1f4049e..65606cdbf7468 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializer.java @@ -28,13 +28,13 @@ /** * Schema Registry-based serializer implementation for Avro data format using Apache Avro. */ -public final class SchemaRegistryApacheAvroEncoder { +public final class SchemaRegistryApacheAvroSerializer { static final String AVRO_MIME_TYPE = "avro/binary"; static final byte[] RECORD_FORMAT_INDICATOR = new byte[]{0x00, 0x00, 0x00, 0x00}; static final int RECORD_FORMAT_INDICATOR_SIZE = RECORD_FORMAT_INDICATOR.length; static final int SCHEMA_ID_SIZE = 32; - private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroEncoder.class); + private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroSerializer.class); private final SchemaRegistryAsyncClient schemaRegistryClient; private final AvroSerializer avroSerializer; private final SerializerOptions serializerOptions; @@ -46,7 +46,7 @@ public final class SchemaRegistryApacheAvroEncoder { * @param avroSerializer Serializer implemented using Apache Avro. * @param serializerOptions Options to configure the serializer with. */ - SchemaRegistryApacheAvroEncoder(SchemaRegistryAsyncClient schemaRegistryClient, + SchemaRegistryApacheAvroSerializer(SchemaRegistryAsyncClient schemaRegistryClient, AvroSerializer avroSerializer, SerializerOptions serializerOptions) { this.schemaRegistryClient = Objects.requireNonNull(schemaRegistryClient, "'schemaRegistryClient' cannot be null."); @@ -56,84 +56,84 @@ public final class SchemaRegistryApacheAvroEncoder { } /** - * Encodes an object into a message. + * Serializes an object into a message. * - * @param object Object to encode. + * @param object Object to serialize. * @param typeReference Type of message to create. * @param Concrete type of {@link MessageWithMetadata}. * - * @return The message encoded or {@code null} if the message could not be encoded. + * @return The message encoded or {@code null} if the message could not be serialized. * * @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no - * argument constructor. Or if the schema could not ve fetched from {@code T}. + * argument constructor. Or if the schema could not be fetched from {@code T}. * @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem * encoding the object. * @throws NullPointerException if the {@code object} is null or {@code typeReference} is null. */ - public T encodeMessageData(Object object, TypeReference typeReference) { - return encodeMessageDataAsync(object, typeReference).block(); + public T serializeMessageData(Object object, TypeReference typeReference) { + return serializeMessageDataAsync(object, typeReference).block(); } /** - * Encodes an object into a message. + * Serializes an object into a message. * - * @param object Object to encode. + * @param object Object to serialize. * @param typeReference Type of message to create. * @param messageFactory Factory to create an instance given the serialized Avro. * @param Concrete type of {@link MessageWithMetadata}. * - * @return The message encoded or {@code null} if the message could not be encoded. + * @return The message encoded or {@code null} if the message could not be serialized. * * @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no - * argument constructor. Or if the schema could not ve fetched from {@code T}. + * argument constructor. Or if the schema could not be fetched from {@code T}. * @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem * encoding the object. * @throws NullPointerException if the {@code object} is null or {@code typeReference} is null. */ - public T encodeMessageData(Object object, TypeReference typeReference, + public T serializeMessageData(Object object, TypeReference typeReference, Function messageFactory) { - return encodeMessageDataAsync(object, typeReference, messageFactory).block(); + return serializeMessageDataAsync(object, typeReference, messageFactory).block(); } /** - * Encodes an object into a message. + * Serializes an object into a message. * - * @param object Object to encode. + * @param object Object to serialize. * @param typeReference Type of message to create. * @param Concrete type of {@link MessageWithMetadata}. * - * @return A Mono that completes with the encoded message. + * @return A Mono that completes with the serialized message. * * @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no - * argument constructor. Or if the schema could not ve fetched from {@code T}. + * argument constructor. Or if the schema could not be fetched from {@code T}. * @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem * encoding the object. * @throws NullPointerException if the {@code object} is null or {@code typeReference} is null. */ - public Mono encodeMessageDataAsync(Object object, + public Mono serializeMessageDataAsync(Object object, TypeReference typeReference) { - return encodeMessageDataAsync(object, typeReference, null); + return serializeMessageDataAsync(object, typeReference, null); } /** - * Encodes an object into a message. + * Serializes an object into a message. * - * @param object Object to encode. + * @param object Object to serialize. * @param typeReference Type of message to create. * @param messageFactory Factory to create an instance given the serialized Avro. If null is passed in, then the * no argument constructor will be used. * @param Concrete type of {@link MessageWithMetadata}. * - * @return A Mono that completes with the encoded message. + * @return A Mono that completes with the serialized message. * * @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no - * argument constructor. Or if the schema could not ve fetched from {@code T}. + * argument constructor. Or if the schema could not be fetched from {@code T}. * @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem * encoding the object. * @throws NullPointerException if the {@code object} is null or {@code typeReference} is null. */ - public Mono encodeMessageDataAsync(Object object, + public Mono serializeMessageDataAsync(Object object, TypeReference typeReference, Function messageFactory) { if (object == null) { @@ -189,25 +189,25 @@ public Mono encodeMessageDataAsync(Object obj } /** - * Decodes a message into its object. + * Deserializes a message into its object. * - * @param message Object to encode. - * @param typeReference Message to encode to. + * @param message Object to deserialize. + * @param typeReference Message type to deserialize to. * @param Concrete type of {@link MessageWithMetadata}. * - * @return The message encoded. + * @return The message deserialized. * * @throws NullPointerException if {@code message} or {@code typeReference} is null. */ - public T decodeMessageData(MessageWithMetadata message, TypeReference typeReference) { - return decodeMessageDataAsync(message, typeReference).block(); + public T deserializeMessageData(MessageWithMetadata message, TypeReference typeReference) { + return deserializeMessageDataAsync(message, typeReference).block(); } /** - * Decodes a message into its object. + * Deserializes a message into its object. * - * @param message Object to encode. - * @param typeReference Message to encode to. + * @param message Object to deserialize. + * @param typeReference Message to deserialize to. * @param Concrete type of {@link MessageWithMetadata}. * * @return A Mono that completes when the message encoded. If {@code message.getBodyAsBinaryData()} is null or @@ -215,7 +215,7 @@ public T decodeMessageData(MessageWithMetadata message, TypeReference typ * * @throws NullPointerException if {@code message} or {@code typeReference} is null. */ - public Mono decodeMessageDataAsync(MessageWithMetadata message, TypeReference typeReference) { + public Mono deserializeMessageDataAsync(MessageWithMetadata message, TypeReference typeReference) { if (message == null) { return monoError(logger, new NullPointerException("'message' cannot be null.")); } else if (typeReference == null) { @@ -282,10 +282,10 @@ public Mono decodeMessageDataAsync(MessageWithMetadata message, TypeRefer contents.reset(); } - return decodeMessageDataAsync(schemaId, contents, typeReference); + return deserializeMessageDataAsync(schemaId, contents, typeReference); } - private Mono decodeMessageDataAsync(String schemaId, ByteBuffer buffer, TypeReference typeReference) { + private Mono deserializeMessageDataAsync(String schemaId, ByteBuffer buffer, TypeReference typeReference) { return this.schemaRegistryClient.getSchema(schemaId) .handle((registryObject, sink) -> { final byte[] payloadSchema = registryObject.getDefinition().getBytes(StandardCharsets.UTF_8); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerBuilder.java similarity index 80% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderBuilder.java rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerBuilder.java index 8886719469981..1b3114adf3d84 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/main/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerBuilder.java @@ -15,15 +15,15 @@ import java.util.Objects; /** - * The builder implementation for building {@link SchemaRegistryApacheAvroEncoder}. + * The builder implementation for building {@link SchemaRegistryApacheAvroSerializer}. * - * @see SchemaRegistryApacheAvroEncoder + * @see SchemaRegistryApacheAvroSerializer */ -public final class SchemaRegistryApacheAvroEncoderBuilder { +public final class SchemaRegistryApacheAvroSerializerBuilder { private static final boolean AVRO_SPECIFIC_READER_DEFAULT = false; private static final int MAX_CACHE_SIZE = 128; - private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroEncoderBuilder.class); + private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroSerializerBuilder.class); private Boolean autoRegisterSchemas; private Boolean avroSpecificReader; private SchemaRegistryAsyncClient schemaRegistryAsyncClient; @@ -32,7 +32,7 @@ public final class SchemaRegistryApacheAvroEncoderBuilder { /** * Instantiates instance of Builder class. Supplies client defaults. */ - public SchemaRegistryApacheAvroEncoderBuilder() { + public SchemaRegistryApacheAvroSerializerBuilder() { this.autoRegisterSchemas = false; this.avroSpecificReader = false; } @@ -46,9 +46,9 @@ public SchemaRegistryApacheAvroEncoderBuilder() { * * @param schemaGroup Azure Schema Registry schema group * - * @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance + * @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance */ - public SchemaRegistryApacheAvroEncoderBuilder schemaGroup(String schemaGroup) { + public SchemaRegistryApacheAvroSerializerBuilder schemaGroup(String schemaGroup) { this.schemaGroup = schemaGroup; return this; } @@ -64,9 +64,9 @@ public SchemaRegistryApacheAvroEncoderBuilder schemaGroup(String schemaGroup) { * * @param autoRegisterSchemas flag for schema auto-registration * - * @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance + * @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance */ - public SchemaRegistryApacheAvroEncoderBuilder autoRegisterSchema(boolean autoRegisterSchemas) { + public SchemaRegistryApacheAvroSerializerBuilder autoRegisterSchema(boolean autoRegisterSchemas) { this.autoRegisterSchemas = autoRegisterSchemas; return this; } @@ -78,9 +78,9 @@ public SchemaRegistryApacheAvroEncoderBuilder autoRegisterSchema(boolean autoReg * @param avroSpecificReader {@code true} to deserialize into {@link SpecificRecord} via {@link * SpecificDatumReader}; {@code false} otherwise. * - * @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance. + * @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance. */ - public SchemaRegistryApacheAvroEncoderBuilder avroSpecificReader(boolean avroSpecificReader) { + public SchemaRegistryApacheAvroSerializerBuilder avroSpecificReader(boolean avroSpecificReader) { this.avroSpecificReader = avroSpecificReader; return this; } @@ -90,9 +90,9 @@ public SchemaRegistryApacheAvroEncoderBuilder avroSpecificReader(boolean avroSpe * * @param schemaRegistryAsyncClient The {@link SchemaRegistryAsyncClient}. * - * @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance. + * @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance. */ - public SchemaRegistryApacheAvroEncoderBuilder schemaRegistryAsyncClient( + public SchemaRegistryApacheAvroSerializerBuilder schemaRegistryAsyncClient( SchemaRegistryAsyncClient schemaRegistryAsyncClient) { this.schemaRegistryAsyncClient = schemaRegistryAsyncClient; return this; @@ -101,13 +101,13 @@ public SchemaRegistryApacheAvroEncoderBuilder schemaRegistryAsyncClient( /** * Creates a new instance of Schema Registry serializer. * - * @return A new instance of {@link SchemaRegistryApacheAvroEncoder}. + * @return A new instance of {@link SchemaRegistryApacheAvroSerializer}. * * @throws NullPointerException if {@link #schemaRegistryAsyncClient(SchemaRegistryAsyncClient)} is {@code null} * @throws IllegalStateException if {@link #autoRegisterSchema(boolean)} is {@code true} but {@link * #schemaGroup(String) schemaGroup} is {@code null}. */ - public SchemaRegistryApacheAvroEncoder buildEncoder() { + public SchemaRegistryApacheAvroSerializer buildSerializer() { final boolean isAutoRegister = autoRegisterSchemas != null && autoRegisterSchemas; if (Objects.isNull(schemaRegistryAsyncClient)) { @@ -126,6 +126,6 @@ public SchemaRegistryApacheAvroEncoder buildEncoder() { EncoderFactory.get(), DecoderFactory.get()); final SerializerOptions options = new SerializerOptions(schemaGroup, isAutoRegister, MAX_CACHE_SIZE); - return new SchemaRegistryApacheAvroEncoder(schemaRegistryAsyncClient, codec, options); + return new SchemaRegistryApacheAvroSerializer(schemaRegistryAsyncClient, codec, options); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/README.md b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/README.md index fe8c37a9f7998..cf8e66173e4b9 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/README.md +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/README.md @@ -40,7 +40,7 @@ This project welcomes contributions and suggestions. See [Contributing][sdk_read [sdk_readme_troubleshooting]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#troubleshooting [sdk_readme_next_steps]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#next-steps [sdk_readme_contributing]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#contributing -[sample_avro_serialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderSample.java +[sample_avro_serialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerSample.java [sample_avro_deserialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%schemaregistry%2Fazure-data-schemaregistry-apacheavro%2Fsrc%2Fsamples%2README.png) diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/ReadmeSamples.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/ReadmeSamples.java index eb685bb70f700..2944d58c1f855 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/ReadmeSamples.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/ReadmeSamples.java @@ -19,10 +19,10 @@ public class ReadmeSamples { /** - * Sample to demonstrate creation of {@link SchemaRegistryApacheAvroEncoder}. - * @return The {@link SchemaRegistryApacheAvroEncoder}. + * Sample to demonstrate creation of {@link SchemaRegistryApacheAvroSerializer}. + * @return The {@link SchemaRegistryApacheAvroSerializer}. */ - public SchemaRegistryApacheAvroEncoder createAvroSchemaRegistryEncoder() { + public SchemaRegistryApacheAvroSerializer createAvroSchemaRegistrySerializer() { // BEGIN: readme-sample-createSchemaRegistryAsyncClient TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); @@ -34,42 +34,42 @@ public SchemaRegistryApacheAvroEncoder createAvroSchemaRegistryEncoder() { .buildAsyncClient(); // END: readme-sample-createSchemaRegistryAsyncClient - // BEGIN: readme-sample-createSchemaRegistryAvroEncoder - SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + // BEGIN: readme-sample-createSchemaRegistryAvroSerializer + SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder() .schemaRegistryAsyncClient(schemaRegistryAsyncClient) .schemaGroup("{schema-group}") - .buildEncoder(); - // END: readme-sample-createSchemaRegistryAvroEncoder + .buildSerializer(); + // END: readme-sample-createSchemaRegistryAvroSerializer - return encoder; + return serializer; } /** * Encode a strongly-typed object into avro payload compatible with schema registry. */ - public void encodeSample() { - SchemaRegistryApacheAvroEncoder encoder = createAvroSchemaRegistryEncoder(); + public void serializeSample() { + SchemaRegistryApacheAvroSerializer serializer = createAvroSchemaRegistrySerializer(); - // BEGIN: readme-sample-encodeSample + // BEGIN: readme-sample-serializeSample PlayingCard playingCard = new PlayingCard(); playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES); playingCard.setIsFaceCard(false); playingCard.setCardValue(5); - MessageWithMetadata message = encoder.encodeMessageData(playingCard, + MessageWithMetadata message = serializer.serializeMessageData(playingCard, TypeReference.createInstance(MessageWithMetadata.class)); - // END: readme-sample-encodeSample + // END: readme-sample-serializeSample } /** * Decode avro payload compatible with schema registry into a strongly-type object. */ - public void decodeSample() { - // BEGIN: readme-sample-decodeSample - SchemaRegistryApacheAvroEncoder encoder = createAvroSchemaRegistryEncoder(); + public void deserializeSample() { + // BEGIN: readme-sample-deserializeSample + SchemaRegistryApacheAvroSerializer serializer = createAvroSchemaRegistrySerializer(); MessageWithMetadata message = getSchemaRegistryAvroMessage(); - PlayingCard playingCard = encoder.decodeMessageData(message, TypeReference.createInstance(PlayingCard.class)); - // END: readme-sample-decodeSample + PlayingCard playingCard = serializer.deserializeMessageData(message, TypeReference.createInstance(PlayingCard.class)); + // END: readme-sample-deserializeSample } /** diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderSample.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerSample.java similarity index 82% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderSample.java rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerSample.java index bb168300362e1..f687f19dcc5a0 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderSample.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerSample.java @@ -13,9 +13,9 @@ import com.azure.identity.DefaultAzureCredentialBuilder; /** - * Sample to demonstrate using {@link SchemaRegistryApacheAvroEncoder} for serialization and deserialization of data. + * Sample to demonstrate using {@link SchemaRegistryApacheAvroSerializer} for serialization and deserialization of data. */ -public class SchemaRegistryApacheAvroEncoderSample { +public class SchemaRegistryApacheAvroSerializerSample { /** * Main method to run this sample. * @@ -33,11 +33,11 @@ public static void main(String[] args) { // Create the encoder instance by configuring it with the schema registry client and // enabling auto registering of new schemas - SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder() .schemaRegistryAsyncClient(schemaRegistryAsyncClient) .schemaGroup("{schema-group}") .avroSpecificReader(true) - .buildEncoder(); + .buildSerializer(); PlayingCard playingCard = new PlayingCard(); playingCard.setCardValue(5); @@ -45,7 +45,7 @@ public static void main(String[] args) { playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES); // Serialize the playing card object and write to the output stream. - MessageWithMetadata message = encoder.encodeMessageData(playingCard, + MessageWithMetadata message = serializer.serializeMessageData(playingCard, TypeReference.createInstance(MessageWithMetadata.class)); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java index 04b1b0fbe9597..a60c9d8417e57 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java @@ -37,16 +37,16 @@ public static void main(String[] args) { // Create the encoder instance by configuring it with the schema registry client and // enabling auto registering of new schemas - SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializerBuilder() .schemaRegistryAsyncClient(schemaRegistryAsyncClient) .schemaGroup("{schema-group}") .avroSpecificReader(true) .autoRegisterSchema(true) - .buildEncoder(); + .buildSerializer(); // Get serialized avro data to deserialize into strongly-typed object. MessageWithMetadata inputStream = getMessageToDeserialize(); - PlayingCard deserializedObject = encoder.decodeMessageData(inputStream, + PlayingCard deserializedObject = encoder.deserializeMessageData(inputStream, TypeReference.createInstance(PlayingCard.class)); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderIntegrationTest.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerIntegrationTest.java similarity index 93% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderIntegrationTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerIntegrationTest.java index 186f1b36a6476..9dfc43773642b 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderIntegrationTest.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerIntegrationTest.java @@ -38,7 +38,7 @@ /** * Tests end to end experience of the schema registry class. */ -public class SchemaRegistryApacheAvroEncoderIntegrationTest extends TestBase { +public class SchemaRegistryApacheAvroSerializerIntegrationTest extends TestBase { static final String SCHEMA_REGISTRY_ENDPOINT = "SCHEMA_REGISTRY_ENDPOINT"; static final String SCHEMA_REGISTRY_GROUP = "SCHEMA_REGISTRY_GROUP"; @@ -99,11 +99,11 @@ protected void afterTest() { public void registerAndGetSchema() { // Arrange final SchemaRegistryClient registryClient = builder.buildClient(); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializerBuilder() .schemaGroup(schemaGroup) .schemaRegistryAsyncClient(builder.buildAsyncClient()) .avroSpecificReader(true) - .buildEncoder(); + .buildSerializer(); final PlayingCard playingCard = PlayingCard.newBuilder() .setCardValue(1) @@ -131,14 +131,14 @@ public void registerAndGetSchema() { assertNotNull(schemaProperties); // Act & Assert - final MessageWithMetadata encodedMessage = encoder.encodeMessageData(cards, + final MessageWithMetadata encodedMessage = encoder.serializeMessageData(cards, TypeReference.createInstance(MessageWithMetadata.class)); assertNotNull(encodedMessage); final byte[] outputArray = encodedMessage.getBodyAsBinaryData().toBytes(); assertTrue(outputArray.length > 0, "There should have been contents in array."); - final HandOfCards actual = encoder.decodeMessageData(encodedMessage, + final HandOfCards actual = encoder.deserializeMessageData(encodedMessage, TypeReference.createInstance(HandOfCards.class)); assertNotNull(actual); diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderTest.java b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerTest.java similarity index 87% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderTest.java rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerTest.java index cbbcd55414de2..cf11a7db0b028 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderTest.java +++ b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerTest.java @@ -56,12 +56,12 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Stream; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoder.AVRO_MIME_TYPE; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoder.RECORD_FORMAT_INDICATOR; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoder.RECORD_FORMAT_INDICATOR_SIZE; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoder.SCHEMA_ID_SIZE; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoderIntegrationTest.PLAYBACK_ENDPOINT; -import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroEncoderIntegrationTest.PLAYBACK_TEST_GROUP; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer.AVRO_MIME_TYPE; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer.RECORD_FORMAT_INDICATOR; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer.RECORD_FORMAT_INDICATOR_SIZE; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializer.SCHEMA_ID_SIZE; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializerIntegrationTest.PLAYBACK_ENDPOINT; +import static com.azure.data.schemaregistry.apacheavro.SchemaRegistryApacheAvroSerializerIntegrationTest.PLAYBACK_TEST_GROUP; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -72,9 +72,9 @@ import static org.mockito.Mockito.when; /** - * Unit tests for {@link SchemaRegistryApacheAvroEncoder}. + * Unit tests for {@link SchemaRegistryApacheAvroSerializer}. */ -public class SchemaRegistryApacheAvroEncoderTest { +public class SchemaRegistryApacheAvroSerializerTest { private static final String MOCK_GUID = new String(new char[SCHEMA_ID_SIZE]).replace("\0", "a"); private static final String MOCK_SCHEMA_GROUP = "mock-group"; private static final int MOCK_CACHE_SIZE = 128; @@ -136,10 +136,10 @@ public void testRegistryGuidPrefixedToPayload() { playingClassSchema.toString(), SchemaFormat.AVRO)).thenReturn(Mono.just(registered)); final String expectedContentType = AVRO_MIME_TYPE + "+" + MOCK_GUID; - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); - StepVerifier.create(encoder.encodeMessageDataAsync(playingCard, + StepVerifier.create(encoder.serializeMessageDataAsync(playingCard, TypeReference.createInstance(MessageWithMetadata.class))) .assertNext(message -> { // guid should match preloaded SchemaRegistryObject guid @@ -155,13 +155,13 @@ public void testNullPayloadThrowsSerializationException() { final AvroSerializer avroSerializer = new AvroSerializer(false, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, false, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, avroSerializer, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); final MessageWithMetadata message = new MessageWithMetadata(); // Act & Assert - StepVerifier.create(encoder.encodeMessageDataAsync(message, null)) + StepVerifier.create(encoder.serializeMessageDataAsync(message, null)) .verifyError(NullPointerException.class); } @@ -174,7 +174,7 @@ public void testIfRegistryNullThenThrow() { // Act & Assert assertThrows(NullPointerException.class, - () -> new SchemaRegistryApacheAvroEncoder(null, encoder, serializerOptions)); + () -> new SchemaRegistryApacheAvroSerializer(null, encoder, serializerOptions)); } @Test @@ -188,7 +188,7 @@ void testGetSchemaAndDeserialize() throws IOException { final SchemaRegistrySchema registrySchema = new SchemaRegistrySchema(registered, playingClassSchema); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, decoder, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, decoder, serializerOptions); assertNotNull(registrySchema.getProperties()); @@ -206,7 +206,7 @@ void testGetSchemaAndDeserialize() throws IOException { final MockMessage message = getPayload(playingCard); - StepVerifier.create(encoder.decodeMessageDataAsync(message, TypeReference.createInstance(PlayingCard.class))) + StepVerifier.create(encoder.deserializeMessageDataAsync(message, TypeReference.createInstance(PlayingCard.class))) .assertNext(actual -> { assertEquals(playingCard.getPlayingCardSuit(), actual.getPlayingCardSuit()); assertEquals(playingCard.getCardValue(), actual.getCardValue()); @@ -233,11 +233,11 @@ public void testEmptyPayload(MessageWithMetadata message) { final AvroSerializer avroSerializer = new AvroSerializer(false, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); // Act & Assert - StepVerifier.create(encoder.decodeMessageDataAsync(message, TypeReference.createInstance(PlayingCard.class))) + StepVerifier.create(encoder.deserializeMessageDataAsync(message, TypeReference.createInstance(PlayingCard.class))) .expectComplete() .verify(); } @@ -252,11 +252,11 @@ public void testEmptyPayloadSync() { final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); final MockMessage message = new MockMessage(); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); // Act - final Person actual = encoder.decodeMessageData(message, TypeReference.createInstance(Person.class)); + final Person actual = encoder.deserializeMessageData(message, TypeReference.createInstance(Person.class)); // Assert assertNull(actual); @@ -270,11 +270,11 @@ public void testNullPayload() { final AvroSerializer avroSerializer = new AvroSerializer(false, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); // Null payload should throw NullPointerException. - StepVerifier.create(encoder.encodeMessageDataAsync(null, null)) + StepVerifier.create(encoder.serializeMessageDataAsync(null, null)) .expectError(NullPointerException.class) .verify(); } @@ -287,11 +287,11 @@ public void testNullPayloadSync() { final AvroSerializer avroSerializer = new AvroSerializer(false, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder( + SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer( client, avroSerializer, serializerOptions); // Null payload should throw NullPointerException. - assertThrows(NullPointerException.class, () -> encoder.decodeMessageData(null, null)); + assertThrows(NullPointerException.class, () -> encoder.deserializeMessageData(null, null)); } /** @@ -317,15 +317,15 @@ public void serializeFromPortal() { .build(); final SchemaRegistryAsyncClient client = getSchemaRegistryClient(testInfo, TestMode.PLAYBACK); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializerBuilder() .schemaGroup(PLAYBACK_TEST_GROUP) .schemaRegistryAsyncClient(client) .avroSpecificReader(true) - .buildEncoder(); + .buildSerializer(); final String expectedContentType = AVRO_MIME_TYPE + "+64fc737160ff41bdb8a0b8af028e6827"; // Act - StepVerifier.create(encoder.encodeMessageDataAsync(record, TypeReference.createInstance(MockMessage.class))) + StepVerifier.create(encoder.serializeMessageDataAsync(record, TypeReference.createInstance(MockMessage.class))) .assertNext(message -> { assertEquals(expectedContentType, message.getContentType()); assertNotNull(message.getBodyAsBinaryData()); @@ -343,11 +343,11 @@ public void serializeFromPortal() { public void serializeForwardCompatibility() { // Arrange final SchemaRegistryAsyncClient client = getSchemaRegistryClient(testInfo, TestMode.PLAYBACK); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder() + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializerBuilder() .schemaGroup(PLAYBACK_TEST_GROUP) .schemaRegistryAsyncClient(client) .avroSpecificReader(true) - .buildEncoder(); + .buildSerializer(); final String expectedContentType = AVRO_MIME_TYPE + "+f047cfa64b374167b3a1d101370c1483"; final String name = "Jackson"; @@ -365,7 +365,7 @@ public void serializeForwardCompatibility() { final AtomicReference outputData = new AtomicReference<>(); // Act: Serialize the new Person2. - StepVerifier.create(encoder.encodeMessageDataAsync(writerPerson, TypeReference.createInstance(MockMessage.class))) + StepVerifier.create(encoder.serializeMessageDataAsync(writerPerson, TypeReference.createInstance(MockMessage.class))) .assertNext(message -> { assertEquals(expectedContentType, message.getContentType()); @@ -379,7 +379,7 @@ public void serializeForwardCompatibility() { // Act: Deserialize Person (the older schema) assertNotNull(outputData.get(), "Value should have been set from the test."); - final Person readerPerson = encoder.decodeMessageData(outputData.get(), TypeReference.createInstance(Person.class)); + final Person readerPerson = encoder.deserializeMessageData(outputData.get(), TypeReference.createInstance(Person.class)); assertNotNull(readerPerson); assertEquals(name, readerPerson.getName()); @@ -396,14 +396,14 @@ public void throwsWhenConstructorNotAvailable() { // Arrange final AvroSerializer avroSerializer = new AvroSerializer(false, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder( + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer( client, avroSerializer, serializerOptions); final PlayingCard playingCard = new PlayingCard(true, 10, PlayingCardSuit.DIAMONDS); final TypeReference typeReference = TypeReference.createInstance(InvalidMessage.class); // Act & Assert - StepVerifier.create(encoder.encodeMessageDataAsync(playingCard, typeReference)) + StepVerifier.create(encoder.serializeMessageDataAsync(playingCard, typeReference)) .expectError(IllegalArgumentException.class) .verify(); } @@ -424,7 +424,7 @@ public void backwardsCompatiblePreamble() throws IOException { final AvroSerializer avroSerializer = new AvroSerializer(true, parser, ENCODER_FACTORY, DECODER_FACTORY); final SerializerOptions serializerOptions = new SerializerOptions(MOCK_SCHEMA_GROUP, true, MOCK_CACHE_SIZE); - final SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoder(client, avroSerializer, + final SchemaRegistryApacheAvroSerializer encoder = new SchemaRegistryApacheAvroSerializer(client, avroSerializer, serializerOptions); when(client.getSchema(MOCK_GUID)).thenReturn(Mono.just(schemaResponse)); @@ -448,7 +448,7 @@ public void backwardsCompatiblePreamble() throws IOException { message.setBodyAsBinaryData(binaryData); // Act - final PlayingCard actual = encoder.decodeMessageData(message, TypeReference.createInstance(PlayingCard.class)); + final PlayingCard actual = encoder.deserializeMessageData(message, TypeReference.createInstance(PlayingCard.class)); // Assert assertNotNull(actual); @@ -506,7 +506,7 @@ private SchemaRegistryAsyncClient getSchemaRegistryClient(TestInfo testInfo, Tes endpoint = PLAYBACK_ENDPOINT; } else { tokenCredential = new DefaultAzureCredentialBuilder().build(); - endpoint = System.getenv(SchemaRegistryApacheAvroEncoderIntegrationTest.SCHEMA_REGISTRY_ENDPOINT); + endpoint = System.getenv(SchemaRegistryApacheAvroSerializerIntegrationTest.SCHEMA_REGISTRY_ENDPOINT); assertNotNull(endpoint, "'endpoint' cannot be null in LIVE/RECORD mode."); } diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderIntegrationTest.registerAndGetSchema.json b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerIntegrationTest.registerAndGetSchema.json similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderIntegrationTest.registerAndGetSchema.json rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerIntegrationTest.registerAndGetSchema.json diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderTest.serializeForwardCompatibility.json b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerTest.serializeForwardCompatibility.json similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderTest.serializeForwardCompatibility.json rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerTest.serializeForwardCompatibility.json diff --git a/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderTest.serializeFromPortal.json b/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerTest.serializeFromPortal.json similarity index 100% rename from sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroEncoderTest.serializeFromPortal.json rename to sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/test/resources/session-records/SchemaRegistryApacheAvroSerializerTest.serializeFromPortal.json