Search in sources :

Example 61 with Timeline

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);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) Test(org.junit.Test)

Example 62 with Timeline

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);
}
Also used : Storage(org.zalando.nakadi.domain.Storage) InconsistentStateException(org.zalando.nakadi.exceptions.runtime.InconsistentStateException) IntStream.range(java.util.stream.IntStream.range) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Date(java.util.Date) NakadiSettings(org.zalando.nakadi.config.NakadiSettings) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) TopicRepositoryHolder(org.zalando.nakadi.repository.TopicRepositoryHolder) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) ImmutableList(com.google.common.collect.ImmutableList) Matchers.eq(org.mockito.Matchers.eq) AdminService(org.zalando.nakadi.service.AdminService) FeatureToggleService(org.zalando.nakadi.service.FeatureToggleService) EventType(org.zalando.nakadi.domain.EventType) TopicRepository(org.zalando.nakadi.repository.TopicRepository) TimelineException(org.zalando.nakadi.exceptions.TimelineException) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) Test(org.junit.Test) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Collectors(java.util.stream.Collectors) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) DefaultStorage(org.zalando.nakadi.domain.DefaultStorage) List(java.util.List) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Timeline(org.zalando.nakadi.domain.Timeline) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TimelineDbRepository(org.zalando.nakadi.repository.db.TimelineDbRepository) Assert(org.junit.Assert) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) Collections(java.util.Collections) StorageDbRepository(org.zalando.nakadi.repository.db.StorageDbRepository) Mockito.mock(org.mockito.Mockito.mock) Timeline(org.zalando.nakadi.domain.Timeline) Date(java.util.Date) Test(org.junit.Test)

Example 63 with Timeline

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());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Date(java.util.Date) Test(org.junit.Test)

Example 64 with Timeline

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));
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Test(org.junit.Test)

Example 65 with Timeline

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));
    }
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Test(org.junit.Test)

Aggregations

Timeline (org.zalando.nakadi.domain.Timeline)74 Test (org.junit.Test)39 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)33 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)19 TopicRepository (org.zalando.nakadi.repository.TopicRepository)17 Date (java.util.Date)14 EventType (org.zalando.nakadi.domain.EventType)14 List (java.util.List)13 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)13 Storage (org.zalando.nakadi.domain.Storage)13 Collectors (java.util.stream.Collectors)12 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)12 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)9 NakadiSettings (org.zalando.nakadi.config.NakadiSettings)9 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)9 Optional (java.util.Optional)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 NakadiException (org.zalando.nakadi.exceptions.NakadiException)8