use of org.zalando.nakadi.domain.NakadiCursor in project nakadi by zalando.
the class EventStreamControllerTest method whenInvalidCursorsThenPreconditionFailed.
@Test
public void whenInvalidCursorsThenPreconditionFailed() throws Exception {
final NakadiCursor cursor = NakadiCursor.of(timeline, "0", "000000000000000000");
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
when(timelineService.createEventConsumer(eq(KAFKA_CLIENT_ID), any())).thenThrow(new InvalidCursorException(CursorError.UNAVAILABLE, cursor));
final StreamingResponseBody responseBody = createStreamingResponseBody(1, 0, 0, 0, 0, "[{\"partition\":\"0\",\"offset\":\"00000000000000000\"}]");
final Problem expectedProblem = Problem.valueOf(PRECONDITION_FAILED, "offset 000000000000000000 for partition 0 is unavailable");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
use of org.zalando.nakadi.domain.NakadiCursor in project nakadi by zalando.
the class SubscriptionControllerTest method whenGetSubscriptionStatThenOk.
@Test
public void whenGetSubscriptionStatThenOk() throws Exception {
final Subscription subscription = builder().withEventType(TIMELINE.getEventType()).build();
final Collection<Partition> partitions = Collections.singleton(new Partition(TIMELINE.getEventType(), "0", "xz", null, Partition.State.ASSIGNED));
final ZkSubscriptionNode zkSubscriptionNode = new ZkSubscriptionNode(partitions, Arrays.asList(new Session("xz", 0)));
when(subscriptionRepository.getSubscription(subscription.getId())).thenReturn(subscription);
when(zkSubscriptionClient.getZkSubscriptionNodeLocked()).thenReturn(Optional.of(zkSubscriptionNode));
final SubscriptionCursorWithoutToken currentOffset = new SubscriptionCursorWithoutToken(TIMELINE.getEventType(), "0", "3");
final EventTypePartition etp = new EventTypePartition(TIMELINE.getEventType(), "0");
final Map<EventTypePartition, SubscriptionCursorWithoutToken> offsets = new HashMap<>();
offsets.put(etp, currentOffset);
when(zkSubscriptionClient.getOffsets(Collections.singleton(etp))).thenReturn(offsets);
when(eventTypeRepository.findByName(TIMELINE.getEventType())).thenReturn(EventTypeTestBuilder.builder().name(TIMELINE.getEventType()).build());
final List<PartitionEndStatistics> statistics = Collections.singletonList(new KafkaPartitionEndStatistics(TIMELINE, 0, 13));
when(topicRepository.loadTopicEndStatistics(eq(Collections.singletonList(TIMELINE)))).thenReturn(statistics);
final NakadiCursor currentCursor = mock(NakadiCursor.class);
when(currentCursor.getEventTypePartition()).thenReturn(new EventTypePartition(TIMELINE.getEventType(), "0"));
when(cursorConverter.convert((List<SubscriptionCursorWithoutToken>) any())).thenReturn(Collections.singletonList(currentCursor));
when(cursorOperationsService.calculateDistance(eq(currentCursor), eq(statistics.get(0).getLast()))).thenReturn(10L);
final List<SubscriptionEventTypeStats> expectedStats = Collections.singletonList(new SubscriptionEventTypeStats(TIMELINE.getEventType(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 10L, "xz", AUTO))));
getSubscriptionStats(subscription.getId()).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(new ItemsWrapper<>(expectedStats))));
}
use of org.zalando.nakadi.domain.NakadiCursor in project nakadi by zalando.
the class CursorOperationsServiceTest method whenCursorsOffsetsAreInvertedThenNegativeDistance.
@Test
public void whenCursorsOffsetsAreInvertedThenNegativeDistance() throws Exception {
final NakadiCursor initialCursor = NakadiCursor.of(timeline, "0", "0000000000000002");
final NakadiCursor finalCursor = NakadiCursor.of(timeline, "0", "0000000000000001");
final Long distance = service.calculateDistance(initialCursor, finalCursor);
assertThat(distance, equalTo(-1L));
}
use of org.zalando.nakadi.domain.NakadiCursor 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.NakadiCursor 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"));
}
Aggregations