Search in sources :

Example 1 with ZooKeeperHolder

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

the class KafkaTopicRepositoryTest method createZooKeeperHolder.

private ZooKeeperHolder createZooKeeperHolder() throws Exception {
    // GetChildrenBuilder
    final GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);
    when(getChildrenBuilder.forPath("/brokers/topics")).thenReturn(allTopics());
    // Curator Framework
    final CuratorFramework curatorFramework = mock(CuratorFramework.class);
    when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
    // ZooKeeperHolder
    final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
    when(zkHolder.get()).thenReturn(curatorFramework);
    return zkHolder;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)

Example 2 with ZooKeeperHolder

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

the class CursorsServiceAT method before.

@Before
public void before() throws Exception {
    sid = randomUUID();
    streamId = randomUUID();
    etName = randomValidEventTypeName();
    topic = randomUUID();
    cursorConverter = mock(CursorConverter.class);
    testCursors = ImmutableList.of(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
    final EventType eventType = mock(EventType.class);
    when(eventType.getName()).thenReturn(etName);
    final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
    when(zkHolder.get()).thenReturn(CURATOR);
    final TopicRepository topicRepository = mock(TopicRepository.class);
    final TimelineService timelineService = mock(TimelineService.class);
    when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
    timeline = buildTimeline(etName, topic, CREATED_AT);
    when(timelineService.getActiveTimeline(any(EventType.class))).thenReturn(timeline);
    final Subscription subscription = mock(Subscription.class);
    when(subscription.getId()).thenReturn(sid);
    when(subscription.getEventTypes()).thenReturn(ImmutableSet.of(etName));
    final SubscriptionDbRepository subscriptionRepo = mock(SubscriptionDbRepository.class);
    when(subscriptionRepo.getSubscription(sid)).thenReturn(subscription);
    final SubscriptionClientFactory zkSubscriptionFactory = new SubscriptionClientFactory(zkHolder, MAPPER);
    uuidGenerator = mock(UUIDGenerator.class);
    when(uuidGenerator.isUUID(any())).thenReturn(true);
    cursorsService = new CursorsService(subscriptionRepo, null, mock(NakadiSettings.class), zkSubscriptionFactory, cursorConverter, uuidGenerator, null);
    // Register cursors in converter
    registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
    registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, OLD_OFFSET));
    registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, NEW_OFFSET));
    registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, OLD_OFFSET));
    // bootstrap data in ZK
    CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P1), OLD_OFFSET.getBytes(UTF_8));
    CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P2), OLD_OFFSET.getBytes(UTF_8));
    CURATOR.create().creatingParentsIfNeeded().forPath(sessionPath(streamId));
}
Also used : CursorsService(org.zalando.nakadi.service.CursorsService) EventType(org.zalando.nakadi.domain.EventType) SubscriptionDbRepository(org.zalando.nakadi.repository.db.SubscriptionDbRepository) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Subscription(org.zalando.nakadi.domain.Subscription) CursorConverter(org.zalando.nakadi.service.CursorConverter) SubscriptionClientFactory(org.zalando.nakadi.service.subscription.zk.SubscriptionClientFactory) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) Before(org.junit.Before)

Example 3 with ZooKeeperHolder

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

the class TimelineSyncAT method createTimeline.

private TimelineSyncImpl createTimeline() throws InterruptedException {
    if (null == uuidGenerator) {
        uuidGenerator = new UUIDGenerator();
    }
    if (null == zookeeperHolder) {
        zookeeperHolder = Mockito.mock(ZooKeeperHolder.class);
        Mockito.when(zookeeperHolder.get()).thenReturn(CURATOR);
    }
    final TimelineSyncImpl result = new TimelineSyncImpl(zookeeperHolder, uuidGenerator);
    synchronized (DELAYED_RUNS) {
        DELAYED_RUNS.add(() -> {
            try {
                result.reactOnEventTypesChange();
            } catch (final InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        });
    }
    return result;
}
Also used : UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) TimelineSyncImpl(org.zalando.nakadi.service.timeline.TimelineSyncImpl) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)

Example 4 with ZooKeeperHolder

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

the class KafkaRepositoryAT method createKafkaTopicRepository.

private KafkaTopicRepository createKafkaTopicRepository() {
    final CuratorZookeeperClient zookeeperClient = mock(CuratorZookeeperClient.class);
    when(zookeeperClient.getCurrentConnectionString()).thenReturn(ZOOKEEPER_URL);
    final CuratorFramework curatorFramework = mock(CuratorFramework.class);
    when(curatorFramework.getZookeeperClient()).thenReturn(zookeeperClient);
    final ZooKeeperHolder zooKeeperHolder = mock(ZooKeeperHolder.class);
    when(zooKeeperHolder.get()).thenReturn(curatorFramework);
    final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
    when(consumer.partitionsFor(any())).thenReturn(new ArrayList<>());
    final KafkaFactory factory = mock(KafkaFactory.class);
    when(factory.getConsumer()).thenReturn(consumer);
    Mockito.doReturn(kafkaHelper.createProducer()).when(factory).takeProducer();
    return new KafkaTopicRepository(zooKeeperHolder, factory, nakadiSettings, kafkaSettings, zookeeperSettings, new UUIDGenerator());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)

Example 5 with ZooKeeperHolder

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

the class ConsumerLimitingServiceAT method before.

@Before
public void before() {
    eventType = TestUtils.randomValidEventTypeName();
    client = TestUtils.randomTextString();
    final ZooKeeperHolder zkHolder = Mockito.mock(ZooKeeperHolder.class);
    when(zkHolder.get()).thenReturn(CURATOR);
    final ZooKeeperLockFactory zkLockFactory = new ZooKeeperLockFactory(zkHolder);
    limitingService = new ConsumerLimitingService(zkHolder, zkLockFactory, 5);
}
Also used : ZooKeeperLockFactory(org.zalando.nakadi.repository.zookeeper.ZooKeeperLockFactory) ConsumerLimitingService(org.zalando.nakadi.service.ConsumerLimitingService) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder) Before(org.junit.Before)

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