Search in sources :

Example 1 with Animal

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());
}
Also used : Animal(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DogKryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogKryoSerializer) DogV2KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogV2KryoSerializer) Test(org.junit.Test)

Example 2 with Animal

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);
    }
}
Also used : Serializable(java.io.Serializable) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) ClassLoaderUtils(org.apache.flink.testutils.ClassLoaderUtils) Animal(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DogKryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogKryoSerializer) DogV2KryoSerializer(org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogV2KryoSerializer)

Aggregations

ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 Animal (org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal)2 DogKryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogKryoSerializer)2 DogV2KryoSerializer (org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.DogV2KryoSerializer)2 Serializable (java.io.Serializable)1 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)1 ClassLoaderUtils (org.apache.flink.testutils.ClassLoaderUtils)1 Test (org.junit.Test)1