Search in sources :

Example 21 with StreamingResponseBody

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));
}
Also used : StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 22 with StreamingResponseBody

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));
}
Also used : NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 23 with StreamingResponseBody

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));
}
Also used : StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 24 with StreamingResponseBody

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));
}
Also used : StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Problem(org.zalando.problem.Problem) Test(org.junit.Test)

Example 25 with StreamingResponseBody

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())));
}
Also used : EventStreamConfig(org.zalando.nakadi.service.EventStreamConfig) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) KafkaPartitionStatistics(org.zalando.nakadi.repository.kafka.KafkaPartitionStatistics) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) EventType(org.zalando.nakadi.domain.EventType) KafkaPartitionStatistics(org.zalando.nakadi.repository.kafka.KafkaPartitionStatistics) EventStream(org.zalando.nakadi.service.EventStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

StreamingResponseBody (org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody)26 Test (org.junit.Test)16 Problem (org.zalando.problem.Problem)10 ExportParameters (org.talend.dataprep.api.export.ExportParameters)9 InputStream (java.io.InputStream)8 TDPException (org.talend.dataprep.exception.TDPException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)6 Configuration (org.talend.dataprep.transformation.api.transformer.configuration.Configuration)6 JsonParser (com.fasterxml.jackson.core.JsonParser)5 StringUtils (org.apache.commons.lang.StringUtils)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Component (org.springframework.stereotype.Component)5 DataSet (org.talend.dataprep.api.dataset.DataSet)5 ExportFormat (org.talend.dataprep.format.export.ExportFormat)5 CSVFormat (org.talend.dataprep.transformation.format.CSVFormat)5 BaseExportStrategy (org.talend.dataprep.transformation.service.BaseExportStrategy)5 ExportUtils (org.talend.dataprep.transformation.service.ExportUtils)5