Search in sources :

Example 41 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class EventTypeCacheTestAT method getMockedTimelines.

private List<Timeline> getMockedTimelines(final String etName) {
    final Timeline t1 = new Timeline(etName, 0, new Storage(), "topic", new Date());
    final Timeline t2 = new Timeline(etName, 1, new Storage(), "topic", new Date(System.currentTimeMillis() + 200));
    t2.setSwitchedAt(new Date(System.currentTimeMillis() + 300));
    final Timeline t3 = new Timeline(etName, 2, new Storage(), "topic", new Date(System.currentTimeMillis() + 500));
    return ImmutableList.of(t1, t2, t3);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) Date(java.util.Date)

Example 42 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class StorageDbRepositoryTest method testDeleteUsedStorage.

@Test(expected = StorageIsUsedException.class)
public void testDeleteUsedStorage() throws Exception {
    final String name = randomUUID();
    final Storage storage = repository.createStorage(createStorage(name, "exaddress", 8181, "address", "path"));
    final EventType eventType = eventTypeDbRepository.saveEventType(TestUtils.buildDefaultEventType());
    final Timeline timeline = TimelineDbRepositoryTest.createTimeline(storage, UUID.randomUUID(), 0, "topic", eventType.getName(), new Date(), new Date(), null, null);
    timelineDbRepository.createTimeline(timeline);
    repository.deleteStorage(storage.getId());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Storage(org.zalando.nakadi.domain.Storage) EventType(org.zalando.nakadi.domain.EventType) Date(java.util.Date) Test(org.junit.Test)

Example 43 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class TimelineDbRepositoryTest method testTimelineUpdate.

@Test
public void testTimelineUpdate() {
    final Timeline initial = insertTimeline(0);
    final Timeline modified = tRepository.getTimeline(initial.getId()).get();
    modified.setCreatedAt(new Date());
    modified.setCleanedUpAt(new Date());
    modified.setSwitchedAt(new Date());
    final Timeline.KafkaStoragePosition pos = new Timeline.KafkaStoragePosition();
    pos.setOffsets(LongStream.range(0L, 10L).mapToObj(Long::new).collect(Collectors.toList()));
    modified.setLatestPosition(pos);
    tRepository.updateTimelime(modified);
    final Timeline result = tRepository.getTimeline(modified.getId()).get();
    Assert.assertEquals(modified, result);
    Assert.assertNotEquals(initial, result);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Date(java.util.Date) Test(org.junit.Test)

Example 44 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class TimelineDbRepositoryTest method testTimelineDeleted.

@Test
public void testTimelineDeleted() {
    final Timeline t1 = insertTimeline(1);
    Assert.assertEquals(1, tRepository.listTimelinesOrdered(testEt.getName()).size());
    tRepository.deleteTimeline(t1.getId());
    Assert.assertEquals(0, tRepository.listTimelinesOrdered(testEt.getName()).size());
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) Test(org.junit.Test)

Example 45 with Timeline

use of org.zalando.nakadi.domain.Timeline in project nakadi by zalando.

the class KafkaTopicRepositoryTest method canLoadPartitionEndStatistics.

@Test
public void canLoadPartitionEndStatistics() 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<PartitionEndStatistics> stats = kafkaTopicRepository.loadTopicEndStatistics(timelines);
    final Set<PartitionEndStatistics> expected = PARTITIONS.stream().map(p -> {
        final Timeline timeline = p.topic.equals(MY_TOPIC) ? t1 : t2;
        return new KafkaPartitionEndStatistics(timeline, p.partition, p.latestOffset - 1);
    }).collect(Collectors.toSet());
    assertThat(newHashSet(stats), equalTo(expected));
}
Also used : EventPublishingException(org.zalando.nakadi.exceptions.EventPublishingException) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) KafkaException(org.apache.kafka.common.KafkaException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Assert.fail(org.junit.Assert.fail) Matchers.anyVararg(org.mockito.Matchers.anyVararg) Consumer(org.apache.kafka.clients.consumer.Consumer) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) PartitionStatistics(org.zalando.nakadi.domain.PartitionStatistics) Set(java.util.Set) PartitionInfo(org.apache.kafka.common.PartitionInfo) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Collectors(java.util.stream.Collectors) Matchers.any(org.mockito.Matchers.any) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) TestUtils.buildTimelineWithTopic(org.zalando.nakadi.utils.TestUtils.buildTimelineWithTopic) Timeline(org.zalando.nakadi.domain.Timeline) ZookeeperSettings(org.zalando.nakadi.repository.zookeeper.ZookeeperSettings) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BatchItem(org.zalando.nakadi.domain.BatchItem) Node(org.apache.kafka.common.Node) Matchers.is(org.hamcrest.Matchers.is) Callback(org.apache.kafka.clients.producer.Callback) Mockito.mock(org.mockito.Mockito.mock) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) NakadiSettings(org.zalando.nakadi.config.NakadiSettings) Cursor(org.zalando.nakadi.view.Cursor) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) HashSet(java.util.HashSet) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) TimeoutException(org.apache.kafka.common.errors.TimeoutException) PartitionEndStatistics(org.zalando.nakadi.domain.PartitionEndStatistics) Test(org.junit.Test) BufferExhaustedException(org.apache.kafka.clients.producer.BufferExhaustedException) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) EventPublishingStatus(org.zalando.nakadi.domain.EventPublishingStatus) CursorError(org.zalando.nakadi.domain.CursorError) Assert(org.junit.Assert) Collections(java.util.Collections) Timeline(org.zalando.nakadi.domain.Timeline) PartitionEndStatistics(org.zalando.nakadi.domain.PartitionEndStatistics) 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