use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method testShiftBeforeInitialBegin.
@Test(expected = InvalidCursorOperation.class)
public void testShiftBeforeInitialBegin() throws Exception {
final Timeline first = mockTimeline(1, 1L);
mockTimelines(first);
final ShiftedNakadiCursor moveBack = new ShiftedNakadiCursor(first, "0", "-1", -1);
service.unshiftCursor(moveBack);
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsService method moveBack.
private NakadiCursor moveBack(final ShiftedNakadiCursor cursor) {
NakadiCursor currentCursor = cursor.getNakadiCursor();
long toMoveBack = -cursor.getShift();
while (toMoveBack > 0) {
final long totalBefore = numberOfEventsBeforeCursor(currentCursor);
if (totalBefore < toMoveBack) {
// +1 is because end is inclusive
toMoveBack -= totalBefore + 1;
// begin event that is not within limits)
if (toMoveBack == 0) {
toMoveBack += totalBefore + 1;
break;
}
final Timeline prevTimeline = getTimeline(currentCursor.getEventType(), currentCursor.getTimeline().getOrder() - 1);
// When moving back latest position is always defined
currentCursor = prevTimeline.getLatestPosition().toNakadiCursor(prevTimeline, currentCursor.getPartition());
} else {
break;
}
}
if (toMoveBack != 0) {
currentCursor = currentCursor.shiftWithinTimeline(-toMoveBack);
}
return currentCursor;
}
Aggregations