Search in sources :

Example 6 with ZkUtils

use of kafka.utils.ZkUtils in project phoenix by apache.

the class PhoenixConsumerIT method setUp.

@Before
public void setUp() throws IOException, SQLException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    kafkaServer.startup();
    // create topic
    AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties());
    pConsumer = new PhoenixConsumer();
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    conn = DriverManager.getConnection(getUrl(), props);
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper) PhoenixConsumer(org.apache.phoenix.kafka.consumer.PhoenixConsumer) MockTime(kafka.utils.MockTime) Time(kafka.utils.Time) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) KafkaConfig(kafka.server.KafkaConfig) Before(org.junit.Before)

Example 7 with ZkUtils

use of kafka.utils.ZkUtils in project metron by apache.

the class KafkaComponent method createTopic.

public void createTopic(String name, int numPartitions, boolean waitUntilMetadataIsPropagated) throws InterruptedException {
    ZkUtils zkUtils = null;
    Level oldLevel = UnitTestHelper.getJavaLoggingLevel();
    try {
        UnitTestHelper.setJavaLoggingLevel(Level.OFF);
        zkUtils = ZkUtils.apply(zookeeperConnectString, 30000, 30000, false);
        AdminUtilsWrapper.createTopic(zkUtils, name, numPartitions, 1, new Properties());
        if (waitUntilMetadataIsPropagated) {
            waitUntilMetadataIsPropagated(name, numPartitions);
        }
    } catch (TopicExistsException tee) {
    } finally {
        if (zkUtils != null) {
            zkUtils.close();
        }
        UnitTestHelper.setJavaLoggingLevel(oldLevel);
    }
}
Also used : Level(java.util.logging.Level) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) TopicExistsException(kafka.common.TopicExistsException)

Example 8 with ZkUtils

use of kafka.utils.ZkUtils in project cruise-control by linkedin.

the class KafkaCruiseControlUnitTestUtils method zkUtils.

public static ZkUtils zkUtils(String zkConnect) {
    ZkConnection zkConnection = new ZkConnection(zkConnect, 30000);
    ZkClient zkClient = new ZkClient(zkConnection, 30000, new ZKStringSerializer());
    return new ZkUtils(zkClient, zkConnection, false);
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Example 9 with ZkUtils

use of kafka.utils.ZkUtils in project cruise-control by linkedin.

the class LoadMonitorTaskRunnerTest method setUp.

@Before
public void setUp() {
    super.setUp();
    ZkUtils zkUtils = KafkaCruiseControlUnitTestUtils.zkUtils(zookeeper().getConnectionString());
    for (int i = 0; i < NUM_TOPICS; i++) {
        AdminUtils.createTopic(zkUtils, "topic-" + i, NUM_PARTITIONS, 1, new Properties(), RackAwareMode.Safe$.MODULE$);
    }
}
Also used : ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) Before(org.junit.Before)

Example 10 with ZkUtils

use of kafka.utils.ZkUtils in project cruise-control by linkedin.

the class ExecutorTest method testBrokerDiesWhenMovePartitions.

@Test
public void testBrokerDiesWhenMovePartitions() throws Exception {
    ZkUtils zkUtils = KafkaCruiseControlUnitTestUtils.zkUtils(zookeeper().getConnectionString());
    Map<String, TopicDescription> topicDescriptions = createTopics();
    int initialLeader0 = topicDescriptions.get(TOPIC_0).partitions().get(0).leader().id();
    int initialLeader1 = topicDescriptions.get(TOPIC_1).partitions().get(0).leader().id();
    _brokers.get(initialLeader0 == 0 ? 1 : 0).shutdown();
    ExecutionProposal proposal0 = new ExecutionProposal(TP0, 0, initialLeader0, Collections.singletonList(initialLeader0), Collections.singletonList(initialLeader0 == 0 ? 1 : 0));
    ExecutionProposal proposal1 = new ExecutionProposal(TP1, 0, initialLeader1, Arrays.asList(initialLeader1, initialLeader1 == 0 ? 1 : 0), Arrays.asList(initialLeader1 == 0 ? 1 : 0, initialLeader1));
    Collection<ExecutionProposal> proposalsToExecute = Arrays.asList(proposal0, proposal1);
    executeAndVerifyProposals(zkUtils, proposalsToExecute, Collections.emptyList());
    // We are not doing the rollback.
    assertEquals(Collections.singletonList(initialLeader0 == 0 ? 1 : 0), ExecutorUtils.newAssignmentForPartition(zkUtils, TP0));
    assertEquals(initialLeader0, zkUtils.getLeaderForPartition(TOPIC_1, PARTITION).get());
}
Also used : TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ZkUtils(kafka.utils.ZkUtils) Test(org.junit.Test)

Aggregations

ZkUtils (kafka.utils.ZkUtils)61 ZkClient (org.I0Itec.zkclient.ZkClient)26 Properties (java.util.Properties)25 ZkConnection (org.I0Itec.zkclient.ZkConnection)22 Test (org.testng.annotations.Test)18 Configuration (org.apache.commons.configuration.Configuration)16 HashMap (java.util.HashMap)8 KafkaConfig (kafka.server.KafkaConfig)8 TestingServer (org.apache.curator.test.TestingServer)8 KafkaServerStartable (kafka.server.KafkaServerStartable)7 ServerSocket (java.net.ServerSocket)6 Test (org.junit.Test)4 File (java.io.File)3 Path (java.nio.file.Path)2 Level (java.util.logging.Level)2 TopicMetadata (kafka.api.TopicMetadata)2 TopicExistsException (kafka.common.TopicExistsException)2 InstanceSpec (org.apache.curator.test.InstanceSpec)2 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)2 Before (org.junit.Before)2