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);
}
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);
}
}
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);
}
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$);
}
}
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());
}
Aggregations