Return-Path: X-Original-To: apmail-flink-dev-archive@www.apache.org Delivered-To: apmail-flink-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D5632176C6 for ; Wed, 5 Nov 2014 12:54:59 +0000 (UTC) Received: (qmail 60258 invoked by uid 500); 5 Nov 2014 12:54:59 -0000 Delivered-To: apmail-flink-dev-archive@flink.apache.org Received: (qmail 60206 invoked by uid 500); 5 Nov 2014 12:54:59 -0000 Mailing-List: contact dev-help@flink.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.incubator.apache.org Delivered-To: mailing list dev@flink.incubator.apache.org Received: (qmail 60194 invoked by uid 99); 5 Nov 2014 12:54:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Nov 2014 12:54:59 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ewenstephan@gmail.com designates 209.85.220.177 as permitted sender) Received: from [209.85.220.177] (HELO mail-vc0-f177.google.com) (209.85.220.177) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Nov 2014 12:54:33 +0000 Received: by mail-vc0-f177.google.com with SMTP id hq12so318651vcb.36 for ; Wed, 05 Nov 2014 04:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=NI85ZdjLu/aYZvYvYTaGSIcoTqvNMxc1oAt7tBxJ0dE=; b=SH/KJZF6479xgygtLzrEpz48yBmfiYD9DXdjfpevAjfnPsblDdakK8VJIQBeSHb57x N4eJsGLhYsSkM/3LnIbtWrz0hPXpFDDd3YEMELLNExy2GQqZQx4JcuBaMsHPWR3dc/YW K5e0w9EUx6RNUb8zSLRlTvlzuJkLX22udOmxMuvPz7U2mItfOK+xSCid1x+6VvaXKWMZ iepw0w4lH2b3kZLf8UkQ3imfRNf5PjiNUUV2XxAgi3GP6BHFn7tZAtPiQk7lARbS9JiY eMfk4zDOgV4I59I1n8xsVW0kpMmQq0Vnu4fOmxJuxxca+BQ7scO07exlwC+ndqp/oppI 13xg== MIME-Version: 1.0 X-Received: by 10.221.51.8 with SMTP id vg8mr50736155vcb.0.1415191982276; Wed, 05 Nov 2014 04:53:02 -0800 (PST) Sender: ewenstephan@gmail.com Received: by 10.31.161.4 with HTTP; Wed, 5 Nov 2014 04:53:02 -0800 (PST) In-Reply-To: <1415191441969-2371.post@n3.nabble.com> References: <1415191441969-2371.post@n3.nabble.com> Date: Wed, 5 Nov 2014 13:53:02 +0100 X-Google-Sender-Auth: pKGYi-VzNYtCdLVGoc1ISSfAGTw Message-ID: Subject: Re: Unit testing Flink programs / DataSet operations From: Stephan Ewen To: dev@flink.incubator.apache.org Content-Type: multipart/alternative; boundary=001a11335aea6487f405071c0f48 X-Virus-Checked: Checked by ClamAV on apache.org --001a11335aea6487f405071c0f48 Content-Type: text/plain; charset=UTF-8 Hey! Why don't you simply run this program and verify that the result is 6? You can use the "LocalCollectionOutputFormat" to collect the results (in your case the one value) and compare it. Stephan On Wed, Nov 5, 2014 at 1:44 PM, Viktor Rosenfled < viktor.rosenfeld@tu-berlin.de> wrote: > Hi everybody, > > I have the following test case prototype and I want to verify that sum() > actually computes the sum. > > @Test > public void shouldComputeSum() throws Exception { > // given > ExecutionEnvironment env = > ExecutionEnvironment.getExecutionEnvironment(); > DataSet> input = env.fromElements( > new Tuple1(1L), > new Tuple1(2L), > new Tuple1(3L)); > > // when > DataSet> result = input.sum(0); > > // then > // verify that result is 6 > } > > I found AggregateTranslationTest where a program plan is created and then > the sink is accessed to verify some structure on the output operator. Using > this as a starting point, I wrote the following code: > > // verify that the result is 6 > OutputFormat> outputFormat = > mock(OutputFormat.class, withSettings().serializable()); > output.output(outputFormat); > env.execute("ComputeCountTest"); > verify(outputFormat).writeRecord(new Tuple1(6L)); > > I encountered a few problems: > > - I can't run this test code from the flink-java module because > env.execute() requires flink-clients which leads to a circular dependency. > > - The outputFormat needs to be serializable; luckily Mockito supports this > even though they consider it a code smell but that can be argued. > > - It doesn't actually work. Mockito prints: > > Wanted but not invoked: > outputFormat.writeRecord((6)); > -> at > > org.apache.flink.api.java.operator.MyAggregateOperatorTest.shouldComputeSum(MyAggregateOperatorTest.java:31) > Actually, there were zero interactions with this mock. > > I suspect env.execute() is non-blocking and that there's a race condition. > > Executing a whole Flink program is probably too heavyweight for a unit test > but I wanted to use it as a starting point. I also found two other methods > to test operator code but I'm not sure which is the preferred way: > > - MapTest: invokes a Map operator on a collection using > MockInvokable.createAndExecute() > > - MapOperatorTest: invokes a Map operator op on a collection using > op.executeOnCollection() > > So, my question is basically if there's a best practice in the Flink code > base to write a unit test similar to the one above. > > Best, > Viktor > > > > -- > View this message in context: > http://apache-flink-incubator-mailing-list-archive.1008284.n3.nabble.com/Unit-testing-Flink-programs-DataSet-operations-tp2371.html > Sent from the Apache Flink (Incubator) Mailing List archive. mailing list > archive at Nabble.com. > --001a11335aea6487f405071c0f48--