@Override public List<TimelineObjectHolder<VersionType, ObjectType>> lookupWithIncompletePartitions(Interval interval) { try { lock.readLock().lock(); return lookup(interval, true); } finally { lock.readLock().unlock(); } }
private static Pair<Map<DataSegment, File>, List<TimelineObjectHolder<String, DataSegment>>> prepareSegments( TaskToolbox toolbox, SegmentProvider segmentProvider ) throws IOException, SegmentLoadingException { final List<DataSegment> usedSegments = segmentProvider.checkAndGetSegments(toolbox); final Map<DataSegment, File> segmentFileMap = toolbox.fetchSegments(usedSegments); final List<TimelineObjectHolder<String, DataSegment>> timelineSegments = VersionedIntervalTimeline .forSegments(usedSegments) .lookup(segmentProvider.interval); return Pair.of(segmentFileMap, timelineSegments); }
@Test public void testMay() { assertValues( Collections.singletonList( createExpected("2011-05-01/2011-05-09", "4", 9) ), timeline.lookup(Intervals.of("2011-05-01/2011-05-09")) ); }
@Test public void testNotFoundReturnsEmpty() { timeline = makeStringIntegerTimeline(); add("2011-04-01/2011-04-09", "1", 1); Assert.assertTrue(timeline.lookup(Intervals.of("1970/1980")).isEmpty()); }
@Test public void testApril() { assertValues( Arrays.asList( createExpected("2011-04-01/2011-04-02", "3", 5), createExpected("2011-04-02/2011-04-06", "2", 1), createExpected("2011-04-06/2011-04-09", "3", 4) ), timeline.lookup(Intervals.of("2011-04-01/2011-04-09")) ); }
@Test public void testRemovePartitionMakesIncomplete() { testIncompletePartitionDoesNotOvershadow(); final IntegerPartitionChunk<Integer> chunk = IntegerPartitionChunk.make(null, 10, 0, 60); Assert.assertEquals(chunk, timeline.remove(Intervals.of("2011-10-05/2011-10-07"), "6", chunk)); assertValues( ImmutableList.of(createExpected("2011-10-05/2011-10-06", "5", 5)), timeline.lookup(Intervals.of("2011-10-05/2011-10-07")) ); Assert.assertTrue("Expected no overshadowed entries", timeline.findOvershadowed().isEmpty()); }
@Test public void testOverlapSecondBefore() { timeline = makeStringIntegerTimeline(); add("2011-01-05/2011-01-15", "1", 3); add("2011-01-01/2011-01-10", "2", 1); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-10", "2", 1), createExpected("2011-01-10/2011-01-15", "1", 3) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-15")) ); }
@Test public void testOverlapSecondAfter() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-10", "2", 3); add("2011-01-05/2011-01-15", "1", 1); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-10", "2", 1), createExpected("2011-01-10/2011-01-15", "1", 3) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-15")) ); }
@Test public void testOverlapFirstBefore() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-10", "1", 1); add("2011-01-05/2011-01-15", "2", 3); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-05", "1", 1), createExpected("2011-01-05/2011-01-15", "2", 3) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-15")) ); }
@Test public void testOverlapFirstAfter() { timeline = makeStringIntegerTimeline(); add("2011-01-05/2011-01-15", "2", 3); add("2011-01-01/2011-01-10", "1", 1); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-05", "1", 1), createExpected("2011-01-05/2011-01-15", "2", 3) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-15")) ); }
@Test public void testOverlapFirstLarger() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 2); add("2011-01-05/2011-01-15", "2", 3); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-05", "1", 2), createExpected("2011-01-05/2011-01-15", "2", 3), createExpected("2011-01-15/2011-01-20", "1", 2) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapFirstPartialAlign() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-15", "2", 3); add("2011-01-01/2011-01-10", "1", 1); add("2011-01-10/2011-01-20", "1", 2); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-15", "2", 3), createExpected("2011-01-15/2011-01-20", "1", 2) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapSameVersionIsOkay() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-10", "1", 1); add("2011-01-01/2011-01-10", "2", 2); add("2011-01-01/2011-01-10", "2", 3); add("2011-01-01/2011-01-10", "1", 4); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-10", "2", 2) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-10")) ); }
@Test public void testOverlapFirstContainsSecond() { timeline = makeStringIntegerTimeline(); add("2011-01-10/2011-01-20", "2", 3); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-01/2011-01-10", "2", 2); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-10", "2", 2), createExpected("2011-01-10/2011-01-20", "2", 3) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapSecondLarger() { timeline = makeStringIntegerTimeline(); add("2011-01-05/2011-01-15", "2", 3); add("2011-01-01/2011-01-20", "1", 2); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-05", "1", 2), createExpected("2011-01-05/2011-01-15", "2", 3), createExpected("2011-01-15/2011-01-20", "1", 2) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapSecondPartialAlign() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-10", "1", 1); add("2011-01-10/2011-01-20", "1", 2); add("2011-01-01/2011-01-15", "2", 3); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-15", "2", 3), createExpected("2011-01-15/2011-01-20", "1", 2) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapV2Large() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-15", "2", 1); add("2011-01-03/2011-01-05", "1", 2); add("2011-01-13/2011-01-20", "1", 3); assertValues( Arrays.asList( createExpected("2011-01-01/2011-01-15", "2", 2), createExpected("2011-01-15/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testMay2() { Assert.assertNotNull(timeline.remove(Intervals.of("2011-05-01/2011-05-10"), "4", makeSingle(1))); assertValues( Arrays.asList( createExpected("2011-05-01/2011-05-03", "2", 7), createExpected("2011-05-03/2011-05-04", "3", 8), createExpected("2011-05-04/2011-05-05", "2", 7) ), timeline.lookup(Intervals.of("2011-05-01/2011-05-09")) ); }
@Test public void testOverlapAndRemove() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-15", "2", 2); timeline.remove(Intervals.of("2011-01-10/2011-01-15"), "2", makeSingle(2)); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }
@Test public void testOverlapAndRemove5() { timeline = makeStringIntegerTimeline(); add("2011-01-01/2011-01-20", "1", 1); add("2011-01-10/2011-01-15", "2", 2); timeline.remove(Intervals.of("2011-01-10/2011-01-15"), "2", makeSingle(2)); add("2011-01-01/2011-01-20", "1", 1); assertValues( Collections.singletonList( createExpected("2011-01-01/2011-01-20", "1", 1) ), timeline.lookup(Intervals.of("2011-01-01/2011-01-20")) ); }