You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/12/07 08:49:17 UTC

[GitHub] [flink] SteNicholas commented on a change in pull request #14207: [FLINK-20250][table-runtime] NPE when invoking AsyncLookupJoinRunner#close method

SteNicholas commented on a change in pull request #14207:
URL: https://github.com/apache/flink/pull/14207#discussion_r537327673



##########
File path: flink-table/flink-table-runtime-blink/src/test/java/org/apache/flink/table/runtime/operators/join/AsyncLookupJoinRunnerTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.table.runtime.operators.join;
+
+import org.apache.flink.api.common.functions.AbstractRichFunction;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.async.AsyncFunction;
+import org.apache.flink.streaming.api.functions.async.ResultFuture;
+import org.apache.flink.streaming.util.MockStreamingRuntimeContext;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.collector.TableFunctionCollector;
+import org.apache.flink.table.runtime.collector.TableFunctionResultFuture;
+import org.apache.flink.table.runtime.generated.GeneratedFunctionWrapper;
+import org.apache.flink.table.runtime.generated.GeneratedResultFutureWrapper;
+import org.apache.flink.table.runtime.operators.join.lookup.AsyncLookupJoinRunner;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Supplier;
+
+import static org.apache.flink.table.data.StringData.fromString;
+import static org.apache.flink.table.runtime.util.StreamRecordUtils.row;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link AsyncLookupJoinRunner}.
+ */
+public class AsyncLookupJoinRunnerTest {
+
+	@Test
+	public void testCloseAsyncLookupJoinRunner() throws Exception {
+		final InternalTypeInfo<RowData> rightRowTypeInfo = InternalTypeInfo.ofFields(
+				DataTypes.INT().getLogicalType(),
+				DataTypes.STRING().getLogicalType());
+		final AsyncLookupJoinRunner joinRunner = new AsyncLookupJoinRunner(
+				new GeneratedFunctionWrapper(new TestingFetcherFunction()),
+				new GeneratedResultFutureWrapper<>(new TestingFetcherResultFuture()),
+				rightRowTypeInfo,
+				rightRowTypeInfo,
+				true,
+				100);
+		assertNull(joinRunner.getAllResultFutures());
+		closeAsyncLookupJoinRunner(joinRunner);
+
+		joinRunner.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
+		joinRunner.open(new Configuration());
+		assertNotNull(joinRunner.getAllResultFutures());
+		closeAsyncLookupJoinRunner(joinRunner);
+
+		joinRunner.open(new Configuration());
+		joinRunner.asyncInvoke(row(1, "a"), new TestingFetcherResultFuture());
+		assertNotNull(joinRunner.getAllResultFutures());
+		closeAsyncLookupJoinRunner(joinRunner);
+	}
+
+	private void closeAsyncLookupJoinRunner(AsyncLookupJoinRunner joinRunner) throws Exception {
+		try {
+			joinRunner.close();
+		} catch (NullPointerException e) {
+			fail("Expected close to fail with null pointer exception.");
+		}
+	}
+
+	// ---------------------------------------------------------------------------------
+
+	/**
+	 * The {@link TestingFetcherFunction} only accepts a single integer lookup key and
+	 * returns zero or one or more RowData.
+	 */
+	public static final class TestingFetcherFunction
+			extends AbstractRichFunction
+			implements AsyncFunction<RowData, RowData> {
+
+		private static final long serialVersionUID = 4018474964018227081L;

Review comment:
       > Could
   
   @leonardBang I thought that it could be defined once and reused `TestingFetcherFunction` and `TestingFetcherResultFuture`. I would like to reuse them.




----------------------------------------------------------------
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:
users@infra.apache.org