voonhous commented on code in PR #19877: URL: https://github.com/apache/hudi/pull/19877#discussion_r3975344221
########## hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestClusteringCommand.java: ########## @@ -0,0 +1,110 @@ +/* + * 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.HoodieCLI; +import org.apache.hudi.cli.functional.CLIFunctionalTestHarness; +import org.apache.hudi.client.SparkRDDWriteClient; +import org.apache.hudi.client.WriteStatus; +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.HoodieTableVersion; +import org.apache.hudi.common.testutils.HoodieTestDataGenerator; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.testutils.Assertions; +import org.apache.hudi.utilities.UtilHelpers; + +import org.apache.spark.api.java.JavaRDD; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static org.apache.hudi.common.testutils.HoodieTestDataGenerator.DEFAULT_FIRST_PARTITION_PATH; +import static org.apache.hudi.common.testutils.HoodieTestDataGenerator.TRIP_EXAMPLE_SCHEMA; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Test cases for the clustering entry point of {@link SparkMain}, which the clustering commands + * reach through a spark-submit of their own. + */ +@Tag("functional") +@SpringBootTest(properties = {"spring.shell.interactive.enabled=false", "spring.shell.command.script.enabled=false"}) +public class TestClusteringCommand extends CLIFunctionalTestHarness { + + private String tableName; + private String tablePath; + + @BeforeEach + public void init() throws IOException { + HoodieCLI.conf = storageConf(); + tableName = tableName(); + tablePath = tablePath(tableName); + + new TableCommand().createTable( + tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(), + "", HoodieTableVersion.current().versionCode(), HoodieAvroPayload.class.getName()); + } + + @Test + public void testSparkMainClusterScheduleAndExecute() throws Exception { + writeCommits(); + HoodieTableMetaClient metaClient = HoodieTableMetaClient.reload(HoodieCLI.getTableMetaClient()); + assertEquals(0, metaClient.getActiveTimeline().filterPendingClusteringTimeline().countInstants()); + + int returnCode = SparkMain.cluster(jsc(), tablePath, tableName, null, 1, "1g", 0, + UtilHelpers.SCHEDULE_AND_EXECUTE, null, + Collections.singletonList("hoodie.clustering.inline.max.commits=1")); Review Comment: Right, the plan came from the size-based strategy all along. Dropped the override; the test still schedules and executes a plan. Done in 513e0a1d8f83. ########## hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCompactionCommand.java: ########## @@ -146,6 +173,203 @@ public void testCompactionShow() throws IOException { assertNotNull(result); } + /** + * Test case of the compaction validation entry point of {@link SparkMain}, which the + * 'compaction validate' command reaches through a spark-submit of its own. + */ + @Test + public void testSparkMainCompactValidate() throws Exception { + createPendingCompactions(); + String outputPath = outputPath("validate"); + + SparkMain.doCompactValidate(jsc(), tablePath, PENDING_COMPACTION_INSTANT, outputPath, 2); + + List<ValidationOpResult> results = readOperationResults(outputPath); + assertEquals(operationsOf(PENDING_COMPACTION_INSTANT).size(), results.size()); + assertTrue(results.stream().allMatch(ValidationOpResult::isSuccess), results.toString()); + assertEquals(fileIdsOf(PENDING_COMPACTION_INSTANT), + results.stream().map(result -> result.getOperation().getFileId()).collect(Collectors.toSet())); + } + + @Test + public void testSparkMainCompactValidateReportsMissingLogFile() throws Exception { + createPendingCompactions(); + HoodieCompactionOperation broken = operationsOf(PENDING_COMPACTION_INSTANT).get(0); + // a log file the plan reads is gone, so that operation can no longer be compacted + Files.delete(Paths.get(tablePath, broken.getPartitionPath(), broken.getDeltaFilePaths().get(0))); + String outputPath = outputPath("validate-broken"); + + SparkMain.doCompactValidate(jsc(), tablePath, PENDING_COMPACTION_INSTANT, outputPath, 2); + + List<ValidationOpResult> results = readOperationResults(outputPath); + assertEquals(operationsOf(PENDING_COMPACTION_INSTANT).size(), results.size()); + List<ValidationOpResult> failed = results.stream().filter(result -> !result.isSuccess()).collect(Collectors.toList()); + assertEquals(1, failed.size(), results.toString()); + assertEquals(broken.getFileId(), failed.get(0).getOperation().getFileId()); + assertTrue(failed.get(0).getException().isPresent()); + } + + /** + * Repair only validates the plan and reports the renames it would need; with the plan intact Review Comment: Done: single `@Test`, the renames claim is gone from the javadoc, and the pointer to #19881 (dryRun ignored) stays. Done in 513e0a1d8f83. -- 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]
