Java Code Examples for org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal

The following examples show how to use org.apache.flink.api.java.typeutils.runtime.kryo.KryoPojosForMigrationTests.Animal. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();

	ClassLoader tempClassLoader =
		new URLClassLoader(new URL[0], KryoSerializerSnapshotTest.class.getClassLoader());
	try {
		Thread.currentThread().setContextClassLoader(tempClassLoader);

		ExecutionConfig conf = registerClassThatIsNotInClassPath(tempClassLoader);

		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);
	}
}
 
Example 2
Source Project: Flink-CEPplus   Source File: KryoSnapshotMigrationTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void add(List<Object[]> all,
						String name, Supplier<TypeSerializer<Animal>> supplier,
						TypeSerializerSchemaCompatibility<Animal> expected) {

	TestSpecification<Animal> flink16 = TestSpecification.<Animal>builder(
		MigrationVersion.v1_6 + " " + name,
		KryoSerializer.class,
		KryoSerializerSnapshot.class,
		MigrationVersion.v1_6)
		.withNewSerializerProvider(supplier, expected)
		.withSnapshotDataLocation("flink-1.6-" + name + "-snapshot")
		.withTestData("flink-1.6-" + name + "-data", 2);

	TestSpecification<Animal> flink17 = TestSpecification.<Animal>builder(
		MigrationVersion.v1_7 + " " + name,
		KryoSerializer.class,
		KryoSerializerSnapshot.class,
		MigrationVersion.v1_7)
		.withNewSerializerProvider(supplier, expected)
		.withSnapshotDataLocation("flink-1.7-" + name + "-snapshot")
		.withTestData("flink-1.7-" + name + "-data", 2);

	all.add(new Object[]{flink16});
	all.add(new Object[]{flink17});
}
 
Example 3
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 CommonTestUtils.ObjectAndClassLoader outsideClassLoading = CommonTestUtils.createObjectFromNewClassLoader();

	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);
	}
}
 
Example 4
Source Project: flink   Source File: KryoSnapshotMigrationTest.java    License: Apache License 2.0 6 votes vote down vote up
private static void add(List<Object[]> all,
						String name, Supplier<TypeSerializer<Animal>> supplier,
						TypeSerializerSchemaCompatibility<Animal> expected) {

	TestSpecification<Animal> flink16 = TestSpecification.<Animal>builder(
		MigrationVersion.v1_6 + " " + name,
		KryoSerializer.class,
		KryoSerializerSnapshot.class,
		MigrationVersion.v1_6)
		.withNewSerializerProvider(supplier, expected)
		.withSnapshotDataLocation("flink-1.6-" + name + "-snapshot")
		.withTestData("flink-1.6-" + name + "-data", 2);

	TestSpecification<Animal> flink17 = TestSpecification.<Animal>builder(
		MigrationVersion.v1_7 + " " + name,
		KryoSerializer.class,
		KryoSerializerSnapshot.class,
		MigrationVersion.v1_7)
		.withNewSerializerProvider(supplier, expected)
		.withSnapshotDataLocation("flink-1.7-" + name + "-snapshot")
		.withTestData("flink-1.7-" + name + "-data", 2);

	all.add(new Object[]{flink16});
	all.add(new Object[]{flink17});
}
 
Example 5
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void addingTypesIsCompatibleAfterReconfiguration() {
	oldConfig.registerKryoType(Animal.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleWithReconfiguredSerializer());
}
 
Example 7
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void replacingKryoSerializersIsCompatibleAsIs() {
	oldConfig.registerKryoType(Animal.class);
	oldConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogV2KryoSerializer.class);

	// it is compatible as is, since Kryo does not expose compatibility API with KryoSerializers
	// so we can not know if DogKryoSerializer is compatible with DogV2KryoSerializer
	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleAsIs());
}
 
Example 8
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void tryingToRestoreWithNonExistingClassShouldBeIncompatible() throws IOException {
	TypeSerializerSnapshot<Animal> restoredSnapshot = kryoSnapshotWithMissingClass();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, new ExecutionConfig());

	assertThat(restoredSnapshot.resolveSchemaCompatibility(currentSerializer),
		isIncompatible());
}
 
