[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to test window

Hey guys,
i Incurred in situation and i need you help.

im trying Using unit test inorder to check my results,
first my  timeWindow is set for 15sec, but the assertyEquals doesnt wait for the window getting the answer,

so everything is telling me index 0 out of bounds (cuze its didnt get to place my object in the list yet)

thank you all!

 import org.apache.flink.annotation.Public;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.test.util.AbstractTestBase;
import org.com.CameraEvent;
import org.com.StreamingJob;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class IntergrationTest extends AbstractTestBase {

public void test() throws Exception {

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

// configure your test environment

// values are collected in a static variable
LinkedList<CameraEvent> events = GenerateEvents();
.keyBy(new StreamingJob.GetKey())
.addSink(new CollectSink());

assertEquals(events.get(1), CollectSink.values.get(0));

private static LinkedList<CameraEvent> GenerateEvents() {
LinkedList<CameraEvent> linkedList;
CameraEvent cameraEvent;
linkedList = new LinkedList<>();
for (int i = 0; i < 2; i++) {

cameraEvent = new CameraEvent("123-123-12", 1, new Date(), "OUT", "CAR");

try {
} catch (InterruptedException e) {
return linkedList;
private static class CollectSink implements SinkFunction<CameraEvent> {

// must be static
public static final List<CameraEvent> values = new ArrayList<>();

public synchronized void invoke(CameraEvent value) throws Exception {