Search in sources :

Example 1 with CursorLag

use of org.zalando.nakadi.view.CursorLag in project nakadi by zalando.

the class PartitionsControllerTest method whenGetPartitionWithConsumedOffsetThenOk.

@Test
public void whenGetPartitionWithConsumedOffsetThenOk() throws Exception {
    when(eventTypeRepositoryMock.findByName(TEST_EVENT_TYPE)).thenReturn(EVENT_TYPE);
    when(topicRepositoryMock.topicExists(eq(EVENT_TYPE.getName()))).thenReturn(true);
    when(topicRepositoryMock.loadPartitionStatistics(eq(TIMELINE), eq(TEST_PARTITION))).thenReturn(Optional.of(TEST_POSITION_STATS.get(0)));
    final List<NakadiCursorLag> lags = mockCursorLag();
    when(cursorOperationsService.cursorsLag(any(), any())).thenReturn(lags);
    mockMvc.perform(get(String.format("/event-types/%s/partitions/%s?consumed_offset=1", TEST_EVENT_TYPE, TEST_PARTITION))).andExpect(status().isOk()).andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(new CursorLag("0", "001-0000-0", "001-0000-1", 42L))));
}
Also used : NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag) CursorLag(org.zalando.nakadi.view.CursorLag) NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag) Test(org.junit.Test)

Example 2 with CursorLag

use of org.zalando.nakadi.view.CursorLag in project nakadi by zalando.

the class PartitionsController method getPartition.

@RequestMapping(value = "/event-types/{name}/partitions/{partition}", method = RequestMethod.GET)
public ResponseEntity<?> getPartition(@PathVariable("name") final String eventTypeName, @PathVariable("partition") final String partition, @Nullable @RequestParam(value = "consumed_offset", required = false) final String consumedOffset, final NativeWebRequest request) {
    LOG.trace("Get partition endpoint for event-type '{}', partition '{}' is called", eventTypeName, partition);
    try {
        final EventType eventType = eventTypeRepository.findByName(eventTypeName);
        authorizationValidator.authorizeStreamRead(eventType);
        if (consumedOffset != null) {
            final CursorLag cursorLag = getCursorLag(eventTypeName, partition, consumedOffset);
            return ok().body(cursorLag);
        } else {
            final EventTypePartitionView result = getTopicPartition(eventTypeName, partition);
            return ok().body(result);
        }
    } catch (final NoSuchEventTypeException e) {
        return create(Problem.valueOf(NOT_FOUND, "topic not found"), request);
    } catch (final NakadiException e) {
        LOG.error("Could not get partition. Respond with SERVICE_UNAVAILABLE.", e);
        return create(e.asProblem(), request);
    } catch (final InvalidCursorException e) {
        return create(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, INVALID_CURSOR_MESSAGE), request);
    }
}
Also used : EventType(org.zalando.nakadi.domain.EventType) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NakadiCursorLag(org.zalando.nakadi.domain.NakadiCursorLag) CursorLag(org.zalando.nakadi.view.CursorLag) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NakadiCursorLag (org.zalando.nakadi.domain.NakadiCursorLag)2 CursorLag (org.zalando.nakadi.view.CursorLag)2 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 EventType (org.zalando.nakadi.domain.EventType)1 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)1 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)1 NakadiException (org.zalando.nakadi.exceptions.NakadiException)1 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)1 EventTypePartitionView (org.zalando.nakadi.view.EventTypePartitionView)1