jiangxin369 commented on code in PR #229:
URL: https://github.com/apache/flink-ml/pull/229#discussion_r1168377341


##########
flink-ml-iteration/src/test/java/org/apache/flink/iteration/operator/OperatorUtilsTest.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.iteration.operator;
+
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.common.typeutils.base.IntSerializer;
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationRecord;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.compile.DraftExecutionEnvironment;
+import org.apache.flink.iteration.operator.allround.AllRoundOperatorWrapper;
+import org.apache.flink.iteration.typeinfo.IterationRecordTypeInfo;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.graph.StreamConfig;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.operators.StreamOperatorFactory;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import 
org.apache.flink.streaming.runtime.tasks.StreamTaskMailboxTestHarnessBuilder;
+import org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask;
+import org.apache.flink.util.OutputTag;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the {@link OperatorUtils}. */
+public class OperatorUtilsTest extends TestLogger {
+
+    @Test
+    public void testCreateWrappedOperatorConfig() throws Exception {
+        StreamOperatorFactory<IterationRecord<Integer>> wrapperFactory =
+                new WrapperOperatorFactory<>(
+                        SimpleOperatorFactory.of(new 
MockTwoInputStreamOperator()),
+                        new AllRoundOperatorWrapper<>());
+
+        OperatorID operatorId = new OperatorID();
+
+        new StreamTaskMailboxTestHarnessBuilder<>(
+                        TwoInputStreamTask::new,
+                        new 
IterationRecordTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO))
+                .addInput(new 
IterationRecordTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO))
+                .addInput(new 
IterationRecordTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO))
+                .setupOutputForSingletonOperatorChain(wrapperFactory, 
operatorId)
+                .build();
+    }
+
+    @Test
+    public void testCreateWrappedOperatorConfigWithSideOutput() throws 
Exception {
+        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+        env.getConfig().enableObjectReuse();
+
+        final OutputTag<Integer> outputTag = new OutputTag("0", Types.INT) {};
+        DataStream<Integer> variableSource =
+                env.addSource(new 
DraftExecutionEnvironment.EmptySource<Integer>() {});
+
+        Iterations.iterateUnboundedStreams(
+                DataStreamList.of(variableSource),
+                DataStreamList.of(),
+                (variableStreams, dataStreams) -> {
+                    DataStream<Integer> variable = variableStreams.get(0);
+                    SingleOutputStreamOperator transformed =
+                            variable.transform(
+                                    "side-output",
+                                    Types.INT,
+                                    new MockSideOutputOperator<>(outputTag));
+                    return new IterationBodyResult(
+                            DataStreamList.of(variable),
+                            
DataStreamList.of(transformed.getSideOutput(outputTag)));
+                });
+        env.execute();

Review Comment:
   I added the check of the value of the output.
   
   I tried to move the test to flink-ml-tests, but it didn't make it simpler, 
so I prefer to leave the test in a directory that corresponds to the source 
code. Note that we also have some test classes running in a mini-cluster in the 
Iteration module, like `BroadcastOutputTest`, 
`OperatorEpochWatermarkTrackerFactoryTest`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to