Search in sources :

Example 1 with MAP_2

use of org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_2 in project flink by apache.

the class RestoreUpgradedJobITCase method runUpgradedJob.

private void runUpgradedJob(String snapshotPath) throws Exception {
    StreamExecutionEnvironment env;
    Configuration conf = new Configuration();
    conf.set(SavepointConfigOptions.SAVEPOINT_PATH, snapshotPath);
    env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
    env.setParallelism(PARALLELISM);
    env.addSource(new StringSource(allDataEmittedLatch)).map(new StringMap(MAP_1.id())).uid(MAP_1.name()).forward().map(new StringMap(MAP_2.id())).uid(MAP_2.name()).slotSharingGroup("anotherSharingGroup").keyBy((key) -> key).map(new StringMap(MAP_3.id())).uid(MAP_3.name()).map(new StringMap(-1)).uid("new_chained_map").rebalance().map(new StringMap(-2)).uid("new_map2").map(new StringMap(MAP_4.id())).uid(MAP_4.name()).rescale().map(new StringMap(MAP_5.id())).uid(MAP_5.name()).broadcast().map(new StringMap(MAP_6.id())).uid(MAP_6.name()).addSink(new StringSink(result)).setParallelism(1);
    JobClient jobClient = env.executeAsync("Total sum");
    waitForAllTaskRunning(CLUSTER.getMiniCluster(), jobClient.getJobID(), false);
    allDataEmittedLatch.get().await();
    // Using stopWithSavepoint to be sure that all values reached the sink.
    jobClient.stopWithSavepoint(true, temporaryFolder.getRoot().getAbsolutePath(), SavepointFormatType.CANONICAL).get();
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) MAP_1(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_1) RunWith(org.junit.runner.RunWith) MAP_2(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_2) MAP_3(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_3) SavepointConfigOptions(org.apache.flink.runtime.jobgraph.SavepointConfigOptions) MAP_4(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_4) MAP_5(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_5) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MAP_6(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_6) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) CANONICAL_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.CANONICAL_SAVEPOINT) CommonTestUtils.waitForAllTaskRunning(org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) TestLogger(org.apache.flink.util.TestLogger) ALIGNED_CHECKPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.ALIGNED_CHECKPOINT) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ClassRule(org.junit.ClassRule) SharedReference(org.apache.flink.testutils.junit.SharedReference) Parameterized(org.junit.runners.Parameterized) Types(org.apache.flink.api.common.typeinfo.Types) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) Iterator(java.util.Iterator) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) JobClient(org.apache.flink.core.execution.JobClient) ExecutionException(java.util.concurrent.ExecutionException) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) NATIVE_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.NATIVE_SAVEPOINT) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) TemporaryFolder(org.junit.rules.TemporaryFolder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobClient(org.apache.flink.core.execution.JobClient)

Example 2 with MAP_2

use of org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_2 in project flink by apache.

the class RestoreUpgradedJobITCase method runOriginalJob.

@NotNull
private String runOriginalJob() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.getCheckpointConfig().setExternalizedCheckpointCleanup(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
    env.getCheckpointConfig().enableUnalignedCheckpoints(false);
    env.getCheckpointConfig().setCheckpointStorage("file://" + temporaryFolder.getRoot().getAbsolutePath());
    env.setParallelism(PARALLELISM);
    env.enableCheckpointing(Integer.MAX_VALUE);
    // Different order of maps before and after savepoint.
    env.addSource(new IntSource(allDataEmittedLatch)).map(new IntMap(MAP_5.id())).uid(MAP_5.name()).forward().map(new IntMap(MAP_1.id())).uid(MAP_1.name()).slotSharingGroup("anotherSharingGroup").keyBy((key) -> key).map(new IntMap(MAP_6.id())).uid(MAP_6.name()).rebalance().map(new IntMap(MAP_4.id())).uid(MAP_4.name()).broadcast().map(new IntMap(MAP_2.id())).uid(MAP_2.name()).rescale().map(new IntMap(MAP_3.id())).uid(MAP_3.name()).addSink(new IntSink(result)).setParallelism(1);
    // when: Job is executed.
    JobClient jobClient = env.executeAsync("Total sum");
    waitForAllTaskRunning(CLUSTER.getMiniCluster(), jobClient.getJobID(), false);
    allDataEmittedLatch.get().await();
    allDataEmittedLatch.get().reset();
    return stopWithSnapshot(jobClient);
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) MAP_1(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_1) RunWith(org.junit.runner.RunWith) MAP_2(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_2) MAP_3(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_3) SavepointConfigOptions(org.apache.flink.runtime.jobgraph.SavepointConfigOptions) MAP_4(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_4) MAP_5(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_5) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MAP_6(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.MapName.MAP_6) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) CANONICAL_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.CANONICAL_SAVEPOINT) CommonTestUtils.waitForAllTaskRunning(org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) TestLogger(org.apache.flink.util.TestLogger) ALIGNED_CHECKPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.ALIGNED_CHECKPOINT) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ClassRule(org.junit.ClassRule) SharedReference(org.apache.flink.testutils.junit.SharedReference) Parameterized(org.junit.runners.Parameterized) Types(org.apache.flink.api.common.typeinfo.Types) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) Iterator(java.util.Iterator) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) Configuration(org.apache.flink.configuration.Configuration) Test(org.junit.Test) JobClient(org.apache.flink.core.execution.JobClient) ExecutionException(java.util.concurrent.ExecutionException) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) NATIVE_SAVEPOINT(org.apache.flink.test.checkpointing.RestoreUpgradedJobITCase.TestCheckpointType.NATIVE_SAVEPOINT) Matchers.is(org.hamcrest.Matchers.is) NotNull(org.jetbrains.annotations.NotNull) TemporaryFolder(org.junit.rules.TemporaryFolder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobClient(org.apache.flink.core.execution.JobClient) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Iterator (java.util.Iterator)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 LockSupport (java.util.concurrent.locks.LockSupport)2 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)2 ListState (org.apache.flink.api.common.state.ListState)2 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)2 Types (org.apache.flink.api.common.typeinfo.Types)2 Configuration (org.apache.flink.configuration.Configuration)2 JobClient (org.apache.flink.core.execution.JobClient)2 SavepointFormatType (org.apache.flink.core.execution.SavepointFormatType)2 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)2 SavepointConfigOptions (org.apache.flink.runtime.jobgraph.SavepointConfigOptions)2 FunctionInitializationContext (org.apache.flink.runtime.state.FunctionInitializationContext)2 FunctionSnapshotContext (org.apache.flink.runtime.state.FunctionSnapshotContext)2 CommonTestUtils.waitForAllTaskRunning (org.apache.flink.runtime.testutils.CommonTestUtils.waitForAllTaskRunning)2 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)2 CheckpointedFunction (org.apache.flink.streaming.api.checkpoint.CheckpointedFunction)2 CheckpointConfig (org.apache.flink.streaming.api.environment.CheckpointConfig)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2