Search in sources :

Example 6 with GlobalPartitionInformation

use of org.apache.storm.kafka.trident.GlobalPartitionInformation in project storm by apache.

the class KafkaUtilsTest method moreTasksThanPartitions.

@Test
public void moreTasksThanPartitions() {
    GlobalPartitionInformation globalPartitionInformation = TestUtils.buildPartitionInfo(1);
    List<GlobalPartitionInformation> partitions = new ArrayList<GlobalPartitionInformation>();
    partitions.add(globalPartitionInformation);
    int numTasks = 2;
    assertEquals(1, KafkaUtils.calculatePartitionsForTask(partitions, numTasks, 0).size());
    assertEquals(0, KafkaUtils.calculatePartitionsForTask(partitions, numTasks, 1).size());
}
Also used : GlobalPartitionInformation(org.apache.storm.kafka.trident.GlobalPartitionInformation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with GlobalPartitionInformation

use of org.apache.storm.kafka.trident.GlobalPartitionInformation in project storm by apache.

the class KafkaUtilsTest method runPartitionToTaskMappingTest.

public void runPartitionToTaskMappingTest(int numPartitions, int partitionsPerTask) {
    GlobalPartitionInformation globalPartitionInformation = TestUtils.buildPartitionInfo(numPartitions);
    List<GlobalPartitionInformation> partitions = new ArrayList<GlobalPartitionInformation>();
    partitions.add(globalPartitionInformation);
    int numTasks = numPartitions / partitionsPerTask;
    for (int i = 0; i < numTasks; i++) {
        assertEquals(partitionsPerTask, KafkaUtils.calculatePartitionsForTask(partitions, numTasks, i).size());
    }
}
Also used : GlobalPartitionInformation(org.apache.storm.kafka.trident.GlobalPartitionInformation) ArrayList(java.util.ArrayList)

Example 8 with GlobalPartitionInformation

use of org.apache.storm.kafka.trident.GlobalPartitionInformation in project heron by twitter.

the class KafkaUtilsTest method runPartitionToTaskMappingTest.

public void runPartitionToTaskMappingTest(int numPartitions, int partitionsPerTask) {
    GlobalPartitionInformation globalPartitionInformation = TestUtils.buildPartitionInfo(numPartitions);
    List<GlobalPartitionInformation> partitions = new ArrayList<GlobalPartitionInformation>();
    partitions.add(globalPartitionInformation);
    int numTasks = numPartitions / partitionsPerTask;
    for (int i = 0; i < numTasks; i++) {
        assertEquals(partitionsPerTask, KafkaUtils.calculatePartitionsForTask(partitions, numTasks, i).size());
    }
}
Also used : GlobalPartitionInformation(org.apache.storm.kafka.trident.GlobalPartitionInformation) ArrayList(java.util.ArrayList)

Example 9 with GlobalPartitionInformation

use of org.apache.storm.kafka.trident.GlobalPartitionInformation in project heron by twitter.

the class DynamicBrokersReader method getBrokerInfo.

/**
   * Get all partitions with their current leaders
   */
public List<GlobalPartitionInformation> getBrokerInfo() throws SocketTimeoutException {
    List<String> topics = getTopics();
    List<GlobalPartitionInformation> partitions = new ArrayList<GlobalPartitionInformation>();
    for (String topic : topics) {
        GlobalPartitionInformation globalPartitionInformation = new GlobalPartitionInformation(topic, this.isWildcardTopic);
        try {
            int numPartitionsForTopic = getNumPartitions(topic);
            String brokerInfoPath = brokerPath();
            for (int partition = 0; partition < numPartitionsForTopic; partition++) {
                int leader = getLeaderFor(topic, partition);
                String path = brokerInfoPath + "/" + leader;
                try {
                    byte[] brokerData = curator.getData().forPath(path);
                    Broker hp = getBrokerHost(brokerData);
                    globalPartitionInformation.addPartition(partition, hp);
                } catch (org.apache.zookeeper.KeeperException.NoNodeException e) {
                    LOG.error("Node {} does not exist ", path);
                }
            }
        } catch (SocketTimeoutException e) {
            throw e;
        // SUPPRESS CHECKSTYLE IllegalCatch
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        LOG.info("Read partition info from zookeeper: " + globalPartitionInformation);
        partitions.add(globalPartitionInformation);
    }
    return partitions;
}
Also used : ArrayList(java.util.ArrayList) SocketTimeoutException(java.net.SocketTimeoutException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SocketTimeoutException(java.net.SocketTimeoutException) GlobalPartitionInformation(org.apache.storm.kafka.trident.GlobalPartitionInformation)

Example 10 with GlobalPartitionInformation

use of org.apache.storm.kafka.trident.GlobalPartitionInformation in project heron by twitter.

the class DynamicBrokersReaderTest method testGetBrokerInfoWildcardMatch.

@Test
public void testGetBrokerInfoWildcardMatch() throws Exception {
    String host = "localhost";
    int port = 9092;
    int partition = 0;
    addPartition(partition, host, port, topic);
    addPartition(partition, host, port, secondTopic);
    List<GlobalPartitionInformation> partitions = wildCardBrokerReader.getBrokerInfo();
    GlobalPartitionInformation brokerInfo = getByTopic(partitions, topic);
    assertNotNull(brokerInfo);
    assertEquals(1, brokerInfo.getOrderedPartitions().size());
    assertEquals(port, brokerInfo.getBrokerFor(partition).port);
    assertEquals(host, brokerInfo.getBrokerFor(partition).host);
    brokerInfo = getByTopic(partitions, secondTopic);
    assertNotNull(brokerInfo);
    assertEquals(1, brokerInfo.getOrderedPartitions().size());
    assertEquals(port, brokerInfo.getBrokerFor(partition).port);
    assertEquals(host, brokerInfo.getBrokerFor(partition).host);
    addPartition(partition, host, port, thirdTopic);
    //Discover newly added topic
    partitions = wildCardBrokerReader.getBrokerInfo();
    assertNotNull(getByTopic(partitions, topic));
    assertNotNull(getByTopic(partitions, secondTopic));
    assertNotNull(getByTopic(partitions, secondTopic));
}
Also used : GlobalPartitionInformation(org.apache.storm.kafka.trident.GlobalPartitionInformation) Test(org.junit.Test)

Aggregations

GlobalPartitionInformation (org.apache.storm.kafka.trident.GlobalPartitionInformation)25 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 SimpleConsumer (kafka.javaapi.consumer.SimpleConsumer)3 SocketTimeoutException (java.net.SocketTimeoutException)2 TopicAndPartition (kafka.common.TopicAndPartition)2 Before (org.junit.Before)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1