Search in sources :

Example 6 with MasterTriggerRestoreHook

use of org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook in project flink by apache.

the class WithMasterCheckpointHookConfigTest method testHookConfiguration.

/**
 * This test creates a program with 4 sources (2 with master hooks, 2 without). The resulting
 * job graph must have 2 configured master hooks.
 */
@Test
public void testHookConfiguration() throws Exception {
    // create some sources some of which configure master hooks
    final TestSource source1 = new TestSource();
    final TestSourceWithHook source2 = new TestSourceWithHook("foo");
    final TestSource source3 = new TestSource();
    final TestSourceWithHook source4 = new TestSourceWithHook("bar");
    final MapFunction<String, String> identity = new Identity<>();
    final IdentityWithHook<String> identityWithHook1 = new IdentityWithHook<>("apple");
    final IdentityWithHook<String> identityWithHook2 = new IdentityWithHook<>("orange");
    final Set<MasterTriggerRestoreHook<?>> hooks = new HashSet<MasterTriggerRestoreHook<?>>(asList(source2.createMasterTriggerRestoreHook(), source4.createMasterTriggerRestoreHook(), identityWithHook1.createMasterTriggerRestoreHook(), identityWithHook2.createMasterTriggerRestoreHook()));
    // we can instantiate a local environment here, because we never actually execute something
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment();
    env.enableCheckpointing(500);
    env.addSource(source1).map(identity).union(env.addSource(source2).map(identity)).union(env.addSource(source3).map(identityWithHook1)).union(env.addSource(source4).map(identityWithHook2)).addSink(new DiscardingSink<String>());
    final JobGraph jg = env.getStreamGraph().getJobGraph();
    SerializedValue<Factory[]> serializedConfiguredHooks = jg.getCheckpointingSettings().getMasterHooks();
    assertNotNull(serializedConfiguredHooks);
    Factory[] configuredHooks = serializedConfiguredHooks.deserializeValue(getClass().getClassLoader());
    assertEquals(hooks.size(), configuredHooks.length);
    // check that all hooks are contained and exist exactly once
    for (Factory f : configuredHooks) {
        MasterTriggerRestoreHook<?> hook = f.create();
        assertTrue(hooks.remove(hook));
    }
    assertTrue(hooks.isEmpty());
}
Also used : Factory(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook.Factory) MasterTriggerRestoreHook(org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MasterTriggerRestoreHook (org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook)6 ArrayList (java.util.ArrayList)3 FlinkException (org.apache.flink.util.FlinkException)3 LinkedHashMap (java.util.LinkedHashMap)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 MasterState (org.apache.flink.runtime.checkpoint.MasterState)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Executor (java.util.concurrent.Executor)1 Nullable (javax.annotation.Nullable)1 JobID (org.apache.flink.api.common.JobID)1 SimpleVersionedSerializer (org.apache.flink.core.io.SimpleVersionedSerializer)1 JobException (org.apache.flink.runtime.JobException)1 Factory (org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook.Factory)1 JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)1