org.apache.flink.core.testutils.FilteredClassLoader Java Examples

The following examples show how to use org.apache.flink.core.testutils.FilteredClassLoader. 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 File: AvroKryoClassloadingTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testKryoInChildClasspath() throws Exception {
	final Class<?> avroClass = AvroKryoSerializerUtils.class;

	final URL avroLocation = avroClass.getProtectionDomain().getCodeSource().getLocation();
	final URL kryoLocation = Kryo.class.getProtectionDomain().getCodeSource().getLocation();

	final ClassLoader parentClassLoader = new FilteredClassLoader(
			avroClass.getClassLoader(), AvroKryoSerializerUtils.class.getName());

	final ClassLoader userAppClassLoader = FlinkUserCodeClassLoaders.childFirst(
			new URL[] { avroLocation, kryoLocation },
			parentClassLoader,
			CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS.defaultValue().split(";"));

	final Class<?> userLoadedAvroClass = Class.forName(avroClass.getName(), false, userAppClassLoader);
	assertNotEquals(avroClass, userLoadedAvroClass);

	// call the 'addAvroGenericDataArrayRegistration(...)' method
	final Method m = userLoadedAvroClass.getMethod("addAvroGenericDataArrayRegistration", LinkedHashMap.class);

	final LinkedHashMap<String, ?> map = new LinkedHashMap<>();
	m.invoke(userLoadedAvroClass.newInstance(), map);

	assertEquals(1, map.size());
}
 
Example #2
Source File: AvroKryoClassloadingTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testKryoInChildClasspath() throws Exception {
	final Class<?> avroClass = AvroKryoSerializerUtils.class;

	final URL avroLocation = avroClass.getProtectionDomain().getCodeSource().getLocation();
	final URL kryoLocation = Kryo.class.getProtectionDomain().getCodeSource().getLocation();

	final ClassLoader parentClassLoader = new FilteredClassLoader(
			avroClass.getClassLoader(), AvroKryoSerializerUtils.class.getName());

	final ClassLoader userAppClassLoader = FlinkUserCodeClassLoaders.childFirst(
			new URL[] { avroLocation, kryoLocation },
			parentClassLoader,
			CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS.defaultValue().split(";"));

	final Class<?> userLoadedAvroClass = Class.forName(avroClass.getName(), false, userAppClassLoader);
	assertNotEquals(avroClass, userLoadedAvroClass);

	// call the 'addAvroGenericDataArrayRegistration(...)' method
	final Method m = userLoadedAvroClass.getMethod("addAvroGenericDataArrayRegistration", LinkedHashMap.class);

	final LinkedHashMap<String, ?> map = new LinkedHashMap<>();
	m.invoke(userLoadedAvroClass.newInstance(), map);

	assertEquals(1, map.size());
}
 
Example #3
Source File: AvroKryoClassloadingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testKryoInChildClasspath() throws Exception {
	final Class<?> avroClass = AvroKryoSerializerUtils.class;

	final URL avroLocation = avroClass.getProtectionDomain().getCodeSource().getLocation();
	final URL kryoLocation = Kryo.class.getProtectionDomain().getCodeSource().getLocation();

	final ClassLoader parentClassLoader = new FilteredClassLoader(
			avroClass.getClassLoader(), AvroKryoSerializerUtils.class.getName());

	final ClassLoader userAppClassLoader = FlinkUserCodeClassLoaders.childFirst(
			new URL[] { avroLocation, kryoLocation },
			parentClassLoader,
			CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS.defaultValue().split(";"),
		NOOP_EXCEPTION_HANDLER);

	final Class<?> userLoadedAvroClass = Class.forName(avroClass.getName(), false, userAppClassLoader);
	assertNotEquals(avroClass, userLoadedAvroClass);

	// call the 'addAvroGenericDataArrayRegistration(...)' method
	final Method m = userLoadedAvroClass.getMethod("addAvroGenericDataArrayRegistration", LinkedHashMap.class);

	final LinkedHashMap<String, ?> map = new LinkedHashMap<>();
	m.invoke(userLoadedAvroClass.newInstance(), map);

	assertEquals(1, map.size());
}