Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6C760200BAE for ; Fri, 28 Oct 2016 11:41:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6B113160AE3; Fri, 28 Oct 2016 09:41:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8A12F160ADD for ; Fri, 28 Oct 2016 11:40:59 +0200 (CEST) Received: (qmail 68703 invoked by uid 500); 28 Oct 2016 09:40:58 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 68689 invoked by uid 99); 28 Oct 2016 09:40:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2016 09:40:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 9F22B2C0087 for ; Fri, 28 Oct 2016 09:40:58 +0000 (UTC) Date: Fri, 28 Oct 2016 09:40:58 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-4552) Refactor WindowOperator/Trigger Tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 28 Oct 2016 09:41:00 -0000 [ https://issues.apache.org/jira/browse/FLINK-4552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15614917#comment-15614917 ] ASF GitHub Bot commented on FLINK-4552: --------------------------------------- Github user aljoscha commented on a diff in the pull request: https://github.com/apache/flink/pull/2572#discussion_r85500442 --- Diff: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/EventTimeTriggerTest.java --- @@ -0,0 +1,153 @@ +/* + * 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.streaming.runtime.operators.windowing; + +import com.google.common.collect.Lists; +import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger; +import org.apache.flink.streaming.api.windowing.triggers.TriggerResult; +import org.apache.flink.streaming.api.windowing.windows.TimeWindow; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests for {@link EventTimeTrigger}. + */ +public class EventTimeTriggerTest { + + /** + * Verify that state of separate windows does not leak into other windows. + */ + @Test + public void testWindowSeparationAndFiring() throws Exception { + TriggerTestHarness testHarness = + new TriggerTestHarness<>(EventTimeTrigger.create(), new TimeWindow.Serializer()); + + // inject several elements + assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord(1), new TimeWindow(0, 2))); + assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord(1), new TimeWindow(0, 2))); + assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord(1), new TimeWindow(0, 2))); + assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord(1), new TimeWindow(2, 4))); + assertEquals(TriggerResult.CONTINUE, testHarness.processElement(new StreamRecord(1), new TimeWindow(2, 4))); + + assertEquals(0, testHarness.numStateEntries()); + assertEquals(0, testHarness.numProcessingTimeTimers()); + assertEquals(2, testHarness.numEventTimeTimers()); + assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); + assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); + + assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(2, new TimeWindow(0, 2))); + + assertEquals(0, testHarness.numStateEntries()); + assertEquals(0, testHarness.numProcessingTimeTimers()); + assertEquals(1, testHarness.numEventTimeTimers()); + assertEquals(0, testHarness.numEventTimeTimers(new TimeWindow(0, 2))); + assertEquals(1, testHarness.numEventTimeTimers(new TimeWindow(2, 4))); + + assertEquals(TriggerResult.FIRE, testHarness.advanceWatermark(4, new TimeWindow(2, 4))); + --- End diff -- The trigger tests only test the isolated behaviour of Triggers, there are no multiple keys here so that wouldn't work. You're right though, about the multiple timers so I'll add a test for this to `WindowOperatorTest` where the timer firing behaviour is tested. > Refactor WindowOperator/Trigger Tests > ------------------------------------- > > Key: FLINK-4552 > URL: https://issues.apache.org/jira/browse/FLINK-4552 > Project: Flink > Issue Type: Improvement > Components: Windowing Operators > Reporter: Aljoscha Krettek > Assignee: Aljoscha Krettek > > Right now, tests for {{WindowOperator}}, {{WindowAssigner}}, {{Trigger}} and {{WindowFunction}} are all conflated in {{WindowOperatorTest}}. All of these test that a certain combination of a {{Trigger}}, {{WindowAssigner}} and {{WindowFunction}} produce the expected output. > We should modularize these tests and spread them out across multiple files, possibly one per trigger, for the triggers. Also, we should extend/change the tests in some key ways: > - {{WindowOperatorTest}} test should just verify that the interaction between {{WindowOperator}} and the various other parts works as expected, that the correct methods on {{Trigger}} and {{WindowFunction}} are called at the expected time and that snapshotting, timers, cleanup etc. work correctly. These tests should also verify that the different state types and {{WindowFunctions}} work correctly. > - {{Trigger}} tests should present elements to triggers and verify that they fire at the correct times. The actual output of the {{WindowFunction}} is not important for these tests. We should also test that triggers correctly clean up state and timers. > - {{WindowAssigner}} tests should test each window assigner and also verify that, for example, the offset parameter of time-based windows works correctly. > There is already {{WindowingTestHarness}} but it is not used by tests, I think we can expand on that and provide more thorough test coverage while also making the tests more maintainable ({{WindowOperatorTest.java}} is nearing 3000 lines of code). -- This message was sent by Atlassian JIRA (v6.3.4#6332)