org.apache.flink.util.SerializedThrowable Java Examples
The following examples show how to use
org.apache.flink.util.SerializedThrowable.
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: RestClusterClientSavepointTriggerTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testTriggerSavepointFailure() throws Exception { final TriggerId triggerId = new TriggerId(); try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint( request -> triggerId, trigger -> new SavepointInfo(null, new SerializedThrowable(new RuntimeException("expected"))))) { final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort()); try { restClusterClient.triggerSavepoint(new JobID(), null).get(); } catch (ExecutionException e) { final Throwable cause = e.getCause(); assertThat(cause, instanceOf(SerializedThrowable.class)); assertThat(((SerializedThrowable) cause) .deserializeError(ClassLoader.getSystemClassLoader()) .getMessage(), equalTo("expected")); } } }
Example #2
Source File: SerializedThrowableTest.java From flink with Apache License 2.0 | 6 votes |
@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()); }
Example #3
Source File: SerializedThrowableSerializerTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSerializationDeserialization() throws Exception { final String lastExceptionMessage = "message"; final String causeMessage = "cause"; final SerializedThrowable serializedThrowable = new SerializedThrowable( new RuntimeException(lastExceptionMessage, new RuntimeException(causeMessage))); final String json = objectMapper.writeValueAsString(serializedThrowable); final SerializedThrowable deserializedSerializedThrowable = objectMapper.readValue( json, SerializedThrowable.class); assertThat(deserializedSerializedThrowable.getMessage(), equalTo(lastExceptionMessage)); assertThat(deserializedSerializedThrowable.getFullStringifiedStackTrace(), equalTo(serializedThrowable.getFullStringifiedStackTrace())); assertThat(deserializedSerializedThrowable.getCause().getMessage(), equalTo(causeMessage)); assertThat(deserializedSerializedThrowable.getCause(), instanceOf(SerializedThrowable.class)); }
Example #4
Source File: SerializedThrowableTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testIdenticalMessageAndStack() { try { IllegalArgumentException original = new IllegalArgumentException("test message"); SerializedThrowable serialized = new SerializedThrowable(original); assertEquals(original.getMessage(), serialized.getMessage()); assertEquals(original.toString(), serialized.toString()); assertEquals(ExceptionUtils.stringifyException(original), ExceptionUtils.stringifyException(serialized)); assertArrayEquals(original.getStackTrace(), serialized.getStackTrace()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #5
Source File: JobExecutionResultResponseBodyTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Parameterized.Parameters public static Collection<Object[]> data() throws IOException { return Arrays.asList(new Object[][] { {JobExecutionResultResponseBody.created(new JobResult.Builder() .jobId(TEST_JOB_ID) .applicationStatus(ApplicationStatus.SUCCEEDED) .netRuntime(TEST_NET_RUNTIME) .accumulatorResults(TEST_ACCUMULATORS) .serializedThrowable(new SerializedThrowable(new RuntimeException("expected"))) .build())}, {JobExecutionResultResponseBody.created(new JobResult.Builder() .jobId(TEST_JOB_ID) .applicationStatus(ApplicationStatus.FAILED) .netRuntime(TEST_NET_RUNTIME) .accumulatorResults(TEST_ACCUMULATORS) .build())}, {JobExecutionResultResponseBody.inProgress()} }); }
Example #6
Source File: SerializedThrowableTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testIdenticalMessageAndStack() { try { IllegalArgumentException original = new IllegalArgumentException("test message"); SerializedThrowable serialized = new SerializedThrowable(original); assertEquals(original.getMessage(), serialized.getMessage()); assertEquals(original.toString(), serialized.toString()); assertEquals(ExceptionUtils.stringifyException(original), ExceptionUtils.stringifyException(serialized)); assertArrayEquals(original.getStackTrace(), serialized.getStackTrace()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #7
Source File: RestClusterClientSavepointTriggerTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTriggerSavepointFailure() throws Exception { final TriggerId triggerId = new TriggerId(); try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint( request -> triggerId, trigger -> new SavepointInfo(null, new SerializedThrowable(new RuntimeException("expected"))))) { final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort()); try { restClusterClient.triggerSavepoint(new JobID(), null).get(); } catch (ExecutionException e) { final Throwable cause = e.getCause(); assertThat(cause, instanceOf(SerializedThrowable.class)); assertThat(((SerializedThrowable) cause) .deserializeError(ClassLoader.getSystemClassLoader()) .getMessage(), equalTo("expected")); } } }
Example #8
Source File: SerializedThrowableSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testSerializationDeserialization() throws Exception { final String lastExceptionMessage = "message"; final String causeMessage = "cause"; final SerializedThrowable serializedThrowable = new SerializedThrowable( new RuntimeException(lastExceptionMessage, new RuntimeException(causeMessage))); final String json = objectMapper.writeValueAsString(serializedThrowable); final SerializedThrowable deserializedSerializedThrowable = objectMapper.readValue( json, SerializedThrowable.class); assertThat(deserializedSerializedThrowable.getMessage(), equalTo(lastExceptionMessage)); assertThat(deserializedSerializedThrowable.getFullStringifiedStackTrace(), equalTo(serializedThrowable.getFullStringifiedStackTrace())); assertThat(deserializedSerializedThrowable.getCause().getMessage(), equalTo(causeMessage)); assertThat(deserializedSerializedThrowable.getCause(), instanceOf(SerializedThrowable.class)); }
Example #9
Source File: TaskExecutionState.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a new task execution state update, with an attached exception. * This constructor may never throw an exception. * * @param jobID * the ID of the job the task belongs to * @param executionId * the ID of the task execution whose state is to be reported * @param executionState * the execution state to be reported * @param error * an optional error * @param accumulators * The flink and user-defined accumulators which may be null. */ public TaskExecutionState(JobID jobID, ExecutionAttemptID executionId, ExecutionState executionState, Throwable error, AccumulatorSnapshot accumulators, IOMetrics ioMetrics) { if (jobID == null || executionId == null || executionState == null) { throw new NullPointerException(); } this.jobID = jobID; this.executionId = executionId; this.executionState = executionState; if (error != null) { this.throwable = new SerializedThrowable(error); } else { this.throwable = null; } this.accumulators = accumulators; this.ioMetrics = ioMetrics; }
Example #10
Source File: SerializedThrowableTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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()); }
Example #11
Source File: SerializedThrowableTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testIdenticalMessageAndStack() { try { IllegalArgumentException original = new IllegalArgumentException("test message"); SerializedThrowable serialized = new SerializedThrowable(original); assertEquals(original.getMessage(), serialized.getMessage()); assertEquals(original.toString(), serialized.toString()); assertEquals(ExceptionUtils.stringifyException(original), ExceptionUtils.stringifyException(serialized)); assertArrayEquals(original.getStackTrace(), serialized.getStackTrace()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example #12
Source File: DeclineCheckpoint.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public DeclineCheckpoint(JobID job, ExecutionAttemptID taskExecutionId, long checkpointId, Throwable reason) { super(job, taskExecutionId, checkpointId); if (reason == null || reason.getClass() == AlignmentLimitExceededException.class || reason.getClass() == CheckpointDeclineOnCancellationBarrierException.class || reason.getClass() == CheckpointDeclineSubsumedException.class || reason.getClass() == CheckpointDeclineTaskNotCheckpointingException.class || reason.getClass() == CheckpointDeclineTaskNotReadyException.class || reason.getClass() == InputEndOfStreamException.class) { // null or known common exceptions that cannot reference any dynamically loaded code this.reason = reason; } else { // some other exception. replace with a serialized throwable, to be on the safe side this.reason = new SerializedThrowable(reason); } }
Example #13
Source File: TaskExecutionState.java From flink with Apache License 2.0 | 6 votes |
/** * Creates a new task execution state update, with an attached exception. * This constructor may never throw an exception. * * @param jobID * the ID of the job the task belongs to * @param executionId * the ID of the task execution whose state is to be reported * @param executionState * the execution state to be reported * @param error * an optional error * @param accumulators * The flink and user-defined accumulators which may be null. */ public TaskExecutionState(JobID jobID, ExecutionAttemptID executionId, ExecutionState executionState, Throwable error, AccumulatorSnapshot accumulators, IOMetrics ioMetrics) { if (jobID == null || executionId == null || executionState == null) { throw new NullPointerException(); } this.jobID = jobID; this.executionId = executionId; this.executionState = executionState; if (error != null) { this.throwable = new SerializedThrowable(error); } else { this.throwable = null; } this.accumulators = accumulators; this.ioMetrics = ioMetrics; }
Example #14
Source File: ExecutionGraph.java From flink with Apache License 2.0 | 5 votes |
private void notifyJobStatusChange(JobStatus newState, Throwable error) { if (jobStatusListeners.size() > 0) { final long timestamp = System.currentTimeMillis(); final Throwable serializedError = error == null ? null : new SerializedThrowable(error); for (JobStatusListener listener : jobStatusListeners) { try { listener.jobStatusChanges(getJobID(), newState, timestamp, serializedError); } catch (Throwable t) { LOG.warn("Error while notifying JobStatusListener", t); } } } }
Example #15
Source File: ApplicationDispatcherBootstrapTest.java From flink with Apache License 2.0 | 5 votes |
private static JobResult createFailedJobResult(final JobID jobId) { return new JobResult.Builder() .jobId(jobId) .netRuntime(2L) .applicationStatus(ApplicationStatus.FAILED) .serializedThrowable(new SerializedThrowable(new JobExecutionException(jobId, "bla bla bla"))) .build(); }
Example #16
Source File: CheckpointException.java From flink with Apache License 2.0 | 5 votes |
public CheckpointException(CheckpointFailureReason failureReason, Throwable cause) { // Defensively replace the cause with a SerializedThrowable in case it's a user-defined exception // that doesn't exist on the JobManager's default classpath. super( failureReason.message(), cause == null ? null : new SerializedThrowable(cause)); this.checkpointFailureReason = Preconditions.checkNotNull(failureReason); }
Example #17
Source File: CheckpointException.java From flink with Apache License 2.0 | 5 votes |
public CheckpointException(String message, CheckpointFailureReason failureReason, Throwable cause) { // Defensively replace the cause with a SerializedThrowable in case it's a user-defined exception // that doesn't exist on the JobManager's default classpath. super( message + " Failure reason: " + failureReason.message(), cause == null ? null : new SerializedThrowable(cause)); this.checkpointFailureReason = Preconditions.checkNotNull(failureReason); }
Example #18
Source File: SerializedThrowableSerializer.java From flink with Apache License 2.0 | 5 votes |
@Override public void serialize(final SerializedThrowable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException { gen.writeStartObject(); gen.writeStringField(FIELD_NAME_CLASS, value.getOriginalErrorClassName()); gen.writeStringField(FIELD_NAME_STACK_TRACE, value.getFullStringifiedStackTrace()); gen.writeBinaryField(FIELD_NAME_SERIALIZED_THROWABLE, InstantiationUtil.serializeObject(value)); gen.writeEndObject(); }
Example #19
Source File: JobExecutionResultResponseBodyTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected void assertOriginalEqualsToUnmarshalled( final JobExecutionResultResponseBody expected, final JobExecutionResultResponseBody actual) { assertThat(actual.getStatus(), equalTo(actual.getStatus())); final JobResult expectedJobExecutionResult = expected.getJobExecutionResult(); final JobResult actualJobExecutionResult = actual.getJobExecutionResult(); if (expectedJobExecutionResult != null) { assertNotNull(actualJobExecutionResult); assertThat(actualJobExecutionResult.getJobId(), equalTo(expectedJobExecutionResult.getJobId())); assertThat(actualJobExecutionResult.getApplicationStatus(), equalTo(expectedJobExecutionResult.getApplicationStatus())); assertThat(actualJobExecutionResult.getNetRuntime(), equalTo(expectedJobExecutionResult.getNetRuntime())); assertThat(actualJobExecutionResult.getAccumulatorResults(), equalTo(expectedJobExecutionResult.getAccumulatorResults())); final Optional<SerializedThrowable> expectedFailureCauseOptional = expectedJobExecutionResult.getSerializedThrowable(); expectedFailureCauseOptional.ifPresent(expectedFailureCause -> { final SerializedThrowable actualFailureCause = actualJobExecutionResult.getSerializedThrowable() .orElseThrow(() -> new AssertionError("actualFailureCause is not available")); assertThat(actualFailureCause.getFullStringifiedStackTrace(), equalTo(expectedFailureCause.getFullStringifiedStackTrace())); assertThat(actualFailureCause.getOriginalErrorClassName(), equalTo(expectedFailureCause.getOriginalErrorClassName())); assertArrayEquals(expectedFailureCause.getSerializedException(), actualFailureCause.getSerializedException()); }); if (expectedJobExecutionResult.getAccumulatorResults() != null) { assertNotNull(actualJobExecutionResult.getAccumulatorResults()); assertArrayEquals( actualJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray(), expectedJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray()); } } }
Example #20
Source File: SavepointInfo.java From flink with Apache License 2.0 | 5 votes |
@JsonCreator public SavepointInfo( @JsonProperty(FIELD_NAME_LOCATION) @Nullable final String location, @JsonProperty(FIELD_NAME_FAILURE_CAUSE) @JsonDeserialize(using = SerializedThrowableDeserializer.class) @Nullable final SerializedThrowable failureCause) { checkArgument( location != null ^ failureCause != null, "Either location or failureCause must be set"); this.location = location; this.failureCause = failureCause; }
Example #21
Source File: SerializedThrowableDeserializer.java From flink with Apache License 2.0 | 5 votes |
@Override public SerializedThrowable deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { final JsonNode root = p.readValueAsTree(); final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue(); try { return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e); } }
Example #22
Source File: ProducerFailedExceptionTest.java From flink with Apache License 2.0 | 5 votes |
@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); }
Example #23
Source File: SavepointInfoTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSetBothLocationAndFailureCause() { try { new SavepointInfo( "/tmp", new SerializedThrowable(new RuntimeException())); fail("Expected exception not thrown"); } catch (IllegalArgumentException e) { } }
Example #24
Source File: JobExecutionResultResponseBodyTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected void assertOriginalEqualsToUnmarshalled( final JobExecutionResultResponseBody expected, final JobExecutionResultResponseBody actual) { assertThat(actual.getStatus(), equalTo(actual.getStatus())); final JobResult expectedJobExecutionResult = expected.getJobExecutionResult(); final JobResult actualJobExecutionResult = actual.getJobExecutionResult(); if (expectedJobExecutionResult != null) { assertNotNull(actualJobExecutionResult); assertThat(actualJobExecutionResult.getJobId(), equalTo(expectedJobExecutionResult.getJobId())); assertThat(actualJobExecutionResult.getApplicationStatus(), equalTo(expectedJobExecutionResult.getApplicationStatus())); assertThat(actualJobExecutionResult.getNetRuntime(), equalTo(expectedJobExecutionResult.getNetRuntime())); assertThat(actualJobExecutionResult.getAccumulatorResults(), equalTo(expectedJobExecutionResult.getAccumulatorResults())); final Optional<SerializedThrowable> expectedFailureCauseOptional = expectedJobExecutionResult.getSerializedThrowable(); expectedFailureCauseOptional.ifPresent(expectedFailureCause -> { final SerializedThrowable actualFailureCause = actualJobExecutionResult.getSerializedThrowable() .orElseThrow(() -> new AssertionError("actualFailureCause is not available")); assertThat(actualFailureCause.getFullStringifiedStackTrace(), equalTo(expectedFailureCause.getFullStringifiedStackTrace())); assertThat(actualFailureCause.getOriginalErrorClassName(), equalTo(expectedFailureCause.getOriginalErrorClassName())); assertArrayEquals(expectedFailureCause.getSerializedException(), actualFailureCause.getSerializedException()); }); if (expectedJobExecutionResult.getAccumulatorResults() != null) { assertNotNull(actualJobExecutionResult.getAccumulatorResults()); assertArrayEquals( actualJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray(), expectedJobExecutionResult.getAccumulatorResults().get(TEST_ACCUMULATOR_NAME).getByteArray()); } } }
Example #25
Source File: JobResultTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testIsNotSuccess() throws Exception { final JobResult jobResult = new JobResult.Builder() .jobId(new JobID()) .serializedThrowable(new SerializedThrowable(new RuntimeException())) .netRuntime(Long.MAX_VALUE) .build(); assertThat(jobResult.isSuccess(), equalTo(false)); }
Example #26
Source File: ExecutionGraph.java From flink with Apache License 2.0 | 5 votes |
private void notifyJobStatusChange(JobStatus newState, Throwable error) { if (jobStatusListeners.size() > 0) { final long timestamp = System.currentTimeMillis(); final Throwable serializedError = error == null ? null : new SerializedThrowable(error); for (JobStatusListener listener : jobStatusListeners) { try { listener.jobStatusChanges(getJobID(), newState, timestamp, serializedError); } catch (Throwable t) { LOG.warn("Error while notifying JobStatusListener", t); } } } }
Example #27
Source File: SerializedThrowableSerializer.java From flink with Apache License 2.0 | 5 votes |
@Override public void serialize(final SerializedThrowable value, final JsonGenerator gen, final SerializerProvider provider) throws IOException { gen.writeStartObject(); gen.writeStringField(FIELD_NAME_CLASS, value.getOriginalErrorClassName()); gen.writeStringField(FIELD_NAME_STACK_TRACE, value.getFullStringifiedStackTrace()); gen.writeBinaryField(FIELD_NAME_SERIALIZED_THROWABLE, InstantiationUtil.serializeObject(value)); gen.writeEndObject(); }
Example #28
Source File: JobResult.java From flink with Apache License 2.0 | 5 votes |
private JobResult( final JobID jobId, final ApplicationStatus applicationStatus, final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults, final long netRuntime, @Nullable final SerializedThrowable serializedThrowable) { checkArgument(netRuntime >= 0, "netRuntime must be greater than or equals 0"); this.jobId = requireNonNull(jobId); this.applicationStatus = requireNonNull(applicationStatus); this.accumulatorResults = requireNonNull(accumulatorResults); this.netRuntime = netRuntime; this.serializedThrowable = serializedThrowable; }
Example #29
Source File: SerializedThrowableDeserializer.java From flink with Apache License 2.0 | 5 votes |
@Override public SerializedThrowable deserialize( final JsonParser p, final DeserializationContext ctxt) throws IOException { final JsonNode root = p.readValueAsTree(); final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue(); try { return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader()); } catch (ClassNotFoundException e) { throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e); } }
Example #30
Source File: DeclineCheckpoint.java From flink with Apache License 2.0 | 5 votes |
public DeclineCheckpoint(JobID job, ExecutionAttemptID taskExecutionId, long checkpointId, Throwable reason) { super(job, taskExecutionId, checkpointId); if (reason == null || reason instanceof CheckpointException) { this.reason = reason; } else { // some other exception. replace with a serialized throwable, to be on the safe side this.reason = new SerializedThrowable(reason); } }