Search in sources :

Example 1 with RemoteRpcInvocation

use of org.apache.flink.runtime.rpc.messages.RemoteRpcInvocation in project flink by apache.

the class FlinkUserCodeClassLoadersTest method testMessageDecodingWithUnavailableClass.

@Test
public void testMessageDecodingWithUnavailableClass() throws Exception {
    final ClassLoader systemClassLoader = getClass().getClassLoader();
    final String className = "UserClass";
    final URLClassLoader userClassLoader = ClassLoaderUtils.compileAndLoadJava(temporaryFolder.newFolder(), className + ".java", "import java.io.Serializable;\n" + "public class " + className + " implements Serializable {}");
    RemoteRpcInvocation method = new RemoteRpcInvocation(className, "test", new Class<?>[] { int.class, Class.forName(className, false, userClassLoader) }, new Object[] { 1, Class.forName(className, false, userClassLoader).newInstance() });
    SerializedValue<RemoteRpcInvocation> serializedMethod = new SerializedValue<>(method);
    expectedException.expect(ClassNotFoundException.class);
    expectedException.expect(allOf(isA(ClassNotFoundException.class), hasProperty("suppressed", hasItemInArray(allOf(isA(ClassNotFoundException.class), hasProperty("message", containsString("Could not deserialize 1th parameter type of method test(int, ...).")))))));
    RemoteRpcInvocation deserializedMethod = serializedMethod.deserializeValue(systemClassLoader);
    deserializedMethod.getMethodName();
    userClassLoader.close();
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) RemoteRpcInvocation(org.apache.flink.runtime.rpc.messages.RemoteRpcInvocation) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SerializedValue(org.apache.flink.util.SerializedValue) Test(org.junit.Test)

Aggregations

URLClassLoader (java.net.URLClassLoader)1 RemoteRpcInvocation (org.apache.flink.runtime.rpc.messages.RemoteRpcInvocation)1 SerializedValue (org.apache.flink.util.SerializedValue)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1