You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/01/23 18:23:57 UTC

[GitHub] [hudi] xushiyan commented on a change in pull request #2478: [HUDI-1476] Introduce unit test infra for java client

xushiyan commented on a change in pull request #2478:
URL: https://github.com/apache/hudi/pull/2478#discussion_r563181808



##########
File path: hudi-common/src/test/java/org/apache/hudi/common/testutils/HoodieTestUtils.java
##########
@@ -107,6 +111,28 @@ public static HoodieTableMetaClient init(Configuration hadoopConf, String basePa
     return HoodieTableMetaClient.initTableAndGetMetaClient(hadoopConf, basePath, properties);
   }
 
+  public static final void createMetadataFolder(String basePath) {

Review comment:
       Please check out `org.apache.hudi.common.testutils.FileCreateUtils`; we have been trying to move methods out from this class as it was crammed with all sorts of helpers.

##########
File path: hudi-client/hudi-java-client/src/test/java/org/apache/hudi/testutils/HoodieJavaClientTestUtils.java
##########
@@ -0,0 +1,313 @@
+/*
+ * 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.hadoop.conf.Configuration;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.avro.HoodieAvroWriteSupport;
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.bloom.BloomFilter;
+import org.apache.hudi.common.bloom.BloomFilterFactory;
+import org.apache.hudi.common.bloom.BloomFilterTypeCode;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.HoodieCommitMetadata;
+import org.apache.hudi.common.model.HoodieBaseFile;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.view.HoodieTableFileSystemView;
+import org.apache.hudi.common.table.view.TableFileSystemView;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.config.HoodieStorageConfig;
+import org.apache.hudi.exception.HoodieException;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.io.storage.HoodieAvroParquetConfig;
+import org.apache.hudi.io.storage.HoodieParquetWriter;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.parquet.avro.AvroParquetReader;
+import org.apache.parquet.avro.AvroReadSupport;
+import org.apache.parquet.avro.AvroSchemaConverter;
+import org.apache.parquet.hadoop.ParquetReader;
+import org.apache.parquet.hadoop.ParquetWriter;
+import org.apache.parquet.hadoop.metadata.CompressionCodecName;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+/**
+ * Utility methods to aid testing inside the HoodieClient module.
+ */
+public class HoodieJavaClientTestUtils {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieJavaClientTestUtils.class);
+  private static final Random RANDOM = new Random();
+  private static final Configuration CONF = new Configuration();
+
+  public static List<WriteStatus> collectStatuses(Iterator<List<WriteStatus>> statusListItr) {
+    List<WriteStatus> statuses = new ArrayList<>();
+    while (statusListItr.hasNext()) {
+      statuses.addAll(statusListItr.next());
+    }
+    return statuses;
+  }
+
+  public static Set<String> getRecordKeys(List<HoodieRecord> hoodieRecords) {
+    Set<String> keys = new HashSet<>();
+    for (HoodieRecord rec : hoodieRecords) {
+      keys.add(rec.getRecordKey());
+    }
+    return keys;
+  }
+
+  public static List<HoodieKey> getHoodieKeys(List<HoodieRecord> hoodieRecords) {
+    List<HoodieKey> keys = new ArrayList<>();
+    for (HoodieRecord rec : hoodieRecords) {
+      keys.add(rec.getKey());
+    }
+    return keys;
+  }
+
+  public static List<HoodieKey> getKeysToDelete(List<HoodieKey> keys, int size) {
+    List<HoodieKey> toReturn = new ArrayList<>();
+    int counter = 0;
+    while (counter < size) {
+      int index = RANDOM.nextInt(keys.size());
+      if (!toReturn.contains(keys.get(index))) {
+        toReturn.add(keys.get(index));
+        counter++;
+      }
+    }
+    return toReturn;
+  }
+
+  private static void fakeMetaFile(String basePath, String commitTime, String suffix) throws IOException {

Review comment:
       There are helpers for these purposes in `FileCreateUtils`, `HoodieTestTable` and `HoodieWriteableTestTable`. Do you think you can make use of them and incorporate into the new classes here?




----------------------------------------------------------------
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