hudi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vinoy...@apache.org
Subject [incubator-hudi] branch master updated: [HUDI-695]Add unit test for TableCommand (#1411)
Date Tue, 17 Mar 2020 06:15:38 GMT
This is an automated email from the ASF dual-hosted git repository.

vinoyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new f1d7bb3  [HUDI-695]Add unit test for TableCommand (#1411)
f1d7bb3 is described below

commit f1d7bb381d4a370beeedb45132b24c2cac00aabf
Author: hongdd <jn_hdd@163.com>
AuthorDate: Tue Mar 17 14:15:30 2020 +0800

    [HUDI-695]Add unit test for TableCommand (#1411)
---
 hudi-cli/pom.xml                                   |  14 ++
 .../hudi/cli/AbstractShellIntegrationTest.java     |  15 ++-
 .../apache/hudi/cli/commands/TestTableCommand.java | 142 +++++++++++++++++++++
 3 files changed, 170 insertions(+), 1 deletion(-)

diff --git a/hudi-cli/pom.xml b/hudi-cli/pom.xml
index 71010cb..d3b08dc 100644
--- a/hudi-cli/pom.xml
+++ b/hudi-cli/pom.xml
@@ -155,6 +155,20 @@
       <artifactId>hudi-utilities_${scala.binary.version}</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hudi</groupId>
+      <artifactId>hudi-common</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hudi</groupId>
+      <artifactId>hudi-client</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
 
     <!-- Logging -->
     <dependency>
diff --git a/hudi-cli/src/test/java/org/apache/hudi/cli/AbstractShellIntegrationTest.java
b/hudi-cli/src/test/java/org/apache/hudi/cli/AbstractShellIntegrationTest.java
index 6db65a7..3e0e6a0 100644
--- a/hudi-cli/src/test/java/org/apache/hudi/cli/AbstractShellIntegrationTest.java
+++ b/hudi-cli/src/test/java/org/apache/hudi/cli/AbstractShellIntegrationTest.java
@@ -18,7 +18,10 @@
 
 package org.apache.hudi.cli;
 
+import org.apache.hudi.common.HoodieClientTestHarness;
+import org.junit.After;
 import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.springframework.shell.Bootstrap;
 import org.springframework.shell.core.JLineShellComponent;
@@ -26,7 +29,7 @@ import org.springframework.shell.core.JLineShellComponent;
 /**
  * Class to start Bootstrap and JLineShellComponent.
  */
-public abstract class AbstractShellIntegrationTest {
+public abstract class AbstractShellIntegrationTest extends HoodieClientTestHarness {
   private static JLineShellComponent shell;
 
   @BeforeClass
@@ -40,6 +43,16 @@ public abstract class AbstractShellIntegrationTest {
     shell.stop();
   }
 
+  @Before
+  public void setup() throws Exception {
+    initResources();
+  }
+
+  @After
+  public void teardown() throws Exception {
+    cleanupResources();
+  }
+
   protected static JLineShellComponent getShell() {
     return shell;
   }
diff --git a/hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestTableCommand.java b/hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestTableCommand.java
new file mode 100644
index 0000000..a4f023f
--- /dev/null
+++ b/hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestTableCommand.java
@@ -0,0 +1,142 @@
+/*
+ * 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.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.util.ConsistencyGuardConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+
+import static org.apache.hudi.common.table.HoodieTableMetaClient.METAFOLDER_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link TableCommand}.
+ */
+public class TestTableCommand extends AbstractShellIntegrationTest {
+
+  private String tableName = "test_table";
+  private String tablePath;
+  private String metaPath;
+
+  /**
+   * Init path after Mini hdfs init.
+   */
+  @Before
+  public void init() {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+    tablePath = basePath + File.separator + tableName;
+    metaPath = tablePath + File.separator + METAFOLDER_NAME;
+  }
+
+  /**
+   * Method to create a table for connect or desc.
+   */
+  private boolean prepareTable() {
+    CommandResult cr = getShell().executeCommand(
+        "create --path " + tablePath + " --tableName " + tableName);
+    return cr.isSuccess();
+  }
+
+  /**
+   * Test Case for connect table.
+   */
+  @Test
+  public void testConnectTable() {
+    // Prepare table
+    assertTrue(prepareTable());
+
+    // Test connect with specified values
+    CommandResult cr = getShell().executeCommand(
+        "connect --path " + tablePath + " --initialCheckIntervalMs 3000 "
+          + "--maxWaitIntervalMs 40000 --maxCheckIntervalMs 8");
+    assertTrue(cr.isSuccess());
+
+    // Check specified values
+    ConsistencyGuardConfig conf = HoodieCLI.consistencyGuardConfig;
+    assertEquals(3000, conf.getInitialConsistencyCheckIntervalMs());
+    assertEquals(40000, conf.getMaxConsistencyCheckIntervalMs());
+    assertEquals(8, conf.getMaxConsistencyChecks());
+
+    // Check default values
+    assertFalse(conf.isConsistencyCheckEnabled());
+    assertEquals(new Integer(1), HoodieCLI.layoutVersion.getVersion());
+  }
+
+  /**
+   * Test Cases for create table with default values.
+   */
+  @Test
+  public void testDefaultCreate() {
+    // Create table
+    assertTrue(prepareTable());
+
+    // Test meta
+    HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
+    assertEquals(metaPath, client.getArchivePath());
+    assertEquals(tablePath, client.getBasePath());
+    assertEquals(metaPath, client.getMetaPath());
+    assertEquals(HoodieTableType.COPY_ON_WRITE, client.getTableType());
+    assertEquals(new Integer(1), client.getTimelineLayoutVersion().getVersion());
+  }
+
+  /**
+   * Test Cases for create table with specified values.
+   */
+  @Test
+  public void testCreateWithSpecifiedValues() {
+    // Test create with specified values
+    CommandResult cr = getShell().executeCommand(
+        "create --path " + tablePath + " --tableName " + tableName
+          + " --tableType MERGE_ON_READ --archiveLogFolder archive");
+    assertTrue(cr.isSuccess());
+    assertEquals("Metadata for table " + tableName + " loaded", cr.getResult().toString());
+    HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
+    assertEquals(metaPath + File.separator + "archive", client.getArchivePath());
+    assertEquals(tablePath, client.getBasePath());
+    assertEquals(metaPath, client.getMetaPath());
+    assertEquals(HoodieTableType.MERGE_ON_READ, client.getTableType());
+  }
+
+  /**
+   * Test Case for desc table.
+   */
+  @Test
+  public void testDescTable() {
+    // Prepare table
+    assertTrue(prepareTable());
+
+    // Test desc table
+    CommandResult cr = getShell().executeCommand("desc");
+    assertTrue(cr.isSuccess());
+
+    // check table's basePath metaPath and type
+    assertTrue(cr.getResult().toString().contains(tablePath));
+    assertTrue(cr.getResult().toString().contains(metaPath));
+    assertTrue(cr.getResult().toString().contains("COPY_ON_WRITE"));
+  }
+}


Mime
View raw message