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))));
}
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);
}
}
Aggregations