zhangyue19921010 commented on a change in pull request #4817:
URL: https://github.com/apache/hudi/pull/4817#discussion_r809754172



##########
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/integ/ITTestClusteringCommand.java
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.integ;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.commands.TableCommand;
+import org.apache.hudi.cli.testutils.AbstractShellIntegrationTest;
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.client.common.HoodieSparkEngineContext;
+import org.apache.hudi.common.model.HoodieAvroPayload;
+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.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.index.HoodieIndex;
+import org.apache.hudi.testutils.HoodieClientTestBase;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test class for {@link 
org.apache.hudi.cli.commands.ClusteringCommand}.
+ * <p/>
+ * A command use SparkLauncher need load jars under lib which generate during 
mvn package.
+ * Use integration test instead of unit test.
+ */
+public class ITTestClusteringCommand extends AbstractShellIntegrationTest {
+
+  private String tablePath;
+  private String tableName;
+
+  @BeforeEach
+  public void init() throws IOException {
+    tableName = "test_table_" + ITTestClusteringCommand.class.getName();
+    tablePath = Paths.get(basePath, tableName).toString();
+
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+    // Create table and connect
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(),
+        "", TimelineLayoutVersion.VERSION_1, 
"org.apache.hudi.common.model.HoodieAvroPayload");
+    metaClient.setBasePath(tablePath);
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+  }
+
+  /**
+   * Test case for command 'clustering schedule'.
+   */
+  @Test
+  public void testScheduleClustering() throws IOException {
+    // generate commits
+    generateCommits();
+
+    CommandResult cr = getShell().executeCommand(
+        String.format("clustering schedule --hoodieConfigs 
hoodie.clustering.inline.max.commits=1 --sparkMaster %s",
+            "local"));
+    assertAll("Command run failed",
+        () -> assertTrue(cr.isSuccess()),
+        () -> assertTrue(
+            cr.getResult().toString().startsWith("Succeeded to schedule 
clustering for")));
+
+    // there is 1 requested clustering
+    HoodieActiveTimeline timeline = 
HoodieCLI.getTableMetaClient().getActiveTimeline();
+    assertEquals(1, timeline.filterPendingReplaceTimeline().countInstants());
+  }
+
+  /**
+   * Test case for command 'clustering run'.
+   */
+  @Test
+  public void testClustering() throws IOException {
+    // generate commits
+    generateCommits();
+
+    String instance = prepareScheduleClustering();
+
+    CommandResult cr2 = getShell().executeCommand(
+        String.format("clustering run --parallelism %s --clusteringInstant %s 
--sparkMaster %s",
+            2, instance, "local"));
+
+    assertAll("Command run failed",
+        () -> assertTrue(cr2.isSuccess()),
+        () -> assertTrue(
+            cr2.getResult().toString().startsWith("Succeeded to run clustering 
for ")));
+
+    // assert clustering complete
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+        .filterCompletedInstants().getInstants()
+        
.map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance),
+        "Pending clustering must be completed");
+
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+            .getCompletedReplaceTimeline().getInstants()
+            
.map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance),
+        "Pending clustering must be completed");
+  }
+
+  /**
+   * Test case for command 'clustering scheduleAndExecute'.
+   */
+  @Test
+  public void testClusteringScheduleAndExecute() throws IOException {
+    // generate commits
+    generateCommits();
+
+    CommandResult cr2 = getShell().executeCommand(
+        String.format("clustering scheduleAndExecute --parallelism %s 
--sparkMaster %s", 2, "local"));
+
+    assertAll("Command run failed",
+        () -> assertTrue(cr2.isSuccess()),
+        () -> assertTrue(
+            cr2.getResult().toString().startsWith("Succeeded to run clustering 
for scheduleAndExecute")));
+
+    // assert clustering complete
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+            .getCompletedReplaceTimeline().getInstants()
+            .map(HoodieInstant::getTimestamp).count() > 0,
+        "Completed clustering couldn't be 0");
+  }
+
+  private String prepareScheduleClustering() {
+    // generate requested clustering
+    CommandResult cr = getShell().executeCommand(
+        String.format("clustering schedule --hoodieConfigs 
hoodie.clustering.inline.max.commits=1 --sparkMaster %s",
+            "local"));
+    assertTrue(cr.isSuccess());
+
+    // get clustering instance
+    HoodieActiveTimeline timeline = 
HoodieCLI.getTableMetaClient().getActiveTimeline();
+    Option<String> instance =

Review comment:
       Okay, Changed. Thanks a lot for your review :)

##########
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/integ/ITTestClusteringCommand.java
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.integ;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.commands.TableCommand;
+import org.apache.hudi.cli.testutils.AbstractShellIntegrationTest;
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.client.common.HoodieSparkEngineContext;
+import org.apache.hudi.common.model.HoodieAvroPayload;
+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.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.index.HoodieIndex;
+import org.apache.hudi.testutils.HoodieClientTestBase;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test class for {@link 
org.apache.hudi.cli.commands.ClusteringCommand}.
+ * <p/>
+ * A command use SparkLauncher need load jars under lib which generate during 
mvn package.
+ * Use integration test instead of unit test.
+ */
+public class ITTestClusteringCommand extends AbstractShellIntegrationTest {
+
+  private String tablePath;
+  private String tableName;
+
+  @BeforeEach
+  public void init() throws IOException {
+    tableName = "test_table_" + ITTestClusteringCommand.class.getName();
+    tablePath = Paths.get(basePath, tableName).toString();
+
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+    // Create table and connect
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(),
+        "", TimelineLayoutVersion.VERSION_1, 
"org.apache.hudi.common.model.HoodieAvroPayload");
+    metaClient.setBasePath(tablePath);
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+  }
+
+  /**
+   * Test case for command 'clustering schedule'.
+   */
+  @Test
+  public void testScheduleClustering() throws IOException {
+    // generate commits
+    generateCommits();
+
+    CommandResult cr = getShell().executeCommand(
+        String.format("clustering schedule --hoodieConfigs 
hoodie.clustering.inline.max.commits=1 --sparkMaster %s",
+            "local"));
+    assertAll("Command run failed",
+        () -> assertTrue(cr.isSuccess()),
+        () -> assertTrue(
+            cr.getResult().toString().startsWith("Succeeded to schedule 
clustering for")));
+
+    // there is 1 requested clustering
+    HoodieActiveTimeline timeline = 
HoodieCLI.getTableMetaClient().getActiveTimeline();
+    assertEquals(1, timeline.filterPendingReplaceTimeline().countInstants());
+  }
+
+  /**
+   * Test case for command 'clustering run'.
+   */
+  @Test
+  public void testClustering() throws IOException {
+    // generate commits
+    generateCommits();
+
+    String instance = prepareScheduleClustering();
+
+    CommandResult cr2 = getShell().executeCommand(
+        String.format("clustering run --parallelism %s --clusteringInstant %s 
--sparkMaster %s",
+            2, instance, "local"));
+
+    assertAll("Command run failed",
+        () -> assertTrue(cr2.isSuccess()),
+        () -> assertTrue(
+            cr2.getResult().toString().startsWith("Succeeded to run clustering 
for ")));
+
+    // assert clustering complete
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+        .filterCompletedInstants().getInstants()
+        
.map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance),
+        "Pending clustering must be completed");
+
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+            .getCompletedReplaceTimeline().getInstants()
+            
.map(HoodieInstant::getTimestamp).collect(Collectors.toList()).contains(instance),
+        "Pending clustering must be completed");
+  }
+
+  /**
+   * Test case for command 'clustering scheduleAndExecute'.
+   */
+  @Test
+  public void testClusteringScheduleAndExecute() throws IOException {
+    // generate commits
+    generateCommits();
+
+    CommandResult cr2 = getShell().executeCommand(
+        String.format("clustering scheduleAndExecute --parallelism %s 
--sparkMaster %s", 2, "local"));
+
+    assertAll("Command run failed",
+        () -> assertTrue(cr2.isSuccess()),
+        () -> assertTrue(
+            cr2.getResult().toString().startsWith("Succeeded to run clustering 
for scheduleAndExecute")));
+
+    // assert clustering complete
+    assertTrue(HoodieCLI.getTableMetaClient().getActiveTimeline().reload()
+            .getCompletedReplaceTimeline().getInstants()
+            .map(HoodieInstant::getTimestamp).count() > 0,
+        "Completed clustering couldn't be 0");
+  }
+
+  private String prepareScheduleClustering() {
+    // generate requested clustering
+    CommandResult cr = getShell().executeCommand(
+        String.format("clustering schedule --hoodieConfigs 
hoodie.clustering.inline.max.commits=1 --sparkMaster %s",
+            "local"));
+    assertTrue(cr.isSuccess());
+
+    // get clustering instance
+    HoodieActiveTimeline timeline = 
HoodieCLI.getTableMetaClient().getActiveTimeline();
+    Option<String> instance =
+        
timeline.filterPendingReplaceTimeline().firstInstant().map(HoodieInstant::getTimestamp);
+    assertTrue(instance.isPresent(), "Must have pending clustering.");

Review comment:
       Sure, thing. Changed.




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


Reply via email to