use of kafka.utils.ZkUtils in project incubator-atlas by apache.
the class AtlasTopicCreatorTest method shouldNotCreateTopicIfItAlreadyExists.
@Test
public void shouldNotCreateTopicIfItAlreadyExists() {
Configuration configuration = mock(Configuration.class);
when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)).thenReturn(true);
when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false");
final ZkUtils zookeeperUtils = mock(ZkUtils.class);
final boolean[] topicExistsCalled = new boolean[] { false };
final boolean[] createTopicCalled = new boolean[] { false };
AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() {
@Override
protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) {
topicExistsCalled[0] = true;
return true;
}
@Override
protected ZkUtils createZkUtils(Configuration atlasProperties) {
return zookeeperUtils;
}
@Override
protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) {
createTopicCalled[0] = true;
}
};
atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK");
assertTrue(topicExistsCalled[0]);
assertFalse(createTopicCalled[0]);
}
use of kafka.utils.ZkUtils in project opennms by OpenNMS.
the class JUnitKafkaServer method getBrokerMetadatas.
private List<BrokerMetadata> getBrokerMetadatas() {
ZkClient zkClient = new ZkClient(getZookeeperConnectString(), 1000, 1000, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(getZookeeperConnectString()), false);
return JavaConversions.asJavaList(AdminUtils.getBrokerMetadatas(zkUtils, Enforced$.MODULE$, Option.empty()));
}
use of kafka.utils.ZkUtils in project flink by apache.
the class KafkaTestEnvironmentImpl method getLeaderToShutDown.
@Override
public int getLeaderToShutDown(String topic) throws Exception {
ZkUtils zkUtils = getZkUtils();
try {
PartitionMetadata firstPart = null;
do {
if (firstPart != null) {
LOG.info("Unable to find leader. error code {}", firstPart.errorCode());
// not the first try. Sleep a bit
Thread.sleep(150);
}
Seq<PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionsMetadata();
firstPart = partitionMetadata.head();
} while (firstPart.errorCode() != 0);
return firstPart.leader().get().id();
} finally {
zkUtils.close();
}
}
use of kafka.utils.ZkUtils in project ignite by apache.
the class TestKafkaBroker method setupZooKeeper.
/**
* Sets up ZooKeeper test server.
*
* @throws Exception If failed.
*/
private void setupZooKeeper() throws Exception {
zkServer = new TestingServer(ZK_PORT, true);
Tuple2<ZkClient, ZkConnection> zkTuple = ZkUtils.createZkClientAndConnection(zkServer.getConnectString(), ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT);
zkUtils = new ZkUtils(zkTuple._1(), zkTuple._2(), false);
}
use of kafka.utils.ZkUtils in project incubator-rya by apache.
the class KafkaTestInstanceRule method createTopic.
/**
* Utility method to provide additional unique topics if they are required.
* @param topicName - The Kafka topic to create.
*/
public void createTopic(final String topicName) {
// Setup Kafka.
ZkUtils zkUtils = null;
try {
logger.info("Creating Kafka Topic: '{}'", topicName);
zkUtils = ZkUtils.apply(new ZkClient(kafkaInstance.getZookeeperConnect(), 30000, 30000, ZKStringSerializer$.MODULE$), false);
AdminUtils.createTopic(zkUtils, topicName, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
} finally {
if (zkUtils != null) {
zkUtils.close();
}
}
}
Aggregations