fengjian428 commented on code in PR #6144:
URL: https://github.com/apache/hudi/pull/6144#discussion_r937933197


##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/table/action/compact/TestInlineCompaction.java:
##########
@@ -93,6 +96,58 @@ public void testSuccessfulCompactionBasedOnNumCommits() 
throws Exception {
     }
   }
 
+  @Test
+  public void testSuccessfulCompactionBasedOnNumAfterCompactionRequest() 
throws Exception {
+    // Given: make 4 commits
+    HoodieWriteConfig cfg = getConfigForInlineCompaction(4, 60, 
CompactionTriggerStrategy.NUM_COMMITS_AFTER_LAST_REQUEST);
+
+    List<String> instants = IntStream.range(0, 3).mapToObj(i -> 
HoodieActiveTimeline.createNewInstantTime()).collect(Collectors.toList());
+
+    try (SparkRDDWriteClient<?> writeClient = getHoodieWriteClient(cfg)) {
+      List<HoodieRecord> records = dataGen.generateInserts(instants.get(0), 
100);
+      HoodieReadClient readClient = getHoodieReadClient(cfg.getBasePath());
+
+      // step 1: create and complete 3 commit
+      runNextDeltaCommits(writeClient, readClient, instants, records, cfg, 
true, new ArrayList<>());
+
+      metaClient = 
HoodieTableMetaClient.builder().setConf(hadoopConf).setBasePath(cfg.getBasePath()).build();
+
+      // step 2: force create a compaction request, but won't run it
+      cfg.setValue(INLINE_COMPACT_NUM_DELTA_COMMITS, "1");
+      String requestInstant = HoodieActiveTimeline.createNewInstantTime();
+      // add one compaction request
+      scheduleCompaction(requestInstant, writeClient, cfg);
+      metaClient.getActiveTimeline().reload();
+      assertEquals(metaClient.getActiveTimeline().getInstants()
+            .filter(hoodieInstant -> 
hoodieInstant.getAction().equals(HoodieTimeline.COMPACTION_ACTION)
+            && hoodieInstant.getState() == 
HoodieInstant.State.REQUESTED).count(), 1);
+      // step 3: try to create another, but this one should fail because the 
NUM_COMMITS_AFTER_LAST_REQUEST strategy ,
+      // and will throw a AssertionError due to scheduleCompaction will check 
if the last instant is a compaction request
+      requestInstant = HoodieActiveTimeline.createNewInstantTime();
+      try {
+        scheduleCompaction(requestInstant, writeClient, cfg);
+        Assertions.fail();
+      } catch (AssertionError error) {
+        //should be here
+      }
+      cfg.setValue(INLINE_COMPACT_NUM_DELTA_COMMITS, "4");
+
+      // step 4: complete the last commit, and this commit also won't generate 
another compaction request
+      // only trigger last compaction request

Review Comment:
   just want to change the config back. 
   I feel trigger last compaction request is equal to executing compaction? Do 
you mean only if trigger the last compaction request, the next compaction 
request would happen?



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