use of org.apache.hudi.common.testutils.MockHoodieTimeline in project hudi by apache.
the class TestHoodieActiveTimeline method testTimelineOperations.
@Test
public void testTimelineOperations() {
timeline = new MockHoodieTimeline(Stream.of("01", "03", "05", "07", "09", "11", "13", "15", "17", "19"), Stream.of("21", "23"));
assertStreamEquals(Stream.of("05", "07", "09", "11"), timeline.getCommitTimeline().filterCompletedInstants().findInstantsInRange("04", "11").getInstants().map(HoodieInstant::getTimestamp), "findInstantsInRange should return 4 instants");
assertStreamEquals(Stream.of("09", "11"), timeline.getCommitTimeline().filterCompletedInstants().findInstantsAfter("07", 2).getInstants().map(HoodieInstant::getTimestamp), "findInstantsAfter 07 should return 2 instants");
assertStreamEquals(Stream.of("01", "03", "05"), timeline.getCommitTimeline().filterCompletedInstants().findInstantsBefore("07").getInstants().map(HoodieInstant::getTimestamp), "findInstantsBefore 07 should return 3 instants");
assertFalse(timeline.empty());
assertFalse(timeline.getCommitTimeline().filterPendingExcludingCompaction().empty());
assertEquals(12, timeline.countInstants());
assertEquals("01", timeline.firstInstant(HoodieTimeline.COMMIT_ACTION, State.COMPLETED).get().getTimestamp());
assertEquals("21", timeline.firstInstant(HoodieTimeline.COMMIT_ACTION, State.INFLIGHT).get().getTimestamp());
assertFalse(timeline.firstInstant(HoodieTimeline.COMMIT_ACTION, State.REQUESTED).isPresent());
assertFalse(timeline.firstInstant(HoodieTimeline.REPLACE_COMMIT_ACTION, State.COMPLETED).isPresent());
HoodieTimeline activeCommitTimeline = timeline.getCommitTimeline().filterCompletedInstants();
assertEquals(10, activeCommitTimeline.countInstants());
assertEquals("01", activeCommitTimeline.firstInstant().get().getTimestamp());
assertEquals("11", activeCommitTimeline.nthInstant(5).get().getTimestamp());
assertEquals("19", activeCommitTimeline.lastInstant().get().getTimestamp());
assertEquals("09", activeCommitTimeline.nthFromLastInstant(5).get().getTimestamp());
assertTrue(activeCommitTimeline.containsInstant(new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, "09")));
assertFalse(activeCommitTimeline.isBeforeTimelineStarts("02"));
assertTrue(activeCommitTimeline.isBeforeTimelineStarts("00"));
}
use of org.apache.hudi.common.testutils.MockHoodieTimeline in project hudi by apache.
the class TestHoodieFileGroup method testCommittedFileSlices.
@Test
public void testCommittedFileSlices() {
// "000" is archived
Stream<String> completed = Arrays.asList("001").stream();
Stream<String> inflight = Arrays.asList("002").stream();
MockHoodieTimeline activeTimeline = new MockHoodieTimeline(completed, inflight);
HoodieFileGroup fileGroup = new HoodieFileGroup("", "data", activeTimeline.getCommitsTimeline().filterCompletedInstants());
for (int i = 0; i < 3; i++) {
HoodieBaseFile baseFile = new HoodieBaseFile("data_1_00" + i);
fileGroup.addBaseFile(baseFile);
}
assertEquals(2, fileGroup.getAllFileSlices().count());
assertTrue(!fileGroup.getAllFileSlices().anyMatch(s -> s.getBaseInstantTime().equals("002")));
assertEquals(3, fileGroup.getAllFileSlicesIncludingInflight().count());
assertTrue(fileGroup.getLatestFileSlice().get().getBaseInstantTime().equals("001"));
assertTrue((new HoodieFileGroup(fileGroup)).getLatestFileSlice().get().getBaseInstantTime().equals("001"));
}
use of org.apache.hudi.common.testutils.MockHoodieTimeline in project hudi by apache.
the class TestPriorityBasedFileSystemView method testGetAllFileGroups.
@Test
public void testGetAllFileGroups() {
Stream<HoodieFileGroup> actual;
String partitionPath = "/table2";
Stream<HoodieFileGroup> expected = Collections.singleton(new HoodieFileGroup(partitionPath, "id1", new MockHoodieTimeline(Stream.empty(), Stream.empty()))).stream();
when(primary.getAllFileGroups(partitionPath)).thenReturn(expected);
actual = fsView.getAllFileGroups(partitionPath);
assertEquals(expected, actual);
resetMocks();
when(primary.getAllFileGroups(partitionPath)).thenThrow(new RuntimeException());
when(secondary.getAllFileGroups(partitionPath)).thenReturn(expected);
actual = fsView.getAllFileGroups(partitionPath);
assertEquals(expected, actual);
resetMocks();
when(secondary.getAllFileGroups(partitionPath)).thenReturn(expected);
actual = fsView.getAllFileGroups(partitionPath);
assertEquals(expected, actual);
resetMocks();
when(secondary.getAllFileGroups(partitionPath)).thenThrow(new RuntimeException());
assertThrows(RuntimeException.class, () -> {
fsView.getAllFileGroups(partitionPath);
});
}
use of org.apache.hudi.common.testutils.MockHoodieTimeline in project hudi by apache.
the class TestPriorityBasedFileSystemView method testGetTimeline.
@Test
public void testGetTimeline() {
HoodieTimeline actual;
HoodieTimeline expected = new MockHoodieTimeline(Stream.empty(), Stream.empty());
when(primary.getTimeline()).thenReturn(expected);
actual = fsView.getTimeline();
assertEquals(expected, actual);
resetMocks();
when(primary.getTimeline()).thenThrow(new RuntimeException());
when(secondary.getTimeline()).thenReturn(expected);
actual = fsView.getTimeline();
assertEquals(expected, actual);
resetMocks();
when(secondary.getTimeline()).thenReturn(expected);
actual = fsView.getTimeline();
assertEquals(expected, actual);
resetMocks();
when(secondary.getTimeline()).thenThrow(new RuntimeException());
assertThrows(RuntimeException.class, () -> {
fsView.getTimeline();
});
}
Aggregations