Search in sources :

Example 1 with GlueSchemaRegistryDefaultCompression

use of com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression in project flink by apache.

the class GlueSchemaRegistryInputStreamDeserializerTest method testGetSchemaAndDeserializedStream_withoutCompression_succeeds.

/**
 * Test whether getSchemaAndDeserializedStream method when compression is not enabled works.
 */
@Test
public void testGetSchemaAndDeserializedStream_withoutCompression_succeeds() throws IOException {
    compressionByte = COMPRESSION_DEFAULT_BYTE;
    compressionHandler = new GlueSchemaRegistryDefaultCompression();
    ByteArrayOutputStream byteArrayOutputStream = buildByteArrayOutputStream(AWSSchemaRegistryConstants.HEADER_VERSION_BYTE, compressionByte);
    byte[] bytes = writeToExistingStream(byteArrayOutputStream, encodeData(userDefinedPojo, new SpecificDatumWriter<>(userSchema)));
    MutableByteArrayInputStream mutableByteArrayInputStream = new MutableByteArrayInputStream();
    mutableByteArrayInputStream.setBuffer(bytes);
    glueSchemaRegistryDeserializationFacade = new MockGlueSchemaRegistryDeserializationFacade(bytes, glueSchema, NONE);
    GlueSchemaRegistryInputStreamDeserializer glueSchemaRegistryInputStreamDeserializer = new GlueSchemaRegistryInputStreamDeserializer(glueSchemaRegistryDeserializationFacade);
    Schema resultSchema = glueSchemaRegistryInputStreamDeserializer.getSchemaAndDeserializedStream(mutableByteArrayInputStream);
    assertThat(resultSchema.toString()).isEqualTo(glueSchema.getSchemaDefinition());
}
Also used : MutableByteArrayInputStream(org.apache.flink.formats.avro.utils.MutableByteArrayInputStream) Schema(org.apache.avro.Schema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GlueSchemaRegistryDefaultCompression(com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter) Test(org.junit.Test)

Example 2 with GlueSchemaRegistryDefaultCompression

use of com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression in project flink by apache.

the class GlueSchemaRegistryInputStreamDeserializerTest method testGetSchemaAndDeserializedStream_withCompression_succeeds.

/**
 * Test whether getSchemaAndDeserializedStream method when compression is enabled works.
 */
@Test
public void testGetSchemaAndDeserializedStream_withCompression_succeeds() throws IOException {
    COMPRESSION compressionType = COMPRESSION.ZLIB;
    compressionByte = AWSSchemaRegistryConstants.COMPRESSION_BYTE;
    compressionHandler = new GlueSchemaRegistryDefaultCompression();
    ByteArrayOutputStream byteArrayOutputStream = buildByteArrayOutputStream(AWSSchemaRegistryConstants.HEADER_VERSION_BYTE, compressionByte);
    byte[] bytes = writeToExistingStream(byteArrayOutputStream, compressData(encodeData(userDefinedPojo, new SpecificDatumWriter<>(userSchema))));
    MutableByteArrayInputStream mutableByteArrayInputStream = new MutableByteArrayInputStream();
    mutableByteArrayInputStream.setBuffer(bytes);
    glueSchemaRegistryDeserializationFacade = new MockGlueSchemaRegistryDeserializationFacade(bytes, glueSchema, compressionType);
    GlueSchemaRegistryInputStreamDeserializer glueSchemaRegistryInputStreamDeserializer = new GlueSchemaRegistryInputStreamDeserializer(glueSchemaRegistryDeserializationFacade);
    Schema resultSchema = glueSchemaRegistryInputStreamDeserializer.getSchemaAndDeserializedStream(mutableByteArrayInputStream);
    assertThat(resultSchema.toString()).isEqualTo(glueSchema.getSchemaDefinition());
}
Also used : MutableByteArrayInputStream(org.apache.flink.formats.avro.utils.MutableByteArrayInputStream) Schema(org.apache.avro.Schema) COMPRESSION(com.amazonaws.services.schemaregistry.utils.AWSSchemaRegistryConstants.COMPRESSION) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GlueSchemaRegistryDefaultCompression(com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression) Test(org.junit.Test)

Aggregations

GlueSchemaRegistryDefaultCompression (com.amazonaws.services.schemaregistry.common.GlueSchemaRegistryDefaultCompression)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Schema (org.apache.avro.Schema)2 MutableByteArrayInputStream (org.apache.flink.formats.avro.utils.MutableByteArrayInputStream)2 Test (org.junit.Test)2 COMPRESSION (com.amazonaws.services.schemaregistry.utils.AWSSchemaRegistryConstants.COMPRESSION)1 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)1