yanghua commented on a change in pull request #1449: [WIP][HUDI-698]Add unit 
test for CleansCommand
URL: https://github.com/apache/incubator-hudi/pull/1449#discussion_r405277008
 
 

 ##########
 File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCleansCommand.java
 ##########
 @@ -0,0 +1,167 @@
+/*
+ * 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.hadoop.conf.Configuration;
+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.model.HoodieCleaningPolicy;
+import org.apache.hudi.common.model.HoodiePartitionMetadata;
+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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link CleansCommand}.
+ */
+public class TestCleansCommand extends AbstractShellIntegrationTest {
+
+  private String tablePath;
+  private String propsFilePath;
+
+  @Before
+  public void init() throws IOException {
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    propsFilePath = 
this.getClass().getClassLoader().getResource("clean.properties").getPath();
+
+    // Create table and connect
+    new TableCommand().createTable(
+        tablePath, tableName,
+        "COPY_ON_WRITE", "", 1, 
"org.apache.hudi.common.model.HoodieAvroPayload");
+
+    Configuration conf = HoodieCLI.conf;
+
+    metaClient = HoodieCLI.getTableMetaClient();
+    // Create four commits
+    for (int i = 100; i < 104; i++) {
+      String timestamp = String.valueOf(i);
+      // Requested Compaction
+      
HoodieTestCommitMetadataGenerator.createCompactionAuxiliaryMetadata(tablePath,
+          new HoodieInstant(HoodieInstant.State.REQUESTED, 
HoodieTimeline.COMPACTION_ACTION, timestamp), conf);
+      // Inflight Compaction
+      
HoodieTestCommitMetadataGenerator.createCompactionAuxiliaryMetadata(tablePath,
+          new HoodieInstant(HoodieInstant.State.INFLIGHT, 
HoodieTimeline.COMPACTION_ACTION, timestamp), conf);
+      
HoodieTestCommitMetadataGenerator.createCommitFileWithMetadata(tablePath, 
timestamp, conf);
+    }
+
+    metaClient = HoodieTableMetaClient.reload(metaClient);
+    // reload the timeline and get all the commits before archive
+    metaClient.getActiveTimeline().reload();
+  }
+
+  /**
+   * Test case for cleans run.
+   */
+  @Test
+  public void testRunClean() throws IOException {
+    // First, there should none of clean instant.
+    assertEquals(0, 
metaClient.getActiveTimeline().reload().getCleanerTimeline().getInstants().count());
+
+    // Create partition metadata
+    new File(tablePath + File.separator + 
HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH
+        + File.separator + 
HoodiePartitionMetadata.HOODIE_PARTITION_METAFILE).createNewFile();
+    new File(tablePath + File.separator + 
HoodieTestCommitMetadataGenerator.DEFAULT_SECOND_PARTITION_PATH
+        + File.separator + 
HoodiePartitionMetadata.HOODIE_PARTITION_METAFILE).createNewFile();
+
+    CommandResult cr = getShell().executeCommand("cleans run --sparkMaster 
local --propsFilePath " + propsFilePath);
+    assertTrue(cr.isSuccess());
 
 Review comment:
   @vinothchandar I have no good solution. WDYT about this issue?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to