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();
}
}
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);
}
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"));
}
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;
}
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"));
}
Aggregations