use of org.apache.flink.core.memory.DataOutputViewStreamWrapper in project flink by apache.
the class TypeSerializerSerializationUtilTest method testSerializerSerializationWithClassNotFound.
/**
* Verifies deserialization failure cases when reading a serializer from bytes, in the case of a
* {@link ClassNotFoundException}.
*/
@Test
public void testSerializerSerializationWithClassNotFound() throws Exception {
TypeSerializer<?> serializer = IntSerializer.INSTANCE;
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer);
serialized = out.toByteArray();
}
TypeSerializer<?> deserializedSerializer;
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer(new DataInputViewStreamWrapper(in), new ArtificialCNFExceptionThrowingClassLoader(Thread.currentThread().getContextClassLoader(), Collections.singleton(IntSerializer.class.getName())), true);
}
Assert.assertTrue(deserializedSerializer instanceof UnloadableDummyTypeSerializer);
Assert.assertArrayEquals(InstantiationUtil.serializeObject(serializer), ((UnloadableDummyTypeSerializer<?>) deserializedSerializer).getActualBytes());
}
use of org.apache.flink.core.memory.DataOutputViewStreamWrapper in project flink by apache.
the class TypeSerializerSerializationUtilTest method testSerializerSerializationWithInvalidClass.
/**
* Verifies deserialization failure cases when reading a serializer from bytes, in the case of a
* {@link InvalidClassException}.
*/
@Test
public void testSerializerSerializationWithInvalidClass() throws Exception {
TypeSerializer<?> serializer = IntSerializer.INSTANCE;
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer);
serialized = out.toByteArray();
}
TypeSerializer<?> deserializedSerializer;
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer(new DataInputViewStreamWrapper(in), new ArtificialCNFExceptionThrowingClassLoader(Thread.currentThread().getContextClassLoader(), Collections.singleton(IntSerializer.class.getName())), true);
}
Assert.assertTrue(deserializedSerializer instanceof UnloadableDummyTypeSerializer);
}
use of org.apache.flink.core.memory.DataOutputViewStreamWrapper in project flink by apache.
the class TypeSerializerSerializationUtilTest method testSerializeConfigurationSnapshots.
/**
* Verifies that reading and writing configuration snapshots work correctly.
*/
@Test
public void testSerializeConfigurationSnapshots() throws Exception {
TypeSerializerSerializationUtilTest.TestConfigSnapshot<String> configSnapshot1 = new TypeSerializerSerializationUtilTest.TestConfigSnapshot<>(1, "foo");
byte[] serializedConfig;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(new DataOutputViewStreamWrapper(out), configSnapshot1, StringSerializer.INSTANCE);
serializedConfig = out.toByteArray();
}
TypeSerializerSnapshot<?> restoredConfigs;
try (ByteArrayInputStream in = new ByteArrayInputStream(serializedConfig)) {
restoredConfigs = TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader(), null);
}
assertEquals(configSnapshot1, restoredConfigs);
}
use of org.apache.flink.core.memory.DataOutputViewStreamWrapper in project flink by apache.
the class TypeSerializerSerializationUtilTest method testSerializerSerialization.
/**
* Verifies that reading and writing serializers work correctly.
*/
@Test
public void testSerializerSerialization() throws Exception {
TypeSerializer<?> serializer = IntSerializer.INSTANCE;
byte[] serialized;
try (ByteArrayOutputStreamWithPos out = new ByteArrayOutputStreamWithPos()) {
TypeSerializerSerializationUtil.writeSerializer(new DataOutputViewStreamWrapper(out), serializer);
serialized = out.toByteArray();
}
TypeSerializer<?> deserializedSerializer;
try (ByteArrayInputStreamWithPos in = new ByteArrayInputStreamWithPos(serialized)) {
deserializedSerializer = TypeSerializerSerializationUtil.tryReadSerializer(new DataInputViewStreamWrapper(in), Thread.currentThread().getContextClassLoader());
}
Assert.assertEquals(serializer, deserializedSerializer);
}
use of org.apache.flink.core.memory.DataOutputViewStreamWrapper in project flink by apache.
the class TypeSerializerSerializationUtilTest method testFailsWhenConfigurationSnapshotClassNotFound.
/**
* Verifies that deserializing config snapshots fail if the config class could not be found.
*/
@Test(expected = IOException.class)
public void testFailsWhenConfigurationSnapshotClassNotFound() throws Exception {
byte[] serializedConfig;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot(new DataOutputViewStreamWrapper(out), new TypeSerializerSerializationUtilTest.TestConfigSnapshot<>(123, "foobar"), StringSerializer.INSTANCE);
serializedConfig = out.toByteArray();
}
try (ByteArrayInputStream in = new ByteArrayInputStream(serializedConfig)) {
// read using a dummy classloader
TypeSerializerSnapshotSerializationUtil.readSerializerSnapshot(new DataInputViewStreamWrapper(in), new URLClassLoader(new URL[0], null), null);
}
fail("Expected a ClassNotFoundException wrapped in IOException");
}
Aggregations