use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal in project flink by apache.
the class KryoSerializerSnapshotTest method tryingToRestoreWithNonExistingClassShouldBeIncompatible.
@Test
public void tryingToRestoreWithNonExistingClassShouldBeIncompatible() throws IOException {
TypeSerializerSnapshot<Animal> restoredSnapshot = kryoSnapshotWithMissingClass();
TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, new ExecutionConfig());
assertThat(restoredSnapshot.resolveSchemaCompatibility(currentSerializer), isIncompatible());
}
use of org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal in project flink by apache.
the class KryoSerializerSnapshotTest method unLoadableSnapshotBytes.
/**
* This method returns the bytes of a serialized {@link KryoSerializerSnapshot}, that contains a
* Kryo registration of a class that does not exists in the current classpath.
*/
private static byte[] unLoadableSnapshotBytes() throws IOException {
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
final ClassLoaderUtils.ObjectAndClassLoader<Serializable> outsideClassLoading = ClassLoaderUtils.createSerializableObjectFromNewClassLoader();
try {
Thread.currentThread().setContextClassLoader(outsideClassLoading.getClassLoader());
ExecutionConfig conf = new ExecutionConfig();
conf.registerKryoType(outsideClassLoading.getObject().getClass());
KryoSerializer<Animal> previousSerializer = new KryoSerializer<>(Animal.class, conf);
TypeSerializerSnapshot<Animal> previousSnapshot = previousSerializer.snapshotConfiguration();
DataOutputSerializer out = new DataOutputSerializer(4096);
TypeSerializerSnapshot.writeVersionedSnapshot(out, previousSnapshot);
return out.getCopyOfBuffer();
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
Aggregations