use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.
the class EventStreamControllerTest method whenStreamLimitLowerThanBatchLimitThenUnprocessableEntity.
@Test
public void whenStreamLimitLowerThanBatchLimitThenUnprocessableEntity() throws NakadiException, IOException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
final StreamingResponseBody responseBody = createStreamingResponseBody(20, 10, 0, 0, 0, null);
final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "stream_limit can't be lower than batch_limit");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody 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.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.
the class EventStreamControllerTest method whenBatchLimitLowerThan1ThenUnprocessableEntity.
@Test
public void whenBatchLimitLowerThan1ThenUnprocessableEntity() throws NakadiException, IOException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
final StreamingResponseBody responseBody = createStreamingResponseBody(0, 0, 0, 0, 0, null);
final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "batch_limit can't be lower than 1");
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.
the class EventStreamControllerTest method whenExceptionIsThrownThenInternalServerError.
@Test
public void whenExceptionIsThrownThenInternalServerError() throws NakadiException, IOException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenThrow(NullPointerException.class);
final StreamingResponseBody responseBody = createStreamingResponseBody();
final Problem expectedProblem = Problem.valueOf(INTERNAL_SERVER_ERROR);
assertThat(responseToString(responseBody), TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem));
}
use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.
the class EventStreamControllerTest method whenNoCursorsThenLatestOffsetsAreUsed.
@Test
public void whenNoCursorsThenLatestOffsetsAreUsed() throws NakadiException, IOException, InvalidCursorException {
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
final List<PartitionStatistics> tps2 = ImmutableList.of(new KafkaPartitionStatistics(timeline, 0, 0, 87), new KafkaPartitionStatistics(timeline, 1, 0, 34));
when(timelineService.getActiveTimeline(any(EventType.class))).thenReturn(timeline);
when(topicRepositoryMock.loadTopicStatistics(eq(Collections.singletonList(timeline)))).thenReturn(tps2);
final ArgumentCaptor<EventStreamConfig> configCaptor = ArgumentCaptor.forClass(EventStreamConfig.class);
final EventStream eventStreamMock = mock(EventStream.class);
when(eventStreamFactoryMock.createEventStream(any(), any(), configCaptor.capture(), any())).thenReturn(eventStreamMock);
final StreamingResponseBody responseBody = createStreamingResponseBody(1, 0, 1, 1, 0, null);
responseBody.writeTo(new ByteArrayOutputStream());
final EventStreamConfig streamConfig = configCaptor.getValue();
assertThat(streamConfig.getCursors(), equalTo(tps2.stream().map(PartitionStatistics::getLast).collect(Collectors.toList())));
}
Aggregations