Search in sources :

Example 1 with DataInputDeserializer

use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.

the class SimpleVersionedSerializationTest method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() throws IOException {
    final SimpleVersionedSerializer<String> utfEncoder = new TestStringSerializer();
    final String testString = "dugfakgs";
    final DataOutputSerializer out = new DataOutputSerializer(32);
    SimpleVersionedSerialization.writeVersionAndSerialize(utfEncoder, testString, out);
    final byte[] outBytes = out.getCopyOfBuffer();
    final byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(utfEncoder, testString);
    assertArrayEquals(bytes, outBytes);
    final DataInputDeserializer in = new DataInputDeserializer(bytes);
    final String deserialized = SimpleVersionedSerialization.readVersionAndDeSerialize(utfEncoder, in);
    final String deserializedFromBytes = SimpleVersionedSerialization.readVersionAndDeSerialize(utfEncoder, outBytes);
    assertEquals(testString, deserialized);
    assertEquals(testString, deserializedFromBytes);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 2 with DataInputDeserializer

use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.

the class SimpleVersionedSerializationTest method testListSerializationRoundTrip.

@Test
public void testListSerializationRoundTrip() throws IOException {
    final SimpleVersionedSerializer<String> utfEncoder = new TestStringSerializer();
    final List<String> datums = ImmutableList.of("beeep!", "beep!!!");
    final DataOutputSerializer out = new DataOutputSerializer(32);
    SimpleVersionedSerialization.writeVersionAndSerializeList(utfEncoder, datums, out);
    final byte[] outBytes = out.getCopyOfBuffer();
    final DataInputDeserializer in = new DataInputDeserializer(outBytes);
    final List<String> deserialized = SimpleVersionedSerialization.readVersionAndDeserializeList(utfEncoder, in);
    assertEquals(datums, deserialized);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 3 with DataInputDeserializer

use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.

the class AvroSerializerSnapshotTest method restorePastSnapshots.

@Test
public void restorePastSnapshots() throws IOException {
    for (int pastVersion : PAST_VERSIONS) {
        AvroSerializer<GenericRecord> currentSerializer = new AvroSerializer<>(GenericRecord.class, Address.getClassSchema());
        DataInputView in = new DataInputDeserializer(Files.readAllBytes(getSerializerSnapshotFilePath(pastVersion)));
        TypeSerializerSnapshot<GenericRecord> restored = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(in, AvroSerializer.class.getClassLoader(), null);
        assertThat(restored.resolveSchemaCompatibility(currentSerializer), isCompatibleAsIs());
    }
}
Also used : DataInputView(org.apache.flink.core.memory.DataInputView) GenericRecord(org.apache.avro.generic.GenericRecord) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 4 with DataInputDeserializer

use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.

the class TypeSerializerSnapshotTest method testSerializerDeserializationFailure.

@Test
public void testSerializerDeserializationFailure() throws Exception {
    TestSerializer ser = new TestSerializer();
    TypeSerializerConfigSnapshot<Object> snap = (TypeSerializerConfigSnapshot<Object>) ser.snapshotConfiguration();
    snap.setPriorSerializer(ser);
    DataOutputSerializer out = new DataOutputSerializer(64);
    TypeSerializerSnapshot.writeVersionedSnapshot(out, snap);
    TypeSerializerSnapshot<Object> readBack = TypeSerializerSnapshot.readVersionedSnapshot(new DataInputDeserializer(out.getCopyOfBuffer()), getClass().getClassLoader());
    assertNotNull(readBack);
    try {
        readBack.restoreSerializer();
        fail("expected exception");
    } catch (IllegalStateException e) {
    // expected
    }
    ((TypeSerializerConfigSnapshot<Object>) readBack).setPriorSerializer(new UnloadableDummyTypeSerializer<>(new byte[0]));
    try {
        readBack.restoreSerializer();
        fail("expected exception");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 5 with DataInputDeserializer

use of org.apache.flink.core.memory.DataInputDeserializer in project flink by apache.

the class CompositeTypeSerializerSnapshotTest method snapshotCompositeSerializerAndGetSchemaCompatibilityAfterRestore.

private TypeSerializerSchemaCompatibility<String> snapshotCompositeSerializerAndGetSchemaCompatibilityAfterRestore(TypeSerializer<?>[] initialNestedSerializers, TypeSerializer<?>[] newNestedSerializer, OuterSchemaCompatibility mockOuterSchemaCompatibilityResult) throws IOException {
    TestCompositeTypeSerializer testSerializer = new TestCompositeTypeSerializer(initialNestedSerializers);
    TypeSerializerSnapshot<String> testSerializerSnapshot = testSerializer.snapshotConfiguration();
    DataOutputSerializer out = new DataOutputSerializer(128);
    TypeSerializerSnapshot.writeVersionedSnapshot(out, testSerializerSnapshot);
    DataInputDeserializer in = new DataInputDeserializer(out.getCopyOfBuffer());
    testSerializerSnapshot = TypeSerializerSnapshot.readVersionedSnapshot(in, Thread.currentThread().getContextClassLoader());
    TestCompositeTypeSerializer newTestSerializer = new TestCompositeTypeSerializer(mockOuterSchemaCompatibilityResult, newNestedSerializer);
    return testSerializerSnapshot.resolveSchemaCompatibility(newTestSerializer);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer)

Aggregations

DataInputDeserializer (org.apache.flink.core.memory.DataInputDeserializer)36 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)15 IOException (java.io.IOException)9 Test (org.junit.Test)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 Path (org.apache.flink.core.fs.Path)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 MapSerializer (org.apache.flink.api.common.typeutils.base.MapSerializer)2 DataInputView (org.apache.flink.core.memory.DataInputView)2 GenericRowData (org.apache.flink.table.data.GenericRowData)2 RowData (org.apache.flink.table.data.RowData)2 ByteOrder (java.nio.ByteOrder)1 ArrayDeque (java.util.ArrayDeque)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1