Search in sources :

Example 21 with HoodieTestTable

use of org.apache.hudi.common.testutils.HoodieTestTable in project hudi by apache.

the class TestCleaner method testCleanMarkerDataFilesOnRollback.

/**
 * Test Cleaning functionality of table.rollback() API.
 */
@Test
public void testCleanMarkerDataFilesOnRollback() throws Exception {
    HoodieTestTable testTable = HoodieTestTable.of(metaClient).addRequestedCommit("001").withMarkerFiles("default", 10, IOType.MERGE);
    final int numTempFilesBefore = testTable.listAllFilesInTempFolder().length;
    assertEquals(10, numTempFilesBefore, "Some marker files are created.");
    HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withFileSystemViewConfig(FileSystemViewStorageConfig.newBuilder().withRemoteServerPort(timelineServicePort).build()).withPath(basePath).build();
    metaClient = HoodieTableMetaClient.reload(metaClient);
    HoodieTable table = HoodieSparkTable.create(config, context, metaClient);
    table.getActiveTimeline().transitionRequestedToInflight(new HoodieInstant(State.REQUESTED, HoodieTimeline.COMMIT_ACTION, "001"), Option.empty());
    metaClient.reloadActiveTimeline();
    HoodieInstant rollbackInstant = new HoodieInstant(State.INFLIGHT, HoodieTimeline.COMMIT_ACTION, "001");
    table.scheduleRollback(context, "002", rollbackInstant, false, config.shouldRollbackUsingMarkers());
    table.rollback(context, "002", rollbackInstant, true, false);
    final int numTempFilesAfter = testTable.listAllFilesInTempFolder().length;
    assertEquals(0, numTempFilesAfter, "All temp files are deleted.");
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieTestTable(org.apache.hudi.common.testutils.HoodieTestTable) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 22 with HoodieTestTable

use of org.apache.hudi.common.testutils.HoodieTestTable in project hudi by apache.

the class TestMarkerBasedRollbackStrategy method testMarkerBasedRollbackAppend.

@Test
public void testMarkerBasedRollbackAppend() throws Exception {
    HoodieTestTable testTable = HoodieTestTable.of(metaClient);
    String f0 = testTable.addRequestedCommit("000").getFileIdsWithBaseFilesInPartitions("partA").get("partA");
    testTable.forCommit("001").withMarkerFile("partA", f0, IOType.APPEND);
    HoodieTable hoodieTable = HoodieSparkTable.create(getConfig(), context, metaClient);
    List<HoodieRollbackRequest> rollbackRequests = new MarkerBasedRollbackStrategy(hoodieTable, context, getConfig(), "002").getRollbackRequests(new HoodieInstant(HoodieInstant.State.INFLIGHT, HoodieTimeline.COMMIT_ACTION, "001"));
    assertEquals(1, rollbackRequests.size());
}
Also used : HoodieInstant(org.apache.hudi.common.table.timeline.HoodieInstant) HoodieTestTable(org.apache.hudi.common.testutils.HoodieTestTable) HoodieTable(org.apache.hudi.table.HoodieTable) HoodieRollbackRequest(org.apache.hudi.avro.model.HoodieRollbackRequest) MarkerBasedRollbackStrategy(org.apache.hudi.table.action.rollback.MarkerBasedRollbackStrategy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HoodieTestTable (org.apache.hudi.common.testutils.HoodieTestTable)22 Test (org.junit.jupiter.api.Test)17 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)14 List (java.util.List)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 HashMap (java.util.HashMap)10 HoodieInstant (org.apache.hudi.common.table.timeline.HoodieInstant)10 HoodieCleanStat (org.apache.hudi.common.HoodieCleanStat)9 Map (java.util.Map)8 FileStatus (org.apache.hadoop.fs.FileStatus)8 IOException (java.io.IOException)7 Arrays (java.util.Arrays)7 Collections (java.util.Collections)7 Collectors (java.util.stream.Collectors)7 Path (org.apache.hadoop.fs.Path)7 HoodieCommonTestHarness (org.apache.hudi.common.testutils.HoodieCommonTestHarness)7 HoodieTableMetadataWriter (org.apache.hudi.metadata.HoodieTableMetadataWriter)7 Assertions (org.junit.jupiter.api.Assertions)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ArrayList (java.util.ArrayList)5