n3nash 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_r372561723
########## 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); Review comment: In general, if you're not checking against the "commitTime" of the hoodie instant, can you simply use the ActiveTime.getInstant() to get a valid commit time instead of passing "1", "2" etc. One of the reasons is to standardize this across all tests - all other tests use commit times in the following format -> "000", "001" if they want to check against a deterministic commit time in the test.. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services