use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class NakadiCursorComparator method compareOrdered.
private int compareOrdered(final NakadiCursor c1, final NakadiCursor c2) {
// If c2 moved from -1, than it is definitely greater.
if (!c2.isInitial()) {
return -1;
}
Iterator<Timeline> timelineIterator = null;
NakadiCursor first = c1;
// Handle obsolete timeline information
if (first.getTimeline().getLatestPosition() == null) {
timelineIterator = createTimelinesIterator(first.getEventType(), first.getTimeline().getOrder());
first = NakadiCursor.of(timelineIterator.next(), first.getPartition(), first.getOffset());
}
while (first.getTimeline().getOrder() != c2.getTimeline().getOrder()) {
if (!first.isLast()) {
return -1;
}
if (null == timelineIterator) {
timelineIterator = createTimelinesIterator(first.getEventType(), first.getTimeline().getOrder() + 1);
}
final Timeline nextTimeline = timelineIterator.next();
final String initialOffset = StaticStorageWorkerFactory.get(nextTimeline).getBeforeFirstOffset();
first = NakadiCursor.of(nextTimeline, first.getPartition(), initialOffset);
}
return first.getOffset().compareTo(c2.getOffset());
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineDbRepositoryTest method testListTimelinesOrdered.
@Test
public void testListTimelinesOrdered() {
final Timeline t1 = insertTimeline(1);
final Timeline t0 = insertTimeline(0);
final List<Timeline> testTimelines = tRepository.listTimelinesOrdered(testEt.getName());
Assert.assertEquals(2, testTimelines.size());
Assert.assertEquals(t0, testTimelines.get(0));
Assert.assertEquals(t1, testTimelines.get(1));
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineDbRepositoryTest method insertTimeline.
private Timeline insertTimeline(final Date cleanupDate, final boolean deleted, final int order) {
final Timeline timeline = createTimeline(storage, UUID.randomUUID(), order, "test_topic", testEt.getName(), new Date(), new Date(), cleanupDate, null);
timeline.setDeleted(deleted);
return tRepository.createTimeline(timeline);
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineDbRepositoryTest method testTimelineCreated.
@Test
public void testTimelineCreated() {
final Timeline timeline = insertTimeline(0);
final Optional<Timeline> fromDb = tRepository.getTimeline(timeline.getId());
Assert.assertTrue(fromDb.isPresent());
Assert.assertFalse(fromDb.get() == timeline);
Assert.assertEquals(timeline, fromDb.get());
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineDbRepositoryTest method testGetExpiredTimelines.
@Test
public void testGetExpiredTimelines() {
final DateTime now = new DateTime();
final DateTime tomorrow = now.plusDays(1);
final DateTime yesterday = now.minusDays(1);
final DateTime twoDaysAgo = now.minusDays(2);
final Timeline t1 = insertTimeline(tomorrow.toDate(), true, 0);
final Timeline t2 = insertTimeline(tomorrow.toDate(), false, 1);
final Timeline t3 = insertTimeline(yesterday.toDate(), true, 2);
final Timeline t4 = insertTimeline(yesterday.toDate(), false, 3);
final Timeline t5 = insertTimeline(twoDaysAgo.toDate(), false, 4);
final Timeline t6 = insertTimeline(null, false, 5);
final List<Timeline> expiredTimelines = tRepository.getExpiredTimelines();
Assert.assertFalse(expiredTimelines.contains(t1));
Assert.assertFalse(expiredTimelines.contains(t2));
Assert.assertFalse(expiredTimelines.contains(t3));
Assert.assertTrue(expiredTimelines.contains(t4));
Assert.assertTrue(expiredTimelines.contains(t5));
Assert.assertFalse(expiredTimelines.contains(t6));
}
Aggregations