Search in sources :

Example 1 with KafkaPartitionStatistics

use of org.zalando.nakadi.repository.kafka.KafkaPartitionStatistics 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

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.Test)1 StreamingResponseBody (org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody)1 EventType (org.zalando.nakadi.domain.EventType)1 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)1 KafkaPartitionStatistics (org.zalando.nakadi.repository.kafka.KafkaPartitionStatistics)1 EventStream (org.zalando.nakadi.service.EventStream)1 EventStreamConfig (org.zalando.nakadi.service.EventStreamConfig)1