twalthr commented on a change in pull request #18255: URL: https://github.com/apache/flink/pull/18255#discussion_r779376768
########## File path: flink-table/flink-table-test-utils/src/main/java/org/apache/flink/table/test/factories/TableFactoryHarness.java ########## @@ -0,0 +1,425 @@ +/* + * 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.test.factories; + +import org.apache.flink.annotation.Experimental; +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.streaming.api.functions.sink.SinkFunction; +import org.apache.flink.streaming.api.functions.source.SourceFunction; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.api.TableDescriptor; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.table.api.ValidationException; +import org.apache.flink.table.catalog.CatalogBaseTable; +import org.apache.flink.table.catalog.CatalogTable; +import org.apache.flink.table.catalog.DefaultCatalogTable; +import org.apache.flink.table.connector.ChangelogMode; +import org.apache.flink.table.connector.sink.DynamicTableSink; +import org.apache.flink.table.connector.sink.SinkFunctionProvider; +import org.apache.flink.table.connector.source.DynamicTableSource; +import org.apache.flink.table.connector.source.LookupTableSource; +import org.apache.flink.table.connector.source.ScanTableSource; +import org.apache.flink.table.connector.source.SourceFunctionProvider; +import org.apache.flink.table.connector.source.TableFunctionProvider; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.factories.DynamicTableFactory; +import org.apache.flink.table.factories.DynamicTableSinkFactory; +import org.apache.flink.table.factories.DynamicTableSourceFactory; +import org.apache.flink.table.factories.FactoryUtil; +import org.apache.flink.table.functions.TableFunction; +import org.apache.flink.testutils.junit.SharedObjects; + +import javax.annotation.Nullable; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +/** + * Provides a flexible testing harness for table factories. + * + * <p>This testing harness allows writing custom sources and sinks which can be directly + * instantiated from the test. This avoids having to implement a factory, and enables using the + * {@link SharedObjects} rule to get direct access to the underlying source/sink from the test. + * + * <p>The underlying source/sink must extend from {@link SourceBase} or {@link SinkBase}. + * + * <p>Example: + * + * <pre>{@code + * public class CustomSourceTest { + * {@literal @}Rule public SharedObjects sharedObjects = SharedObjects.create(); + * + * {@literal @}Test + * public void test() { + * SharedReference<List<Long>> appliedLimits = sharedObjects.add(new ArrayList<>()); + * TableDescriptor sourceDescriptor = + * TableFactoryHarness.newBuilder() + * .schema(Schema.derived()) + * .source(new CustomSource(appliedLimits)) + * .build(); + * tEnv.createTable("T", sourceDescriptor); + * + * tEnv.explainSql("SELECT * FROM T LIMIT 42"); + * + * assertEquals(1, appliedLimits.get().size()); + * assertEquals((Long) 42L, appliedLimits.get().get(0)); + * } + * + * private static class CustomSource extends TableFactoryHarness.ScanSourceBase + * implements SupportsLimitPushDown { + * private final SharedReference<List<Long>> appliedLimits; + * + * CustomSource(SharedReference<List<Long>> appliedLimits) { + * this.appliedLimits = appliedLimits; + * } + * + * public void applyLimit(long limit) { + * appliedLimits.get().add(limit); + * } + * } + * } + * }</pre> + */ +@Experimental +public class TableFactoryHarness { + + /** Factory identifier for {@link Factory}. */ + public static final String IDENTIFIER = "harness"; Review comment: This factory is not registered in META-INF of this module. ########## File path: flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TableFactoryHarness.java ########## @@ -95,7 +95,11 @@ * } * } * }</pre> + * + * @deprecated If you're using this test utility, then move the test class in flink-table-tests and + * use the TableFactoryHarness from table-test-utils */ +@Deprecated public class TableFactoryHarness { Review comment: We still have duplicate classes. We should port the existing tests and remove this class. -- 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]
