voonhous commented on code in PR #18816:
URL: https://github.com/apache/hudi/pull/18816#discussion_r3887430215
##########
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestRepairsCommand.java:
##########
@@ -18,434 +18,51 @@
package org.apache.hudi.cli.commands;
-import org.apache.hudi.cli.HoodieCLI;
-import org.apache.hudi.cli.HoodiePrintHelper;
-import org.apache.hudi.cli.HoodieTableHeaderFields;
-import org.apache.hudi.cli.functional.CLIFunctionalTestHarness;
-import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
-import org.apache.hudi.cli.testutils.ShellEvaluationResultUtil;
-import org.apache.hudi.client.SparkRDDWriteClient;
-import org.apache.hudi.client.WriteClientTestUtils;
-import org.apache.hudi.client.WriteStatus;
-import org.apache.hudi.common.fs.FSUtils;
-import org.apache.hudi.common.model.HoodieAvroIndexedRecord;
-import org.apache.hudi.common.model.HoodieKey;
-import org.apache.hudi.common.model.HoodieRecord;
-import org.apache.hudi.common.model.HoodieTableType;
-import org.apache.hudi.common.table.HoodieTableConfig;
import org.apache.hudi.common.table.HoodieTableMetaClient;
-import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
-import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
-import org.apache.hudi.common.util.PartitionPathEncodeUtils;
-import org.apache.hudi.config.HoodieWriteConfig;
-import org.apache.hudi.hadoop.fs.HadoopFSUtils;
-import org.apache.hudi.keygen.SimpleKeyGenerator;
-import org.apache.hudi.storage.StorageConfiguration;
-import org.apache.hudi.storage.HoodieStorageUtils;
-import org.apache.hudi.testutils.Assertions;
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.storage.hadoop.HadoopStorageConfiguration;
-import org.apache.avro.generic.GenericRecord;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.Logger;
-import org.apache.logging.log4j.core.appender.AbstractAppender;
-import org.apache.spark.api.java.JavaRDD;
-import org.apache.spark.sql.SQLContext;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.shell.Shell;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.net.URL;
import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.stream.Collectors;
-import static
org.apache.hudi.common.table.HoodieTableConfig.DROP_PARTITION_COLUMNS;
-import static org.apache.hudi.common.table.HoodieTableConfig.NAME;
-import static org.apache.hudi.common.table.HoodieTableConfig.TABLE_CHECKSUM;
-import static
org.apache.hudi.common.table.HoodieTableConfig.TIMELINE_HISTORY_PATH;
-import static
org.apache.hudi.common.table.HoodieTableConfig.TIMELINE_LAYOUT_VERSION;
-import static org.apache.hudi.common.table.HoodieTableConfig.TYPE;
-import static org.apache.hudi.common.table.HoodieTableConfig.VERSION;
-import static org.apache.hudi.common.table.HoodieTableConfig.generateChecksum;
-import static org.apache.hudi.common.table.HoodieTableConfig.validateChecksum;
-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;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-/**
- * Test class for {@link RepairsCommand}.
- */
-@Tag("functional")
-@SpringBootTest(properties = {"spring.shell.interactive.enabled=false",
"spring.shell.command.script.enabled=false"})
-public class TestRepairsCommand extends CLIFunctionalTestHarness {
-
- @Autowired
- private Shell shell;
+public class TestRepairsCommand {
+ private RepairsCommand repairsCommand;
+ private HoodieTableMetaClient metaClient;
private String tablePath;
- private FileSystem fs;
@BeforeEach
public void init() throws IOException {
- String tableName = tableName();
- tablePath = tablePath(tableName);
- fs = HadoopFSUtils.getFs(tablePath, storageConf());
-
- // Create table and connect
- new TableCommand().createTable(
- tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(),
- HoodieTableConfig.TIMELINE_HISTORY_PATH.defaultValue(),
TimelineLayoutVersion.VERSION_1,
"org.apache.hudi.common.model.HoodieAvroPayload");
- }
-
- @AfterEach
- public void cleanUp() throws IOException {
- fs.close();
+ repairsCommand = new RepairsCommand();
+ tablePath =
Files.createTempDirectory("test_table").toAbsolutePath().toString();
+
+ metaClient = HoodieTableMetaClient.newTableBuilder()
+ .setTableType("COPY_ON_WRITE")
+ .setTableName("test_table")
+
.setPayloadClassName("org.apache.hudi.common.model.OverwriteWithLatestAvroPayload")
+ .setTableVersion(HoodieTableVersion.current().versionCode())
+ .initTable(new HadoopStorageConfiguration(new
org.apache.hadoop.conf.Configuration()), tablePath);
}
- /**
- * Test case for dry run 'repair addpartitionmeta'.
- */
@Test
- public void testAddPartitionMetaWithDryRun() throws IOException {
- // create commit instant
- Files.createFile(Paths.get(tablePath, ".hoodie/timeline/", "100.commit"));
-
- // create partition path
- String partition1 = Paths.get(tablePath,
HoodieTestDataGenerator.DEFAULT_FIRST_PARTITION_PATH).toString();
- String partition2 = Paths.get(tablePath,
HoodieTestDataGenerator.DEFAULT_SECOND_PARTITION_PATH).toString();
- String partition3 = Paths.get(tablePath,
HoodieTestDataGenerator.DEFAULT_THIRD_PARTITION_PATH).toString();
- assertTrue(fs.mkdirs(new Path(partition1)));
- assertTrue(fs.mkdirs(new Path(partition2)));
- assertTrue(fs.mkdirs(new Path(partition3)));
-
- // default is dry run.
- Object result = shell.evaluate(() -> "repair addpartitionmeta");
- assertTrue(ShellEvaluationResultUtil.isSuccess(result));
-
- // expected all 'No'.
- String[][] rows = FSUtils.getAllPartitionFoldersThreeLevelsDown(
- HoodieStorageUtils.getStorage(
- HadoopFSUtils.convertToStoragePath(new Path(tablePath)),
- HadoopFSUtils.getStorageConf(fs.getConf())), tablePath)
- .stream()
- .map(partition -> new String[] {partition, "No", "None"})
- .toArray(String[][]::new);
- String expected = HoodiePrintHelper.print(new String[]
{HoodieTableHeaderFields.HEADER_PARTITION_PATH,
- HoodieTableHeaderFields.HEADER_METADATA_PRESENT,
HoodieTableHeaderFields.HEADER_ACTION}, rows);
- expected = removeNonWordAndStripSpace(expected);
- String got = removeNonWordAndStripSpace(result.toString());
- assertEquals(expected, got);
+ public void testAddPartitionMetaDryRun() {
+ String result = repairsCommand.addPartitionMeta(true);
+ assertEquals("Partition metadata added successfully", result);
}
Review Comment:
No longer applies -- follows from the production class not having been
gutted on the current head. `addPartitionMeta` is intact, so the test is not
exercising a stub.
--
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]