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 2020/04/08 09:12:39 UTC

[GitHub] [incubator-hudi] yanghua commented on a change in pull request #1490: [HUDI-700]Add unit test for FileSystemViewCommand

yanghua commented on a change in pull request #1490: [HUDI-700]Add unit test for FileSystemViewCommand
URL: https://github.com/apache/incubator-hudi/pull/1490#discussion_r405375896
 
 

 ##########
 File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestFileSystemViewCommand.java
 ##########
 @@ -0,0 +1,245 @@
+/*
+ * 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.cli.commands;
+
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.model.FileSlice;
+import org.apache.hudi.common.model.HoodieFileGroup;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.view.HoodieTableFileSystemView;
+import org.apache.hudi.common.table.view.SyncableFileSystemView;
+import org.apache.hudi.common.util.NumericUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test class for {@link FileSystemViewCommand}.
+ */
+public class TestFileSystemViewCommand extends AbstractShellIntegrationTest {
+  private String tablePath;
+  private String partitionPath;
+  private SyncableFileSystemView fsView;
+
+  private static String TEST_WRITE_TOKEN = "1-0-1";
+
+  @Before
+  public void init() throws IOException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    new TableCommand().createTable(
+        tablePath, tableName,
+        "COPY_ON_WRITE", "", 1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    metaClient = HoodieCLI.getTableMetaClient();
+
+    partitionPath = HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    String fullPartitionPath = tablePath + "/" + partitionPath;
+    new File(fullPartitionPath).mkdirs();
+
+    // Generate 2 commits
+    String commitTime1 = "1";
+    String commitTime2 = "2";
+
+    String fileId1 = UUID.randomUUID().toString();
+
+    // Write date files and log file
+    new File(fullPartitionPath + "/" + FSUtils.makeDataFileName(commitTime1, TEST_WRITE_TOKEN, fileId1))
+        .createNewFile();
+    new File(fullPartitionPath + "/"
+        + FSUtils.makeLogFileName(fileId1, HoodieLogFile.DELTA_EXTENSION, commitTime1, 0, TEST_WRITE_TOKEN))
+        .createNewFile();
+    new File(fullPartitionPath + "/" + FSUtils.makeDataFileName(commitTime2, TEST_WRITE_TOKEN, fileId1))
+        .createNewFile();
+    new File(fullPartitionPath + "/"
+        + FSUtils.makeLogFileName(fileId1, HoodieLogFile.DELTA_EXTENSION, commitTime2, 0, TEST_WRITE_TOKEN))
+        .createNewFile();
+
+    // Write commit files
+    new File(tablePath + "/.hoodie/" + commitTime1 + ".commit").createNewFile();
+    new File(tablePath + "/.hoodie/" + commitTime2 + ".commit").createNewFile();
+
+    // Reload meta client and create fsView
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+
+    fsView = new HoodieTableFileSystemView(metaClient, metaClient.getActiveTimeline(), true);
+  }
+
+  /**
+   * Test case for 'show fsview all'.
+   */
+  @Test
+  public void testShowCommits() {
+    // Test default show fsview all
+    CommandResult cr = getShell().executeCommand("show fsview all");
 
 Review comment:
   ditto

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


With regards,
Apache Git Services