use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class CursorOperationsServiceTest method testShiftBeforeInitialBegin.
@Test(expected = InvalidCursorOperation.class)
public void testShiftBeforeInitialBegin() throws Exception {
final Timeline first = mockTimeline(1, 1L);
mockTimelines(first);
final ShiftedNakadiCursor moveBack = new ShiftedNakadiCursor(first, "0", "-1", -1);
service.unshiftCursor(moveBack);
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineServiceTest method testGetActiveTimelinesOrderedFilters.
@Test
public void testGetActiveTimelinesOrderedFilters() throws Exception {
final String eventTypeName = "my-et";
final List<Timeline> testTimelines = range(0, 5).mapToObj(x -> mock(Timeline.class)).collect(Collectors.toList());
Mockito.when(testTimelines.get(0).getSwitchedAt()).thenReturn(new Date());
Mockito.when(testTimelines.get(0).isDeleted()).thenReturn(false);
Mockito.when(testTimelines.get(1).getSwitchedAt()).thenReturn(new Date());
Mockito.when(testTimelines.get(1).isDeleted()).thenReturn(false);
Mockito.when(testTimelines.get(2).getSwitchedAt()).thenReturn(null);
Mockito.when(testTimelines.get(2).isDeleted()).thenReturn(false);
Mockito.when(testTimelines.get(3).getSwitchedAt()).thenReturn(new Date());
Mockito.when(testTimelines.get(3).isDeleted()).thenReturn(true);
Mockito.when(testTimelines.get(4).getSwitchedAt()).thenReturn(new Date());
Mockito.when(testTimelines.get(4).isDeleted()).thenReturn(false);
Mockito.when(eventTypeCache.getTimelinesOrdered(eq(eventTypeName))).thenReturn(testTimelines);
final List<Timeline> expectedResult = ImmutableList.of(testTimelines.get(0), testTimelines.get(1), testTimelines.get(4));
final List<Timeline> result = timelineService.getActiveTimelinesOrdered(eventTypeName);
Assert.assertEquals(expectedResult, result);
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineServiceTest method shouldDeleteAllTimelinesWhenOneTimelineWasMarkedAsDeleted.
@Test
public void shouldDeleteAllTimelinesWhenOneTimelineWasMarkedAsDeleted() throws Exception {
final EventType eventType = buildDefaultEventType();
final Timeline t1 = Timeline.createTimeline(eventType.getName(), 1, null, "topic1", new Date());
t1.setDeleted(true);
t1.setSwitchedAt(new Date());
final Timeline t2 = Timeline.createTimeline(eventType.getName(), 2, null, "topic2", new Date());
t2.setSwitchedAt(new Date());
Mockito.when(eventTypeCache.getTimelinesOrdered(eventType.getName())).thenReturn(ImmutableList.of(t1, t2));
timelineService.deleteAllTimelinesForEventType(eventType.getName());
Mockito.verify(timelineDbRepository, Mockito.times(2)).deleteTimeline(Mockito.any());
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineCleaningJobTest method whenCleanupTimelinesAndCacheFailedToUpdateThenTimelineStateIsReverted.
@Test
public void whenCleanupTimelinesAndCacheFailedToUpdateThenTimelineStateIsReverted() throws Exception {
final Timeline t1 = createTimeline("et1", "topic1");
final ImmutableList<Timeline> expiredTimelines = ImmutableList.of(t1);
when(timelineDbRepository.getExpiredTimelines()).thenReturn(expiredTimelines);
final TopicRepository topicRepository = mock(TopicRepository.class);
when(timelineService.getTopicRepository(eq(t1))).thenReturn(topicRepository);
doThrow(new Exception()).when(eventTypeCache).updated(any());
timelineCleanupJob.cleanupTimelines();
verify(timelineDbRepository, times(2)).updateTimelime(any());
assertThat(t1.isDeleted(), is(false));
}
use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.
the class TimelineCleaningJobTest method whenCleanupTimelinesThenOk.
@Test
public void whenCleanupTimelinesThenOk() throws Exception {
final Timeline t1 = createTimeline("et1", "topic1");
final Timeline t2 = createTimeline("et2", "topic2");
final ImmutableList<Timeline> expiredTimelines = ImmutableList.of(t1, t2);
when(timelineDbRepository.getExpiredTimelines()).thenReturn(expiredTimelines);
final TopicRepository topicRepository = mock(TopicRepository.class);
when(timelineService.getTopicRepository(argThat(isOneOf(t1, t2)))).thenReturn(topicRepository);
timelineCleanupJob.cleanupTimelines();
final ArgumentCaptor<Timeline> timelineCaptor = ArgumentCaptor.forClass(Timeline.class);
verify(timelineDbRepository, times(2)).updateTimelime(timelineCaptor.capture());
final List<Timeline> updatedTimelines = timelineCaptor.getAllValues();
final Iterator<Timeline> updatedTimelinesIterator = updatedTimelines.iterator();
for (final Timeline timeline : expiredTimelines) {
verify(topicRepository).deleteTopic(timeline.getTopic());
verify(eventTypeCache).updated(timeline.getEventType());
final Timeline updatedTimeline = updatedTimelinesIterator.next();
assertThat(timeline.getEventType(), equalTo(updatedTimeline.getEventType()));
assertThat(updatedTimeline.isDeleted(), is(true));
}
}
Aggregations