Search in sources :

Example 1 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class CheckpointResourcesCleanupRunnerTest method testResultFutureWithErrorAfterStart.

private static void testResultFutureWithErrorAfterStart(ThrowingConsumer<CheckpointResourcesCleanupRunner, ? extends Exception> preCheckLifecycleHandling) throws Exception {
    final SerializedThrowable expectedError = new SerializedThrowable(new Exception("Expected exception"));
    final CompletableFuture<JobManagerRunnerResult> actualResult = getResultFutureFromTestInstance(createJobResultWithFailure(expectedError), preCheckLifecycleHandling);
    assertThat(actualResult).isCompletedWithValueMatching(jobManagerRunnerResult -> Objects.requireNonNull(jobManagerRunnerResult.getExecutionGraphInfo().getArchivedExecutionGraph().getFailureInfo()).getException().equals(expectedError), "JobManagerRunner should have failed with expected error");
}
Also used : JobManagerRunnerResult(org.apache.flink.runtime.jobmaster.JobManagerRunnerResult) FlinkException(org.apache.flink.util.FlinkException) ExecutionException(java.util.concurrent.ExecutionException) UnavailableDispatcherOperationException(org.apache.flink.runtime.dispatcher.UnavailableDispatcherOperationException) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 2 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class CheckpointResourcesCleanupRunnerTest method testResultFutureWithErrorBeforeStart.

@Test
public void testResultFutureWithErrorBeforeStart() throws Exception {
    final CompletableFuture<JobManagerRunnerResult> resultFuture = getResultFutureFromTestInstance(createJobResultWithFailure(new SerializedThrowable(new Exception("Expected exception"))), BEFORE_START);
    assertThat(resultFuture).isNotCompleted();
}
Also used : JobManagerRunnerResult(org.apache.flink.runtime.jobmaster.JobManagerRunnerResult) FlinkException(org.apache.flink.util.FlinkException) ExecutionException(java.util.concurrent.ExecutionException) UnavailableDispatcherOperationException(org.apache.flink.runtime.dispatcher.UnavailableDispatcherOperationException) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.jupiter.api.Test)

Example 3 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class SerializedThrowableDeserializer method deserialize.

@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);
    }
}
Also used : JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 4 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class RestClusterClientTest method testDisposeSavepoint.