Example 9
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSnapshot<Animal> kryoSnapshotWithMissingClass() throws IOException {
	DataInputView in = new DataInputDeserializer(unLoadableSnapshotBytes());

	return TypeSerializerSnapshot.readVersionedSnapshot(
		in,
		KryoSerializerSnapshotTest.class.getClassLoader());
}
 
Example 10
Source Project: Flink-CEPplus   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSchemaCompatibility<Animal> resolveKryoCompatibility(ExecutionConfig previous, ExecutionConfig current) {
	KryoSerializer<Animal> previousSerializer = new KryoSerializer<>(Animal.class, previous);
	TypeSerializerSnapshot<Animal> previousSnapshot = previousSerializer.snapshotConfiguration();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, current);
	return previousSnapshot.resolveSchemaCompatibility(currentSerializer);
}
 
Example 11
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void addingTypesIsCompatibleAfterReconfiguration() {
	oldConfig.registerKryoType(Animal.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleWithReconfiguredSerializer());
}
 
Example 12
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void replacingKryoSerializersIsCompatibleAsIs() {
	oldConfig.registerKryoType(Animal.class);
	oldConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogV2KryoSerializer.class);

	// it is compatible as is, since Kryo does not expose compatibility API with KryoSerializers
	// so we can not know if DogKryoSerializer is compatible with DogV2KryoSerializer
	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleAsIs());
}
 
Example 13
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void tryingToRestoreWithNonExistingClassShouldBeIncompatible() throws IOException {
	TypeSerializerSnapshot<Animal> restoredSnapshot = kryoSnapshotWithMissingClass();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, new ExecutionConfig());

	assertThat(restoredSnapshot.resolveSchemaCompatibility(currentSerializer),
		isIncompatible());
}
 
Example 14
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSnapshot<Animal> kryoSnapshotWithMissingClass() throws IOException {
	DataInputView in = new DataInputDeserializer(unLoadableSnapshotBytes());

	return TypeSerializerSnapshot.readVersionedSnapshot(
		in,
		KryoSerializerSnapshotTest.class.getClassLoader());
}
 
Example 15
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSchemaCompatibility<Animal> resolveKryoCompatibility(ExecutionConfig previous, ExecutionConfig current) {
	KryoSerializer<Animal> previousSerializer = new KryoSerializer<>(Animal.class, previous);
	TypeSerializerSnapshot<Animal> previousSnapshot = previousSerializer.snapshotConfiguration();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, current);
	return previousSnapshot.resolveSchemaCompatibility(currentSerializer);
}
 
Example 16
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void addingTypesIsCompatibleAfterReconfiguration() {
	oldConfig.registerKryoType(Animal.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleWithReconfiguredSerializer());
}
 
Example 17
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void replacingKryoSerializersIsCompatibleAsIs() {
	oldConfig.registerKryoType(Animal.class);
	oldConfig.registerTypeWithKryoSerializer(Dog.class, DogKryoSerializer.class);

	newConfig.registerKryoType(Animal.class);
	newConfig.registerTypeWithKryoSerializer(Dog.class, DogV2KryoSerializer.class);

	// it is compatible as is, since Kryo does not expose compatibility API with KryoSerializers
	// so we can not know if DogKryoSerializer is compatible with DogV2KryoSerializer
	assertThat(resolveKryoCompatibility(oldConfig, newConfig),
		isCompatibleAsIs());
}
 
Example 18
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void tryingToRestoreWithNonExistingClassShouldBeIncompatible() throws IOException {
	TypeSerializerSnapshot<Animal> restoredSnapshot = kryoSnapshotWithMissingClass();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, new ExecutionConfig());

	assertThat(restoredSnapshot.resolveSchemaCompatibility(currentSerializer),
		isIncompatible());
}
 
