use of org.apache.flink.util.SerializedThrowable in project flink by apache.
the class ProducerFailedExceptionTest method testCauseIsSerialized.
@Test
public void testCauseIsSerialized() throws Exception {
// Tests that the cause is stringified, because it might be an instance
// of a user level Exception, which can not be deserialized by the
// remote receiver's system class loader.
ProducerFailedException e = new ProducerFailedException(new Exception());
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof SerializedThrowable);
}
use of org.apache.flink.util.SerializedThrowable in project flink by apache.
the class SerializedThrowableTest method testSerialization.
@Test
public void testSerialization() {
try {
// We need an exception whose class is not in the core class loader
final ClassLoaderUtils.ObjectAndClassLoader<Exception> outsideClassLoading = ClassLoaderUtils.createExceptionObjectFromNewClassLoader();
ClassLoader loader = outsideClassLoading.getClassLoader();
Exception userException = outsideClassLoading.getObject();
Class<?> clazz = userException.getClass();
// check that we cannot simply copy the exception
try {
byte[] serialized = InstantiationUtil.serializeObject(userException);
InstantiationUtil.deserializeObject(serialized, getClass().getClassLoader());
fail("should fail with a class not found exception");
} catch (ClassNotFoundException e) {
// as we want it
}
// validate that the SerializedThrowable mimics the original exception
SerializedThrowable serialized = new SerializedThrowable(userException);
assertEquals(userException.getMessage(), serialized.getMessage());
assertEquals(userException.toString(), serialized.toString());
assertEquals(ExceptionUtils.stringifyException(userException), ExceptionUtils.stringifyException(serialized));
assertArrayEquals(userException.getStackTrace(), serialized.getStackTrace());
// copy the serialized throwable and make sure everything still works
SerializedThrowable copy = CommonTestUtils.createCopySerializable(serialized);
assertEquals(userException.getMessage(), copy.getMessage());
assertEquals(userException.toString(), copy.toString());
assertEquals(ExceptionUtils.stringifyException(userException), ExceptionUtils.stringifyException(copy));
assertArrayEquals(userException.getStackTrace(), copy.getStackTrace());
// deserialize the proper exception
Throwable deserialized = copy.deserializeError(loader);
assertEquals(clazz, deserialized.getClass());
// deserialization with the wrong classloader does not lead to a failure
Throwable wronglyDeserialized = copy.deserializeError(getClass().getClassLoader());
assertEquals(ExceptionUtils.stringifyException(userException), ExceptionUtils.stringifyException(wronglyDeserialized));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.util.SerializedThrowable in project flink by apache.
the class SerializedThrowableTest method testCauseChaining.
@Test
public void testCauseChaining() {
Exception cause2 = new Exception("level2");
Exception cause1 = new Exception("level1", cause2);
Exception root = new Exception("level0", cause1);
SerializedThrowable st = new SerializedThrowable(root);
assertEquals("level0", st.getMessage());
assertNotNull(st.getCause());
assertEquals("level1", st.getCause().getMessage());
assertNotNull(st.getCause().getCause());
assertEquals("level2", st.getCause().getCause().getMessage());
}
use of org.apache.flink.util.SerializedThrowable in project flink by apache.
the class SerializedThrowableTest method testCyclicCauseChaining.
@Test
public void testCyclicCauseChaining() {
Exception cause3 = new Exception("level3");
Exception cause2 = new Exception("level2", cause3);
Exception cause1 = new Exception("level1", cause2);
Exception root = new Exception("level0", cause1);
// introduce a cyclic reference
cause3.initCause(cause1);
SerializedThrowable st = new SerializedThrowable(root);
assertArrayEquals(root.getStackTrace(), st.getStackTrace());
assertEquals(ExceptionUtils.stringifyException(root), ExceptionUtils.stringifyException(st));
}
use of org.apache.flink.util.SerializedThrowable in project flink by apache.
the class CheckpointResourcesCleanupRunnerTest method testRequestJobWithFailure.
@Test
public void testRequestJobWithFailure() {
final SerializedThrowable expectedError = new SerializedThrowable(new Exception("Expected exception"));
final JobResult jobResult = createJobResultWithFailure(expectedError);
testRequestJobExecutionGraph(jobResult, System.currentTimeMillis(), actualExecutionGraph -> Objects.requireNonNull(actualExecutionGraph.getFailureInfo()).getException().equals(expectedError));
}
Aggregations