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);
}
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);
}
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());
}
}
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
}
}
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);
}
Aggregations