Search in sources :

Example 26 with StreamingResponseBody

use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.

the class EventStreamControllerTest method whenNormalCaseThenParametersArePassedToConfigAndStreamStarted.

@Test
public void whenNormalCaseThenParametersArePassedToConfigAndStreamStarted() throws Exception {
    final EventConsumer eventConsumerMock = mock(EventConsumer.class);
    when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
    when(timelineService.createEventConsumer(eq(KAFKA_CLIENT_ID), eq(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))))).thenReturn(eventConsumerMock);
    when(timelineService.getActiveTimeline(eq(EVENT_TYPE))).thenReturn(timeline);
    final ArgumentCaptor<Integer> statusCaptor = getStatusCaptor();
    final ArgumentCaptor<String> contentTypeCaptor = getContentTypeCaptor();
    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, 2, 3, 4, 5, "[{\"partition\":\"0\",\"offset\":\"000000000000000000\"}]");
    final OutputStream outputStream = mock(OutputStream.class);
    responseBody.writeTo(outputStream);
    final EventStreamConfig streamConfig = configCaptor.getValue();
    assertThat(streamConfig, equalTo(EventStreamConfig.builder().withCursors(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))).withBatchLimit(1).withStreamLimit(2).withBatchTimeout(3).withStreamTimeout(4).withStreamKeepAliveLimit(5).build()));
    assertThat(statusCaptor.getValue(), equalTo(HttpStatus.OK.value()));
    assertThat(contentTypeCaptor.getValue(), equalTo("application/x-json-stream"));
    verify(timelineService, times(1)).createEventConsumer(eq(KAFKA_CLIENT_ID), eq(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))));
    verify(eventStreamFactoryMock, times(1)).createEventStream(eq(outputStream), eq(eventConsumerMock), eq(streamConfig), any());
    verify(eventStreamMock, times(1)).streamEvents(any(), any());
    verify(outputStream, times(2)).flush();
    verify(outputStream, times(1)).close();
}
Also used : EventConsumer(org.zalando.nakadi.repository.EventConsumer) EventStreamConfig(org.zalando.nakadi.service.EventStreamConfig) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) EventStream(org.zalando.nakadi.service.EventStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) 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