use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsController method moveCursors.
@RequestMapping(path = "/event-types/{eventTypeName}/shifted-cursors", method = RequestMethod.POST)
public ResponseEntity<?> moveCursors(@PathVariable("eventTypeName") final String eventTypeName, @Valid @RequestBody final ValidListWrapper<ShiftedCursor> cursors) throws InternalNakadiException, NoSuchEventTypeException {
final EventType eventType = eventTypeRepository.findByName(eventTypeName);
authorizationValidator.authorizeStreamRead(eventType);
final List<ShiftedNakadiCursor> domainCursor = cursors.getList().stream().map(this.toShiftedNakadiCursor(eventTypeName)).collect(Collectors.toList());
final List<NakadiCursor> domainResultCursors = cursorOperationsService.unshiftCursors(domainCursor);
final List<Cursor> viewResult = domainResultCursors.stream().map(cursorConverter::convert).collect(Collectors.toList());
return status(OK).body(viewResult);
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method shiftCursorBackToPreviousTimeline.
@Test
public void shiftCursorBackToPreviousTimeline() throws Exception {
final Timeline initialTimeline = mockTimeline(0, 10L);
final Timeline intermediaryTimeline = mockTimeline(1, 9L);
final Timeline finalTimeline = mockTimeline(2, 9L);
mockTimelines(initialTimeline, intermediaryTimeline, finalTimeline);
final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(finalTimeline, "0", "000000000000000003", -15L);
final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
assertThat(cursor.getTimeline().getOrder(), equalTo(0));
assertThat(cursor.getOffset(), equalTo("000000000000000009"));
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method shiftCursorForwardInTheSameTimelineOpen.
@Test
public void shiftCursorForwardInTheSameTimelineOpen() {
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("000000000000000006"));
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method shiftCursorToTheRightSameClosedTimeline.
@Test
public void shiftCursorToTheRightSameClosedTimeline() throws Exception {
final Timeline initialTimeline = mockTimeline(0, 10L);
final ShiftedNakadiCursor shiftedCursor = new ShiftedNakadiCursor(initialTimeline, "0", "000000000000000003", 2L);
mockTimelines(initialTimeline);
final NakadiCursor cursor = service.unshiftCursor(shiftedCursor);
assertThat(cursor.getOffset(), equalTo("000000000000000005"));
}
use of org.zalando.nakadi.domain.ShiftedNakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method testShiftToInitialBegin.
@Test
public void testShiftToInitialBegin() throws Exception {
final Timeline first = mockTimeline(1, 1L);
final Timeline last = mockOpenTimeline(2);
mockTimelines(first, last);
final ShiftedNakadiCursor moveBack = new ShiftedNakadiCursor(last, "0", "000000000000000001", -4);
assertEquals(NakadiCursor.of(first, "0", "-1"), service.unshiftCursor(moveBack));
}
Aggregations