use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class KafkaTopicRepositoryTest method canLoadPartitionStatistics.
@Test
public void canLoadPartitionStatistics() throws Exception {
final Timeline t1 = mock(Timeline.class);
when(t1.getTopic()).thenReturn(MY_TOPIC);
final Timeline t2 = mock(Timeline.class);
when(t2.getTopic()).thenReturn(ANOTHER_TOPIC);
final ImmutableList<Timeline> timelines = ImmutableList.of(t1, t2);
final List<PartitionStatistics> stats = kafkaTopicRepository.loadTopicStatistics(timelines);
final Set<PartitionStatistics> expected = PARTITIONS.stream().map(p -> {
final Timeline timeline = p.topic.equals(MY_TOPIC) ? t1 : t2;
return new KafkaPartitionStatistics(timeline, p.partition, p.earliestOffset, p.latestOffset - 1);
}).collect(Collectors.toSet());
assertThat(newHashSet(stats), equalTo(expected));
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class PartitionsControllerTest method mockCursorLag.
private List<NakadiCursorLag> mockCursorLag() {
final Timeline timeline = mock(Timeline.class);
when(timeline.getStorage()).thenReturn(new Storage("ccc", Storage.Type.KAFKA));
final NakadiCursorLag lag = mock(NakadiCursorLag.class);
final NakadiCursor firstCursor = NakadiCursor.of(timeline, "0", "0");
final NakadiCursor lastCursor = NakadiCursor.of(timeline, "0", "1");
when(lag.getLag()).thenReturn(42L);
when(lag.getPartition()).thenReturn("0");
when(lag.getFirstCursor()).thenReturn(firstCursor);
when(lag.getLastCursor()).thenReturn(lastCursor);
return Lists.newArrayList(lag);
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelinesControllerTest method whenGetTimelinesThenOk.
@Test
public void whenGetTimelinesThenOk() throws Exception {
final Storage kafkaStorage = StoragesControllerTest.createKafkaStorage("deafult");
final ImmutableList<Timeline> timelines = ImmutableList.of(Timeline.createTimeline("event_type", 0, kafkaStorage, "topic", new Date()), Timeline.createTimeline("event_type_1", 1, kafkaStorage, "topic_1", new Date()));
Mockito.when(timelineService.getTimelines(Mockito.any())).thenReturn(timelines);
final List<TimelineView> timelineViews = timelines.stream().map(TimelineView::new).collect(Collectors.toList());
mockMvc.perform(MockMvcRequestBuilders.get("/event-types/event_type/timelines").contentType(MediaType.APPLICATION_JSON).principal(PrincipalMockFactory.mockPrincipal("nakadi"))).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().json(TestUtils.OBJECT_MAPPER.writeValueAsString(timelineViews)));
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineService method deleteAllTimelinesForEventType.
public Multimap<TopicRepository, String> deleteAllTimelinesForEventType(final String eventTypeName) throws TimelineException, NotFoundException, InternalNakadiException, NoSuchEventTypeException {
LOG.info("Deleting all timelines for event type {}", eventTypeName);
final Multimap<TopicRepository, String> topicsToDelete = ArrayListMultimap.create();
for (final Timeline timeline : getAllTimelinesOrdered(eventTypeName)) {
if (!timeline.isDeleted()) {
topicsToDelete.put(getTopicRepository(timeline), timeline.getTopic());
}
timelineDbRepository.deleteTimeline(timeline.getId());
}
return topicsToDelete;
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineService method switchTimelines.
private void switchTimelines(final Timeline activeTimeline, final Timeline nextTimeline) throws InconsistentStateException, RepositoryProblemException, TimelineException, ConflictException {
LOG.info("Switching timelines from {} to {}", activeTimeline, nextTimeline);
try {
timelineSync.startTimelineUpdate(activeTimeline.getEventType(), nakadiSettings.getTimelineWaitTimeoutMs());
} catch (final InterruptedException ie) {
Thread.currentThread().interrupt();
throw new TimelineException("Failed to switch timeline for: " + activeTimeline.getEventType());
} catch (final IllegalStateException ie) {
throw new ConflictException("Timeline is already being created for: " + activeTimeline.getEventType(), ie);
}
try {
transactionTemplate.execute(status -> {
timelineDbRepository.createTimeline(nextTimeline);
nextTimeline.setSwitchedAt(new Date());
final Timeline.StoragePosition sp = topicRepositoryHolder.createStoragePosition(activeTimeline);
activeTimeline.setLatestPosition(sp);
scheduleTimelineCleanup(activeTimeline);
timelineDbRepository.updateTimelime(activeTimeline);
timelineDbRepository.updateTimelime(nextTimeline);
return null;
});
} catch (final TransactionException tx) {
LOG.error(tx.getMessage(), tx);
throw new TimelineException("Failed to create timeline in DB for: " + activeTimeline.getEventType(), tx);
} finally {
finishTimelineUpdate(activeTimeline.getEventType());
}
}
Aggregations