use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class StateDescriptorPassingTest method testApplyWindowState.
@Test
public void testApplyWindowState() throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.IngestionTime);
env.registerTypeWithKryoSerializer(File.class, JavaSerializer.class);
DataStream<File> src = env.fromElements(new File("/"));
SingleOutputStreamOperator<?> result = src.keyBy(new KeySelector<File, String>() {
@Override
public String getKey(File value) {
return null;
}
}).timeWindow(Time.milliseconds(1000)).apply(new WindowFunction<File, String, String, TimeWindow>() {
@Override
public void apply(String s, TimeWindow window, Iterable<File> input, Collector<String> out) {
}
});
validateListStateDescriptorConfigured(result);
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class StateDescriptorPassingTest method testProcessWindowState.
@Test
public void testProcessWindowState() throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.IngestionTime);
env.registerTypeWithKryoSerializer(File.class, JavaSerializer.class);
DataStream<File> src = env.fromElements(new File("/"));
SingleOutputStreamOperator<?> result = src.keyBy(new KeySelector<File, String>() {
@Override
public String getKey(File value) {
return null;
}
}).timeWindow(Time.milliseconds(1000)).process(new ProcessWindowFunction<File, String, String, TimeWindow>() {
@Override
public void process(String s, Context ctx, Iterable<File> input, Collector<String> out) {
}
});
validateListStateDescriptorConfigured(result);
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class StateDescriptorPassingTest method testApplyWindowAllState.
@Test
public void testApplyWindowAllState() throws Exception {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.IngestionTime);
env.registerTypeWithKryoSerializer(File.class, JavaSerializer.class);
DataStream<File> src = env.fromElements(new File("/"));
SingleOutputStreamOperator<?> result = src.timeWindowAll(Time.milliseconds(1000)).apply(new AllWindowFunction<File, String, TimeWindow>() {
@Override
public void apply(TimeWindow window, Iterable<File> input, Collector<String> out) {
}
});
validateListStateDescriptorConfigured(result);
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class AllWindowTranslationTest method testApplyProcessingTimeTime.
@Test
@SuppressWarnings("rawtypes")
public void testApplyProcessingTimeTime() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime);
DataStream<Tuple2<String, Integer>> source = env.fromElements(Tuple2.of("hello", 1), Tuple2.of("hello", 2));
DataStream<Tuple2<String, Integer>> window1 = source.windowAll(TumblingProcessingTimeWindows.of(Time.of(1, TimeUnit.SECONDS))).apply(new AllWindowFunction<Tuple2<String, Integer>, Tuple2<String, Integer>, TimeWindow>() {
private static final long serialVersionUID = 1L;
@Override
public void apply(TimeWindow window, Iterable<Tuple2<String, Integer>> values, Collector<Tuple2<String, Integer>> out) throws Exception {
for (Tuple2<String, Integer> in : values) {
out.collect(in);
}
}
});
OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>> transform = (OneInputTransformation<Tuple2<String, Integer>, Tuple2<String, Integer>>) window1.getTransformation();
OneInputStreamOperator<Tuple2<String, Integer>, Tuple2<String, Integer>> operator = transform.getOperator();
Assert.assertTrue(operator instanceof WindowOperator);
WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?> winOperator = (WindowOperator<String, Tuple2<String, Integer>, ?, ?, ?>) operator;
Assert.assertTrue(winOperator.getTrigger() instanceof ProcessingTimeTrigger);
Assert.assertTrue(winOperator.getWindowAssigner() instanceof TumblingProcessingTimeWindows);
Assert.assertTrue(winOperator.getStateDescriptor() instanceof ListStateDescriptor);
processElementAndEnsureOutput(winOperator, winOperator.getKeySelector(), BasicTypeInfo.STRING_TYPE_INFO, new Tuple2<>("hello", 1));
}
use of org.apache.flink.streaming.api.windowing.windows.TimeWindow in project flink by apache.
the class AllWindowTranslationTest method testMergingAssignerWithNonMergingTriggerFails.
@Test
public void testMergingAssignerWithNonMergingTriggerFails() throws Exception {
// verify that we check for trigger compatibility
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
AllWindowedStream<String, TimeWindow> windowedStream = env.fromElements("Hello", "Ciao").windowAll(EventTimeSessionWindows.withGap(Time.seconds(5)));
try {
windowedStream.trigger(new Trigger<String, TimeWindow>() {
private static final long serialVersionUID = 6558046711583024443L;
@Override
public TriggerResult onElement(String element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception {
return null;
}
@Override
public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext ctx) throws Exception {
return null;
}
@Override
public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext ctx) throws Exception {
return null;
}
@Override
public boolean canMerge() {
return false;
}
@Override
public void clear(TimeWindow window, TriggerContext ctx) throws Exception {
}
});
} catch (UnsupportedOperationException e) {
// use a catch to ensure that the exception is thrown by the fold
return;
}
fail("The trigger call should fail.");
}
Aggregations