yanghua commented on a change in pull request #2281:
URL: https://github.com/apache/hudi/pull/2281#discussion_r550163481
##########
File path:
hudi-common/src/test/java/org/apache/hudi/common/testutils/HoodieCommonTestHarness.java
##########
@@ -52,6 +53,24 @@ protected void initPath() {
}
}
+ /**
+ * Initializes a test data generator which used to generate test datas.
+ *
+ */
+ protected void initTestDataGenerator() {
Review comment:
Why do we need to move this code snippet from `HoodieClientTestHarness`
in this PR?
##########
File path:
hudi-client/hudi-flink-client/src/test/java/org/apache/hudi/testutils/HoodieFlinkClientTestHarness.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.hudi.testutils;
+
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.testutils.HoodieCommonTestHarness;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocalFileSystem;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestInfo;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class HoodieFlinkClientTestHarness extends HoodieCommonTestHarness
implements Serializable {
+
+ protected static final Logger LOG =
LogManager.getLogger(HoodieFlinkClientTestHarness.class);
+ private String testMethodName;
+ protected transient Configuration hadoopConf = null;
+ protected transient FileSystem fs;
+ protected transient MiniClusterWithClientResource flinkCluster = null;
+
+ @BeforeEach
+ public void setTestMethodName(TestInfo testInfo) {
+ if (testInfo.getTestMethod().isPresent()) {
+ testMethodName = testInfo.getTestMethod().get().getName();
+ } else {
+ testMethodName = "Unknown";
+ }
+ }
+
+ protected void initFlinkMiniCluster() {
+ flinkCluster = new MiniClusterWithClientResource(
+ new MiniClusterResourceConfiguration.Builder()
+ .setNumberSlotsPerTaskManager(2)
+ .setNumberTaskManagers(1)
+ .build());
+ }
+
+ protected void initFileSystem() {
+ hadoopConf = new Configuration();
+ initFileSystemWithConfiguration(hadoopConf);
+ }
+
+ private void initFileSystemWithConfiguration(Configuration configuration) {
+ if (basePath == null) {
+ throw new IllegalStateException("The base path has not been
initialized.");
+ }
+ fs = FSUtils.getFs(basePath, configuration);
+ if (fs instanceof LocalFileSystem) {
+ LocalFileSystem lfs = (LocalFileSystem) fs;
+ // With LocalFileSystem, with checksum disabled, fs.open() returns an
inputStream which is FSInputStream
+ // This causes ClassCastExceptions in LogRecordScanner (and potentially
other places) calling fs.open
+ // So, for the tests, we enforce checksum verification to circumvent the
problem
+ lfs.setVerifyChecksum(true);
+ }
+ }
+
+ /**
+ * Initializes an instance of {@link HoodieTableMetaClient} with a special
table type specified by
+ * {@code getTableType()}.
+ *
+ * @throws IOException
+ */
+ protected void initMetaClient() throws IOException {
+ initMetaClient(getTableType());
+ }
+
+ protected void initMetaClient(HoodieTableType tableType) throws IOException {
+ if (basePath == null) {
+ throw new IllegalStateException("The base path has not been
initialized.");
+ }
+ metaClient = HoodieTestUtils.init(hadoopConf, basePath, tableType);
+ }
+
+
+ /**
+ * Cleanups file system.
+ *
+ * @throws IOException
+ */
+ protected void cleanupFileSystem() throws IOException {
+ if (fs != null) {
+ LOG.warn("Closing file-system instance used in previous test-run");
+ fs.close();
+ fs = null;
+ }
+ }
+
+ protected void cleanupFlinkMiniCluster() {
+ if (flinkCluster != null) {
+ flinkCluster.after();
+ flinkCluster = null;
+ }
+ }
+
+ public static class SimpleSink implements SinkFunction<HoodieRecord> {
Review comment:
`SimpleTestSinkFunction` sounds better?
##########
File path: hudi-flink/pom.xml
##########
@@ -173,5 +173,102 @@
<artifactId>bijection-avro_${scala.binary.version}</artifactId>
<version>0.9.7</version>
</dependency>
+
+ <!-- Test -->
Review comment:
`Test suite` or `Test frameworks` sounds better?
##########
File path:
hudi-flink/src/main/java/org/apache/hudi/source/JsonStringToHoodieRecordMapFunction.java
##########
@@ -40,32 +43,47 @@
*/
public class JsonStringToHoodieRecordMapFunction implements
MapFunction<String, HoodieRecord> {
- private final HoodieFlinkStreamer.Config cfg;
+ private TypedProperties props;
private KeyGenerator keyGenerator;
private AvroConvertor avroConvertor;
+ private Option<String> schemaStr = Option.empty();
+ private String payloadClassName;
+ private String orderingField;
- public JsonStringToHoodieRecordMapFunction(HoodieFlinkStreamer.Config cfg) {
- this.cfg = cfg;
+ public JsonStringToHoodieRecordMapFunction(TypedProperties props) {
+ this.props = props;
+ init();
+ }
+
+ public JsonStringToHoodieRecordMapFunction(TypedProperties props, String
schemaStr) {
Review comment:
Can we reuse the first constructor?
----------------------------------------------------------------
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:
[email protected]