@Test
public void testDisposeSavepoint() throws Exception {
    final String savepointPath = "foobar";
    final String exceptionMessage = "Test exception.";
    final FlinkException testException = new FlinkException(exceptionMessage);
    final TestSavepointDisposalHandlers testSavepointDisposalHandlers = new TestSavepointDisposalHandlers(savepointPath);
    final TestSavepointDisposalHandlers.TestSavepointDisposalTriggerHandler testSavepointDisposalTriggerHandler = testSavepointDisposalHandlers.new TestSavepointDisposalTriggerHandler();
    final TestSavepointDisposalHandlers.TestSavepointDisposalStatusHandler testSavepointDisposalStatusHandler = testSavepointDisposalHandlers.new TestSavepointDisposalStatusHandler(OptionalFailure.of(AsynchronousOperationInfo.complete()), OptionalFailure.of(AsynchronousOperationInfo.completeExceptional(new SerializedThrowable(testException))), OptionalFailure.ofFailure(testException));
    try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(testSavepointDisposalStatusHandler, testSavepointDisposalTriggerHandler)) {
        RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        try {
            {
                final CompletableFuture<Acknowledge> disposeSavepointFuture = restClusterClient.disposeSavepoint(savepointPath);
                assertThat(disposeSavepointFuture.get(), is(Acknowledge.get()));
            }
            {
                final CompletableFuture<Acknowledge> disposeSavepointFuture = restClusterClient.disposeSavepoint(savepointPath);
                try {
                    disposeSavepointFuture.get();
                    fail("Expected an exception");
                } catch (ExecutionException ee) {
                    assertThat(ExceptionUtils.findThrowableWithMessage(ee, exceptionMessage).isPresent(), is(true));
                }
            }
            {
                try {
                    restClusterClient.disposeSavepoint(savepointPath).get();
                    fail("Expected an exception.");
                } catch (ExecutionException ee) {
                    assertThat(ExceptionUtils.findThrowable(ee, RestClientException.class).isPresent(), is(true));
                }
            }
        } finally {
            restClusterClient.close();
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Test(org.junit.Test)

Example 5 with SerializedThrowable

use of org.apache.flink.util.SerializedThrowable in project flink by apache.

the class WritableSavepointITCase method validateModification.

private void validateModification(StateBackend backend, String savepointPath) throws Exception {
    StreamExecutionEnvironment sEnv = StreamExecutionEnvironment.getExecutionEnvironment();
    sEnv.setStateBackend(backend);
    DataStream<Account> stream = sEnv.fromCollection(accounts).keyBy(acc -> acc.id).flatMap(new UpdateAndGetAccount()).uid(ACCOUNT_UID);
    CompletableFuture<Collection<Account>> results = collector.collect(stream);
    stream.map(acc -> acc.id).map(new StatefulOperator()).uid(MODIFY_UID).addSink(new DiscardingSink<>());
    JobGraph jobGraph = sEnv.getStreamGraph().getJobGraph();
    jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepointPath, false));
    ClusterClient<?> client = MINI_CLUSTER_RESOURCE.getClusterClient();
    Optional<SerializedThrowable> serializedThrowable = client.submitJob(jobGraph).thenCompose(client::requestJobResult).get().getSerializedThrowable();
    Assert.assertFalse(serializedThrowable.isPresent());
    Assert.assertEquals("Unexpected output", 3, results.get().size());
}
Also used : RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) Arrays(java.util.Arrays) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) EmbeddedRocksDBStateBackend(org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend) ArrayList(java.util.ArrayList) StateBootstrapFunction(org.apache.flink.state.api.functions.StateBootstrapFunction) HashSet(java.util.HashSet) ListState(org.apache.flink.api.common.state.ListState) DataSet(org.apache.flink.api.java.DataSet) StateBackend(org.apache.flink.runtime.state.StateBackend) StreamCollector(org.apache.flink.streaming.util.StreamCollector) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) Collector(org.apache.flink.util.Collector) KeyedStateBootstrapFunction(org.apache.flink.state.api.functions.KeyedStateBootstrapFunction) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) AbstractTestBase(org.apache.flink.test.util.AbstractTestBase) Types(org.apache.flink.api.common.typeinfo.Types) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) DiscardingSink(org.apache.flink.streaming.api.functions.sink.DiscardingSink) AbstractID(org.apache.flink.util.AbstractID) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) Set(java.util.Set) Test(org.junit.Test) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend) RocksDBStateBackend(org.apache.flink.contrib.streaming.state.RocksDBStateBackend) DataStream(org.apache.flink.streaming.api.datastream.DataStream) Objects(java.util.Objects) List(java.util.List) Rule(org.junit.Rule) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ValueState(org.apache.flink.api.common.state.ValueState) ClusterClient(org.apache.flink.client.program.ClusterClient) BroadcastProcessFunction(org.apache.flink.streaming.api.functions.co.BroadcastProcessFunction) HashMapStateBackend(org.apache.flink.runtime.state.hashmap.HashMapStateBackend) BroadcastStateBootstrapFunction(org.apache.flink.state.api.functions.BroadcastStateBootstrapFunction) SerializedThrowable(org.apache.flink.util.SerializedThrowable) Optional(java.util.Optional) Assert(org.junit.Assert) SavepointRestoreSettings(org.apache.flink.runtime.jobgraph.SavepointRestoreSettings) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Collection(java.util.Collection) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Aggregations

SerializedThrowable (org.apache.flink.util.SerializedThrowable)30 Test (org.junit.Test)16 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)6 FlinkException (org.apache.flink.util.FlinkException)6 ExecutionException (java.util.concurrent.ExecutionException)5 Collection (java.util.Collection)4 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)4 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 UnavailableDispatcherOperationException (org.apache.flink.runtime.dispatcher.UnavailableDispatcherOperationException)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 RichFlatMapFunction (org.apache.flink.api.common.functions.RichFlatMapFunction)2 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)2 ListState (org.apache.flink.api.common.state.ListState)2