use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method shiftCursorRightToNextTimeline.
@Test
public void shiftCursorRightToNextTimeline() throws Exception {
final Timeline initialTimeline = mockTimeline(1, 10L);
final Timeline nextTimeline = mockTimeline(2, 3L);
final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", 9L);
mockTimelines(initialTimeline, nextTimeline);
final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
assertThat(cursor.getTimeline().getOrder(), equalTo(2));
assertThat(cursor.getOffset(), equalTo("000000000000000001"));
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor 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.ShiftedNakadiCursor 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.ShiftedNakadiCursor 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"));
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsService method moveForward.
private NakadiCursor moveForward(final ShiftedNakadiCursor cursor) {
NakadiCursor currentCursor = cursor.getNakadiCursor();
long stillToAdd = cursor.getShift();
while (currentCursor.getTimeline().getLatestPosition() != null) {
final NakadiCursor timelineLastPosition = currentCursor.getTimeline().getLatestPosition().toNakadiCursor(currentCursor.getTimeline(), currentCursor.getPartition());
final long distance = calculateDistance(currentCursor, timelineLastPosition);
if (stillToAdd > distance) {
stillToAdd -= distance;
final Timeline nextTimeline = getTimeline(currentCursor.getEventType(), currentCursor.getTimeline().getOrder() + 1);
currentCursor = NakadiCursor.of(nextTimeline, currentCursor.getPartition(), StaticStorageWorkerFactory.get(nextTimeline).getBeforeFirstOffset());
} else {
break;
}
}
if (stillToAdd > 0) {
return currentCursor.shiftWithinTimeline(stillToAdd);
}
return currentCursor;
}
Aggregations