/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.flink.stormcompatibility.wordcount; import org.apache.flink.api.java.tuple.Tuple0; import org.apache.flink.configuration.Configuration; import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction; import org.apache.flink.streaming.api.operators.OneInputStreamOperator; import org.apache.flink.streaming.api.operators.Output; import org.apache.flink.streaming.api.watermark.Watermark; import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; import org.apache.flink.streaming.runtime.tasks.StreamingRuntimeContext; public class TestEmptyTuple { public static void main(String[] args) throws Exception { final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream input = env.addSource(new Empty()).setParallelism(4); input.shuffle().transform("verify", null, new Counter()).setParallelism(1); env.execute(); } public static class Empty implements ParallelSourceFunction { private static final long serialVersionUID = 1350902748274781033L; private volatile boolean isRunning = true; @Override public void run( org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext ctx) throws Exception { while (this.isRunning) { Thread.sleep(1000); ctx.collect(new Tuple0()); } } @Override public void cancel() { this.isRunning = false; } } public static class Counter implements OneInputStreamOperator { private static final long serialVersionUID = 5518823010274195186L; @Override public void setup(Output> output, StreamingRuntimeContext runtimeContext) { // TODO Auto-generated method stub } @Override public void open(Configuration config) throws Exception { // TODO Auto-generated method stub } @Override public void close() throws Exception { // TODO Auto-generated method stub } @Override public StreamingRuntimeContext getRuntimeContext() { // TODO Auto-generated method stub return null; } @Override public boolean isInputCopyingDisabled() { // TODO Auto-generated method stub return false; } @Override public void setChainingStrategy( org.apache.flink.streaming.api.operators.StreamOperator.ChainingStrategy strategy) { // TODO Auto-generated method stub } @Override public org.apache.flink.streaming.api.operators.StreamOperator.ChainingStrategy getChainingStrategy() { // TODO Auto-generated method stub return null; } private int counter = 0; @Override public void processElement(StreamRecord element) throws Exception { System.out.println("Tuple0: " + (++counter)); } @Override public void processWatermark(Watermark mark) throws Exception { // TODO Auto-generated method stub } } }