use of org.apache.flink.streaming.api.functions.sink.PrintSinkFunction in project flink by apache.
the class StickyAllocationAndLocalRecoveryTestJob method main.
public static void main(String[] args) throws Exception {
final ParameterTool pt = ParameterTool.fromArgs(args);
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(pt.getInt("parallelism", 1));
env.setMaxParallelism(pt.getInt("maxParallelism", pt.getInt("parallelism", 1)));
env.enableCheckpointing(pt.getInt("checkpointInterval", 1000));
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, pt.getInt("restartDelay", 0)));
if (pt.getBoolean("externalizedCheckpoints", false)) {
env.getCheckpointConfig().setExternalizedCheckpointCleanup(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
}
String checkpointDir = pt.getRequired("checkpointDir");
env.getCheckpointConfig().setCheckpointStorage(checkpointDir);
boolean killJvmOnFail = pt.getBoolean("killJvmOnFail", false);
String stateBackend = pt.get("stateBackend", "hashmap");
if ("hashmap".equals(stateBackend)) {
env.setStateBackend(new HashMapStateBackend());
} else if ("rocks".equals(stateBackend)) {
boolean incrementalCheckpoints = pt.getBoolean("incrementalCheckpoints", false);
env.setStateBackend(new EmbeddedRocksDBStateBackend(incrementalCheckpoints));
} else {
throw new IllegalArgumentException("Unknown backend: " + stateBackend);
}
// make parameters available in the web interface
env.getConfig().setGlobalJobParameters(pt);
// delay to throttle down the production of the source
long delay = pt.getLong("delay", 0L);
// the maximum number of attempts, before the job finishes with success
int maxAttempts = pt.getInt("maxAttempts", 3);
// size of one artificial value
int valueSize = pt.getInt("valueSize", 10);
env.addSource(new RandomLongSource(maxAttempts, delay)).keyBy((KeySelector<Long, Long>) aLong -> aLong).flatMap(new StateCreatingFlatMap(valueSize, killJvmOnFail)).addSink(new PrintSinkFunction<>());
env.execute("Sticky Allocation And Local Recovery Test");
}
use of org.apache.flink.streaming.api.functions.sink.PrintSinkFunction in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkStdOut.
@Test
public void testPrintSinkStdOut() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>();
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.out", printSink.toString());
assertEquals("hello world!" + line, arrayOutputStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.api.functions.sink.PrintSinkFunction in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkWithPrefix.
@Test
public void testPrintSinkWithPrefix() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>();
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 2, 1));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.out", printSink.toString());
assertEquals("2> hello world!" + line, arrayOutputStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.api.functions.sink.PrintSinkFunction in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkStdErr.
@Test
public void testPrintSinkStdErr() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>(true);
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.err", printSink.toString());
assertEquals("hello world!" + line, arrayErrorStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.api.functions.sink.PrintSinkFunction in project flink by apache.
the class DataStreamStateTTLTestProgram method main.
public static void main(String[] args) throws Exception {
final ParameterTool pt = ParameterTool.fromArgs(args);
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
setupEnvironment(env, pt);
setBackendWithCustomTTLTimeProvider(env);
TtlTestConfig config = TtlTestConfig.fromArgs(pt);
StateTtlConfig ttlConfig = StateTtlConfig.newBuilder(config.ttl).cleanupFullSnapshot().build();
env.addSource(new TtlStateUpdateSource(config.keySpace, config.sleepAfterElements, config.sleepTime)).name("TtlStateUpdateSource").keyBy(TtlStateUpdate::getKey).flatMap(new TtlVerifyUpdateFunction(ttlConfig, config.reportStatAfterUpdatesNum)).name("TtlVerifyUpdateFunction").addSink(new PrintSinkFunction<>()).name("PrintFailedVerifications");
env.execute("State TTL test job");
}
Aggregations