AHeise commented on a change in pull request #9717: [FLINK-14044] [runtime] 
Reducing synchronization in AsyncWaitOperator
URL: https://github.com/apache/flink/pull/9717#discussion_r329898500
 
 

 ##########
 File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/async/queue/QueueUtil.java
 ##########
 @@ -0,0 +1,62 @@
+/*
+ * 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.api.operators.async.queue;
+
+import org.apache.flink.streaming.api.functions.async.ResultFuture;
+import org.apache.flink.streaming.api.operators.TimestampedCollector;
+import org.apache.flink.streaming.runtime.streamrecord.StreamElement;
+import org.apache.flink.streaming.util.CollectorOutput;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Utility for putting elements inside a {@link StreamElementQueue}.
+ */
+class QueueUtil {
+       static ResultFuture<Integer> putSucessfully(StreamElementQueue<Integer> 
queue, StreamElement streamElement) {
+               Optional<ResultFuture<Integer>> resultFuture = 
queue.tryPut(streamElement);
+               assertTrue(resultFuture.isPresent());
+               return resultFuture.get();
+       }
+
+       static void putUnsucessfully(StreamElementQueue<Integer> queue, 
StreamElement streamElement) {
+               Optional<ResultFuture<Integer>> resultFuture = 
queue.tryPut(streamElement);
+               assertFalse(resultFuture.isPresent());
+       }
+
+       /**
+        * Pops all completed elements from the head of this queue.
+        *
+        * @return Completed elements or empty list of none exists.
+        */
+       static List<StreamElement> popCompleted(StreamElementQueue<Integer> 
queue) {
+               final List<StreamElement> completed = new ArrayList<>();
+               TimestampedCollector<Integer> collector = new 
TimestampedCollector<>(new CollectorOutput<>(completed));
+               while (queue.hasCompletedElements()) {
+                       queue.emitCompletedElement(collector);
+               }
+               collector.close();
 
 Review comment:
   We need to call close here exactly because it flushes data (in this case it 
could flush buffered data into the list). Compare with Kryo's `Output`.
   
   Flushing the list on `close` would be an odd behavior that breaks with the 
expectations that we have from `java.io.StringWriter`, `ByteArrayOutputStream`, 
etc.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to