Search in sources :

Example 11 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class CursorOperationsServiceTest method shiftCursorToExpiredTimeline.

@Test
public void shiftCursorToExpiredTimeline() throws Exception {
    final Timeline initialTimeline = mockTimeline(1, 5L);
    final Timeline finalTimeline = mockTimeline(1);
    when(timelineService.getActiveTimelinesOrdered(any())).thenReturn(Lists.newArrayList(initialTimeline, finalTimeline));
    final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(finalTimeline, "0", "000000000000000003", -15L);
    try {
        service.unshiftCursor(shiftedCursor);
        fail();
    } catch (final InvalidCursorOperation e) {
        assertThat(e.getReason(), equalTo(TIMELINE_NOT_FOUND));
    } catch (final Exception e) {
        fail();
    }
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) InvalidCursorOperation(org.zalando.nakadi.exceptions.runtime.InvalidCursorOperation) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 12 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class CursorOperationsServiceTest method testDistanceWithEmptyTimelines.

@Test
public void testDistanceWithEmptyTimelines() throws Exception {
    final Timeline first = mockTimeline(1, 9L);
    final Timeline last = mockOpenTimeline(5);
    mockTimelines(first, mockTimeline(2, -1L), mockTimeline(3, -1L), mockTimeline(4, -1L), last);
    final NakadiCursor firstCursor = NakadiCursor.of(first, "0", "000000000000000001");
    final NakadiCursor lastCursor = NakadiCursor.of(last, "0", "000000000000000010");
    assertEquals(service.calculateDistance(firstCursor, lastCursor), 19L);
    assertEquals(service.calculateDistance(lastCursor, firstCursor), -19L);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 13 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class CursorOperationsServiceTest method shiftCursorBackInTheSameTimelineClosed.

@Test
public void shiftCursorBackInTheSameTimelineClosed() {
    final Timeline initialTimeline = mockTimeline(0, 10L);
    final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", -3L);
    final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
    assertThat(cursor.getOffset(), equalTo("000000000000000000"));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 14 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class CursorOperationsServiceTest method mockTimeline.

private Timeline mockTimeline(final int order, @Nullable final Long latestOffset) {
    final Timeline timeline = mock(Timeline.class);
    when(timeline.getOrder()).thenReturn(order);
    final Storage storage = new Storage();
    storage.setType(Storage.Type.KAFKA);
    when(timeline.getStorage()).thenReturn(storage);
    if (latestOffset == null) {
        when(timeline.isActive()).thenReturn(false);
        when(timeline.getLatestPosition()).thenReturn(null);
    } else {
        when(timeline.isActive()).thenReturn(true);
        when(timeline.getLatestPosition()).thenReturn(new Timeline.KafkaStoragePosition(Collections.singletonList(latestOffset)));
    }
    when(timeline.isActive()).thenReturn(null == latestOffset);
    final TopicRepository repository = new KafkaTopicRepository(mock(ZooKeeperHolder.class), mock(KafkaFactory.class), mock(NakadiSettings.class), mock(KafkaSettings.class), mock(ZookeeperSettings.class), mock(UUIDGenerator.class));
    when(timelineService.getTopicRepository(timeline)).thenReturn(repository);
    return timeline;
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) KafkaFactory(org.zalando.nakadi.repository.kafka.KafkaFactory) Storage(org.zalando.nakadi.domain.Storage) KafkaTopicRepository(org.zalando.nakadi.repository.kafka.KafkaTopicRepository) KafkaSettings(org.zalando.nakadi.repository.kafka.KafkaSettings) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) TopicRepository(org.zalando.nakadi.repository.TopicRepository) KafkaTopicRepository(org.zalando.nakadi.repository.kafka.KafkaTopicRepository) ZookeeperSettings(org.zalando.nakadi.repository.zookeeper.ZookeeperSettings) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) NakadiSettings(org.zalando.nakadi.config.NakadiSettings)

Example 15 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class CursorOperationsServiceTest method testShiftWithEmptyTimelines.

@Test
public void testShiftWithEmptyTimelines() throws Exception {
    final Timeline first = mockTimeline(1, 9L);
    final Timeline last = mockOpenTimeline(5);
    mockTimelines(first, mockTimeline(2, -1L), mockTimeline(3, -1L), mockTimeline(4, -1L), last);
    final ShiftedNakadiCursor moveForward = new ShiftedNakadiCursor(first, "0", "000000000000000001", 19);
    assertEquals(service.unshiftCursor(moveForward), NakadiCursor.of(last, "0", "000000000000000010"));
    final ShiftedNakadiCursor moveBackward = new ShiftedNakadiCursor(last, "0", "000000000000000010", -19);
    assertEquals(service.unshiftCursor(moveBackward), NakadiCursor.of(first, "0", "000000000000000001"));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) 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