hudi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-hudi] prashantwason commented on a change in pull request #1287: [HUDI-566] Added new test cases for class HoodieTimeline, HoodieDefaultTimeline and HoodieActiveTimeline.
Date Thu, 30 Jan 2020 22:02:45 GMT
prashantwason commented on a change in pull request #1287: [HUDI-566] Added new test cases
for class HoodieTimeline, HoodieDefaultTimeline and HoodieActiveTimeline.
URL: https://github.com/apache/incubator-hudi/pull/1287#discussion_r373217796
 
 

 ##########
 File path: hudi-common/src/test/java/org/apache/hudi/common/table/string/TestHoodieActiveTimeline.java
 ##########
 @@ -164,4 +173,242 @@ public void testTimelineOperations() {
     assertFalse("", activeCommitTimeline.isBeforeTimelineStarts("02"));
     assertTrue("", activeCommitTimeline.isBeforeTimelineStarts("00"));
   }
+
+  @Test
+  public void testTimelineGetOperations() {
+    Vector<HoodieInstant> allInstants = getAllInstants();
+    Supplier<Stream<HoodieInstant>> sup = () -> allInstants.stream();
+    timeline = new HoodieActiveTimeline(metaClient, true);
+    timeline.setInstants(allInstants);
+
+    BiConsumer<HoodieTimeline, Set<String>> checkTimeline = (HoodieTimeline timeline,
Set<String> actions) -> {
+      sup.get().filter(i -> actions.contains(i.getAction())).forEach(i -> assertTrue(timeline.containsInstant(i)));
+      sup.get().filter(i -> !actions.contains(i.getAction())).forEach(i -> assertFalse(timeline.containsInstant(i)));
+    };
+
+    // Test that various types of getXXX operations from HoodieActiveTimeline
+    // return the correct set of Instant
+    checkTimeline.accept(timeline.getCommitsTimeline(),
+            Sets.newHashSet(HoodieTimeline.COMMIT_ACTION, HoodieTimeline.DELTA_COMMIT_ACTION));
+    checkTimeline.accept(timeline.getCommitsAndCompactionTimeline(),
+            Sets.newHashSet(HoodieTimeline.COMMIT_ACTION, HoodieTimeline.DELTA_COMMIT_ACTION,
HoodieTimeline.COMPACTION_ACTION));
+    checkTimeline.accept(timeline.getCommitTimeline(), Sets.newHashSet(HoodieTimeline.COMMIT_ACTION));
+
+    checkTimeline.accept(timeline.getDeltaCommitTimeline(), Sets.newHashSet(HoodieTimeline.DELTA_COMMIT_ACTION));
+    checkTimeline.accept(timeline.getCleanerTimeline(), Sets.newHashSet(HoodieTimeline.CLEAN_ACTION));
+    checkTimeline.accept(timeline.getRollbackTimeline(), Sets.newHashSet(HoodieTimeline.ROLLBACK_ACTION));
+    checkTimeline.accept(timeline.getRestoreTimeline(), Sets.newHashSet(HoodieTimeline.RESTORE_ACTION));
+    checkTimeline.accept(timeline.getSavePointTimeline(), Sets.newHashSet(HoodieTimeline.SAVEPOINT_ACTION));
+    checkTimeline.accept(timeline.getAllCommitsTimeline(),
+            Sets.newHashSet(HoodieTimeline.COMMIT_ACTION, HoodieTimeline.DELTA_COMMIT_ACTION,
+                    HoodieTimeline.CLEAN_ACTION, HoodieTimeline.COMPACTION_ACTION,
+                    HoodieTimeline.SAVEPOINT_ACTION, HoodieTimeline.ROLLBACK_ACTION));
+
+    // Get some random Instants
+    Random rand = new Random();
+    Set<String> randomInstants = sup.get().filter(i -> rand.nextBoolean())
+                                          .map(i -> i.getAction())
+                                          .collect(Collectors.toSet());
+    checkTimeline.accept(timeline.getTimelineOfActions(randomInstants), randomInstants);
+  }
+
+  @Test
+  public void testTimelineInstantOperations() {
+    timeline = new HoodieActiveTimeline(metaClient, true);
+    assertEquals("No instant present", timeline.countInstants(), 0);
+
+    // revertToInflight
+    HoodieInstant commit = new HoodieInstant(State.COMPLETED, HoodieTimeline.COMMIT_ACTION,
"1");
+    timeline.createNewInstant(commit);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    assertTrue(timeline.containsInstant(commit));
+    HoodieInstant inflight = timeline.revertToInflight(commit);
+    // revert creates the .requested file
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    assertTrue(timeline.containsInstant(inflight));
+    assertFalse(timeline.containsInstant(commit));
+
+    // deleteInflight
+    timeline.deleteInflight(inflight);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    assertFalse(timeline.containsInstant(inflight));
+    assertFalse(timeline.containsInstant(commit));
+
+    // deletePending
+    timeline.createNewInstant(commit);
+    timeline.createNewInstant(inflight);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    timeline.deletePending(inflight);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    assertFalse(timeline.containsInstant(inflight));
+    assertTrue(timeline.containsInstant(commit));
+
+    // deleteCompactionRequested
+    HoodieInstant compaction = new HoodieInstant(State.REQUESTED, HoodieTimeline.COMPACTION_ACTION,
"2");
+    timeline.createNewInstant(compaction);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 2);
+    timeline.deleteCompactionRequested(compaction);
+    timeline = timeline.reload();
+    assertEquals(timeline.countInstants(), 1);
+    assertFalse(timeline.containsInstant(inflight));
+    assertFalse(timeline.containsInstant(compaction));
+    assertTrue(timeline.containsInstant(commit));
+
+    // transitionCompactionXXXtoYYY and revertCompactionXXXtoYYY
+    compaction = new HoodieInstant(State.REQUESTED, HoodieTimeline.COMPACTION_ACTION, "3");
+    timeline.createNewInstant(compaction);
+    timeline = timeline.reload();
+    assertTrue(timeline.containsInstant(compaction));
+    inflight = timeline.transitionCompactionRequestedToInflight(compaction);
+    timeline = timeline.reload();
+    assertFalse(timeline.containsInstant(compaction));
+    assertTrue(timeline.containsInstant(inflight));
+    compaction = timeline.revertCompactionInflightToRequested(inflight);
+    timeline = timeline.reload();
+    assertTrue(timeline.containsInstant(compaction));
+    assertFalse(timeline.containsInstant(inflight));
+    inflight = timeline.transitionCompactionRequestedToInflight(compaction);
+    compaction = timeline.transitionCompactionInflightToComplete(inflight, Option.empty());
+    timeline = timeline.reload();
+    assertTrue(timeline.containsInstant(compaction));
+    assertFalse(timeline.containsInstant(inflight));
+
+    // transitionCleanXXXtoYYY
+    HoodieInstant clean = new HoodieInstant(State.REQUESTED, HoodieTimeline.CLEAN_ACTION,
"4");
+    timeline.saveToCleanRequested(clean, Option.empty());
+    timeline = timeline.reload();
+    assertTrue(timeline.containsInstant(clean));
+    inflight = timeline.transitionCleanRequestedToInflight(clean, Option.empty());
+    timeline = timeline.reload();
+    assertFalse(timeline.containsInstant(clean));
+    assertTrue(timeline.containsInstant(inflight));
+    clean = timeline.transitionCleanInflightToComplete(inflight, Option.empty());
+    timeline = timeline.reload();
+    assertTrue(timeline.containsInstant(clean));
+    assertFalse(timeline.containsInstant(inflight));
+
+    // Various states of Instants
+    HoodieInstant srcInstant = new HoodieInstant(State.COMPLETED, HoodieTimeline.RESTORE_ACTION,
"5");
+    HoodieInstant otherInstant = HoodieTimeline.getRequestedInstant(srcInstant);
+    assertEquals(otherInstant, new HoodieInstant(State.REQUESTED, HoodieTimeline.RESTORE_ACTION,
"5"));
+    otherInstant = HoodieTimeline.getCleanRequestedInstant("5");
+    assertEquals(otherInstant, new HoodieInstant(State.REQUESTED, HoodieTimeline.CLEAN_ACTION,
"5"));
+    otherInstant = HoodieTimeline.getCleanInflightInstant("5");
+    assertEquals(otherInstant, new HoodieInstant(State.INFLIGHT, HoodieTimeline.CLEAN_ACTION,
"5"));
+    otherInstant = HoodieTimeline.getCompactionRequestedInstant("5");
+    assertEquals(otherInstant, new HoodieInstant(State.REQUESTED, HoodieTimeline.COMPACTION_ACTION,
"5"));
+    otherInstant = HoodieTimeline.getCompactionInflightInstant("5");
+    assertEquals(otherInstant, new HoodieInstant(State.INFLIGHT, HoodieTimeline.COMPACTION_ACTION,
"5"));
+
+    // containsOrBeforeTimelineStarts
+    Vector<HoodieInstant> allInstants = getAllInstants();
+    timeline = new HoodieActiveTimeline(metaClient, true);
+    timeline.setInstants(allInstants);
+
+    timeline.setInstants(allInstants);
+    timeline.createNewInstant(new HoodieInstant(State.REQUESTED, HoodieTimeline.COMMIT_ACTION,
"2"));
+    allInstants.stream().map(i -> i.getTimestamp()).forEach(s -> assertTrue(timeline.containsOrBeforeTimelineStarts(s)));
+    assertTrue(timeline.containsOrBeforeTimelineStarts("0"));
+    assertFalse(timeline.containsOrBeforeTimelineStarts(String.valueOf(System.currentTimeMillis()
+ 1000)));
+    assertFalse(timeline.getTimelineHash().isEmpty());
+
+    // Etc.
+    timeline.getInstantDetails(clean);
 
 Review comment:
   removed.

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


With regards,
Apache Git Services

Mime
View raw message