Example 19
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSnapshot<Animal> kryoSnapshotWithMissingClass() throws IOException {
	DataInputView in = new DataInputDeserializer(unLoadableSnapshotBytes());

	return TypeSerializerSnapshot.readVersionedSnapshot(
		in,
		KryoSerializerSnapshotTest.class.getClassLoader());
}
 
Example 20
Source Project: flink   Source File: KryoSerializerSnapshotTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeSerializerSchemaCompatibility<Animal> resolveKryoCompatibility(ExecutionConfig previous, ExecutionConfig current) {
	KryoSerializer<Animal> previousSerializer = new KryoSerializer<>(Animal.class, previous);
	TypeSerializerSnapshot<Animal> previousSnapshot = previousSerializer.snapshotConfiguration();

	TypeSerializer<Animal> currentSerializer = new KryoSerializer<>(Animal.class, current);
	return previousSnapshot.resolveSchemaCompatibility(currentSerializer);
}
 
Example 21
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Animal> createUpgradedSerializer() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.registerKryoType(DummyClassOne.class);
	executionConfig.registerTypeWithKryoSerializer(
			DummyClassTwo.class,
			DefaultSerializers.StringSerializer.class);

	return new KryoSerializer<>(Animal.class, executionConfig);
}
 
Example 22
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Animal> createPriorSerializer() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.registerKryoType(Dog.class);
	executionConfig.registerKryoType(Cat.class);
	executionConfig.registerKryoType(Parrot.class);

	return new KryoSerializer<>(Animal.class, executionConfig);
}
 
Example 23
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Animal> createUpgradedSerializer() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.registerKryoType(DummyClassOne.class);
	executionConfig.registerKryoType(Dog.class);
	executionConfig.registerKryoType(DummyClassTwo.class);
	executionConfig.registerKryoType(Cat.class);
	executionConfig.registerKryoType(Parrot.class);

	return new KryoSerializer<>(Animal.class, executionConfig);
}
 
Example 24
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Animal> createPriorSerializer() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.registerTypeWithKryoSerializer(
			Dog.class,
			KryoPojosForMigrationTests.DogKryoSerializer.class);
	executionConfig.registerKryoType(Cat.class);
	executionConfig.registerTypeWithKryoSerializer(
			Parrot.class,
			KryoPojosForMigrationTests.ParrotKryoSerializer.class);

	return new KryoSerializer<>(Animal.class, executionConfig);
}
 
Example 25
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeSerializer<Animal> createUpgradedSerializer() {
	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.registerKryoType(DummyClassOne.class);
	executionConfig.registerTypeWithKryoSerializer(
			Dog.class,
			KryoPojosForMigrationTests.DogV2KryoSerializer.class);
	executionConfig.registerKryoType(DummyClassTwo.class);
	executionConfig.registerKryoType(Cat.class);
	executionConfig.registerTypeWithKryoSerializer(
			Parrot.class,
			KryoPojosForMigrationTests.ParrotKryoSerializer.class);

	return new KryoSerializer<>(Animal.class, executionConfig);
}
 
Example 26
Source Project: Flink-CEPplus   Source File: KryoSnapshotMigrationTest.java    License: Apache License 2.0 4 votes vote down vote up
private static void add(List<Object[]> all, String name, Supplier<TypeSerializer<Animal>> supplier) {
	add(all, name, supplier, compatibleAsIs());
}
 
Example 27
Source Project: flink   Source File: KryoSnapshotMigrationTest.java    License: Apache License 2.0 4 votes vote down vote up
private static void add(List<Object[]> all, String name, Supplier<TypeSerializer<Animal>> supplier) {
	add(all, name, supplier, compatibleAsIs());
}
 
Example 28
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer<Animal> createPriorSerializer() {
	return new KryoSerializer<>(Animal.class, new ExecutionConfig());
}
 
Example 29
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Animal createTestData() {
	return new Dog("Hasso");
}
 
Example 30
Source Project: flink   Source File: KryoSerializerUpgradeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializer<Animal> createUpgradedSerializer() {
	return new KryoSerializer<>(Animal.class, new ExecutionConfig());
}