Search in sources :

Example 31 with Timeline

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());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor)

Example 32 with Timeline

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));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Test(org.junit.Test)

Example 33 with Timeline

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);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Date(java.util.Date)

Example 34 with 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());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Test(org.junit.Test)

Example 35 with Timeline

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));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Timeline (org.zalando.nakadi.domain.Timeline)74 Test (org.junit.Test)39 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)33 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)19 TopicRepository (org.zalando.nakadi.repository.TopicRepository)17 Date (java.util.Date)14 EventType (org.zalando.nakadi.domain.EventType)14 List (java.util.List)13 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)13 Storage (org.zalando.nakadi.domain.Storage)13 Collectors (java.util.stream.Collectors)12 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)12 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)9 NakadiSettings (org.zalando.nakadi.config.NakadiSettings)9 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)9 Optional (java.util.Optional)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 NakadiException (org.zalando.nakadi.exceptions.NakadiException)8