Search in sources :

Example 1 with TimestampedValue

use of org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue in project flink by apache.

the class RecordEmitterTest method testRetainMinAfterReachingLimit.

@Test
public void testRetainMinAfterReachingLimit() throws Exception {
    TestRecordEmitter emitter = new TestRecordEmitter();
    final TimestampedValue<String> one = new TimestampedValue<>("1", 1);
    final TimestampedValue<String> two = new TimestampedValue<>("2", 2);
    final TimestampedValue<String> three = new TimestampedValue<>("3", 3);
    final TimestampedValue<String> ten = new TimestampedValue<>("10", 10);
    final TimestampedValue<String> eleven = new TimestampedValue<>("11", 11);
    final TimestampedValue<String> twenty = new TimestampedValue<>("20", 20);
    final TimestampedValue<String> thirty = new TimestampedValue<>("30", 30);
    final RecordEmitter.RecordQueue<TimestampedValue> queue0 = emitter.getQueue(0);
    final RecordEmitter.RecordQueue<TimestampedValue> queue1 = emitter.getQueue(1);
    queue0.put(one);
    queue0.put(two);
    queue0.put(three);
    queue0.put(ten);
    queue0.put(eleven);
    queue1.put(twenty);
    queue1.put(thirty);
    emitter.setMaxLookaheadMillis(1);
    emitter.setCurrentWatermark(5);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(emitter);
    try {
        // emits one record past the limit
        Deadline dl = Deadline.fromNow(Duration.ofSeconds(10));
        while (emitter.results.size() != 4 && dl.hasTimeLeft()) {
            Thread.sleep(10);
        }
        Assert.assertThat(emitter.results, Matchers.contains(one, two, three, ten));
        // advance watermark, emits remaining record from queue0
        emitter.setCurrentWatermark(10);
        dl = Deadline.fromNow(Duration.ofSeconds(10));
        while (emitter.results.size() != 5 && dl.hasTimeLeft()) {
            Thread.sleep(10);
        }
        Assert.assertThat(emitter.results, Matchers.contains(one, two, three, ten, eleven));
    } finally {
        emitter.stop();
        executor.shutdownNow();
    }
}
Also used : TimestampedValue(org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue) Deadline(org.apache.flink.api.common.time.Deadline) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 2 with TimestampedValue

use of org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue in project flink by apache.

the class RecordEmitterTest method test.

@Test
public void test() throws Exception {
    TestRecordEmitter emitter = new TestRecordEmitter();
    final TimestampedValue<String> one = new TimestampedValue<>("one", 1);
    final TimestampedValue<String> two = new TimestampedValue<>("two", 2);
    final TimestampedValue<String> five = new TimestampedValue<>("five", 5);
    final TimestampedValue<String> ten = new TimestampedValue<>("ten", 10);
    final RecordEmitter.RecordQueue<TimestampedValue> queue0 = emitter.getQueue(0);
    final RecordEmitter.RecordQueue<TimestampedValue> queue1 = emitter.getQueue(1);
    queue0.put(one);
    queue0.put(five);
    queue0.put(ten);
    queue1.put(two);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(emitter);
    Deadline dl = Deadline.fromNow(Duration.ofSeconds(10));
    while (emitter.results.size() != 4 && dl.hasTimeLeft()) {
        Thread.sleep(10);
    }
    emitter.stop();
    executor.shutdownNow();
    Assert.assertThat(emitter.results, Matchers.contains(one, five, two, ten));
}
Also used : TimestampedValue(org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue) Deadline(org.apache.flink.api.common.time.Deadline) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)2 Deadline (org.apache.flink.api.common.time.Deadline)2 TimestampedValue (org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue)2 Test (org.junit.Test)2