Search in sources :

Example 6 with ZooKeeperHolder

use of org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder in project nakadi by zalando.

the class KafkaRepositoryCreator method createTopicRepository.

@Override
public TopicRepository createTopicRepository(final Storage storage) throws TopicRepositoryException {
    try {
        final Storage.KafkaConfiguration kafkaConfiguration = storage.getKafkaConfiguration();
        final ZooKeeperHolder zooKeeperHolder = new ZooKeeperHolder(kafkaConfiguration.getZkAddress(), kafkaConfiguration.getZkPath(), kafkaConfiguration.getExhibitorAddress(), kafkaConfiguration.getExhibitorPort());
        final KafkaFactory kafkaFactory = new KafkaFactory(new KafkaLocationManager(zooKeeperHolder, kafkaSettings), metricRegistry);
        final KafkaTopicRepository kafkaTopicRepository = new KafkaTopicRepository(zooKeeperHolder, kafkaFactory, nakadiSettings, kafkaSettings, zookeeperSettings, uuidGenerator);
        // check that it does work
        kafkaTopicRepository.listTopics();
        return kafkaTopicRepository;
    } catch (final Exception e) {
        throw new TopicRepositoryException("Could not create topic repository", e);
    }
}
Also used : KafkaFactory(org.zalando.nakadi.repository.kafka.KafkaFactory) Storage(org.zalando.nakadi.domain.Storage) KafkaTopicRepository(org.zalando.nakadi.repository.kafka.KafkaTopicRepository) KafkaLocationManager(org.zalando.nakadi.repository.kafka.KafkaLocationManager) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) TopicRepositoryException(org.zalando.nakadi.exceptions.runtime.TopicRepositoryException) TopicRepositoryException(org.zalando.nakadi.exceptions.runtime.TopicRepositoryException)

Example 7 with ZooKeeperHolder

use of org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder in project nakadi by zalando.

the class NakadiConfigTest method setUp.

@Before
public void setUp() {
    final CuratorFramework curatorFramework = Mockito.mock(CuratorFramework.class);
    zooKeeperHolder = Mockito.mock(ZooKeeperHolder.class);
    Mockito.when(zooKeeperHolder.get()).thenReturn(curatorFramework);
    Mockito.when(curatorFramework.getData()).thenReturn(dataBuilder);
    Mockito.when(environment.getProperty("nakadi.zookeeper.exhibitor.port", "0")).thenReturn("0");
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) Before(org.junit.Before)

Example 8 with ZooKeeperHolder

use of org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder in project nakadi by zalando.

the class EventTypeCacheTest method testEventTypesPreloaded.

@Test
public void testEventTypesPreloaded() throws Exception {
    final EventTypeRepository etRepo = Mockito.mock(EventTypeRepository.class);
    final TimelineDbRepository timelineRepository = Mockito.mock(TimelineDbRepository.class);
    final ZooKeeperHolder zkHolder = Mockito.mock(ZooKeeperHolder.class);
    final TimelineSync timelineSync = Mockito.mock(TimelineSync.class);
    final EventType et = TestUtils.buildDefaultEventType();
    Mockito.when(etRepo.list()).thenReturn(Collections.singletonList(et));
    final Timeline timeline = TestUtils.buildTimeline(et.getName());
    final List<Timeline> timelines = Collections.singletonList(timeline);
    Mockito.when(timelineRepository.listTimelinesOrdered()).thenReturn(timelines);
    Mockito.when(timelineSync.registerTimelineChangeListener(Matchers.eq(et.getName()), Mockito.any())).thenReturn(() -> {
    });
    final EventTypeCache eventTypeCache = new EventTypeCache(etRepo, timelineRepository, zkHolder, null, timelineSync) {

        @Override
        public void created(final String name) throws Exception {
        // ignore this call, because mocking is too complex
        }
    };
    Assert.assertSame(et, eventTypeCache.getEventType(et.getName()));
    Mockito.verify(etRepo, Mockito.times(0)).findByName(Mockito.any());
    Mockito.verify(etRepo, Mockito.times(1)).list();
    Assert.assertEquals(timelines, eventTypeCache.getTimelinesOrdered(et.getName()));
    Mockito.verify(timelineRepository, Mockito.times(0)).listTimelinesOrdered(Mockito.any());
    Mockito.verify(timelineRepository, Mockito.times(1)).listTimelinesOrdered();
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) EventType(org.zalando.nakadi.domain.EventType) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) TimelineSync(org.zalando.nakadi.service.timeline.TimelineSync) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) Test(org.junit.Test)

Aggregations

ZooKeeperHolder (org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)8 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 Before (org.junit.Before)3 UUIDGenerator (org.zalando.nakadi.util.UUIDGenerator)3 EventType (org.zalando.nakadi.domain.EventType)2 CuratorZookeeperClient (org.apache.curator.CuratorZookeeperClient)1 GetChildrenBuilder (org.apache.curator.framework.api.GetChildrenBuilder)1 Test (org.junit.Test)1 Storage (org.zalando.nakadi.domain.Storage)1 Subscription (org.zalando.nakadi.domain.Subscription)1 Timeline (org.zalando.nakadi.domain.Timeline)1 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)1 TopicRepositoryException (org.zalando.nakadi.exceptions.runtime.TopicRepositoryException)1 EventTypeRepository (org.zalando.nakadi.repository.EventTypeRepository)1 TopicRepository (org.zalando.nakadi.repository.TopicRepository)1 SubscriptionDbRepository (org.zalando.nakadi.repository.db.SubscriptionDbRepository)1 KafkaFactory (org.zalando.nakadi.repository.kafka.KafkaFactory)1 KafkaLocationManager (org.zalando.nakadi.repository.kafka.KafkaLocationManager)1 KafkaTopicRepository (org.zalando.nakadi.repository.kafka.KafkaTopicRepository)1 ZooKeeperLockFactory (org.zalando.nakadi.repository.zookeeper.ZooKeeperLockFactory)1