Search in sources :

Example 1 with UUIDGenerator

use of org.zalando.nakadi.util.UUIDGenerator 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 2 with UUIDGenerator

use of org.zalando.nakadi.util.UUIDGenerator 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 3 with UUIDGenerator

use of org.zalando.nakadi.util.UUIDGenerator 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)

Aggregations

ZooKeeperHolder (org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)3 UUIDGenerator (org.zalando.nakadi.util.UUIDGenerator)3 CuratorZookeeperClient (org.apache.curator.CuratorZookeeperClient)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 Before (org.junit.Before)1 EventType (org.zalando.nakadi.domain.EventType)1 Subscription (org.zalando.nakadi.domain.Subscription)1 TopicRepository (org.zalando.nakadi.repository.TopicRepository)1 SubscriptionDbRepository (org.zalando.nakadi.repository.db.SubscriptionDbRepository)1 CursorConverter (org.zalando.nakadi.service.CursorConverter)1 CursorsService (org.zalando.nakadi.service.CursorsService)1 SubscriptionClientFactory (org.zalando.nakadi.service.subscription.zk.SubscriptionClientFactory)1 TimelineService (org.zalando.nakadi.service.timeline.TimelineService)1 TimelineSyncImpl (org.zalando.nakadi.service.timeline.TimelineSyncImpl)1