当前位置: 首页>>代码示例>>Java>>正文


Java TestUtils类代码示例

本文整理汇总了Java中kafka.utils.TestUtils的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TestUtils类属于kafka.utils包,在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import kafka.utils.TestUtils; //导入依赖的package包/类
public void initialize() {
    if (initialized) {
        throw new IllegalStateException("Context has been already initialized");
    }
    zkServer = new EmbeddedZookeeper(TestZKUtils.zookeeperConnect());
    zkClient = new ZkClient(zkServer.connectString(), 10000, 10000, ZKStringSerializer$.MODULE$);

    port = TestUtils.choosePort();

    KafkaConfig config = new KafkaConfig(TestUtils.createBrokerConfig(brokerId, port, true));
    Time mock = new MockTime();

    kafkaServer = new KafkaServer(config, mock);
    kafkaServer.startup();

    initialized = true;
}
 
开发者ID:researchgate,项目名称:kafka-metamorph,代码行数:18,代码来源:Kafka08TestContext.java

示例2: setUpClass

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    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("kafkaUtils-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topics
    AdminUtils.createTopic(zkUtils, TOPIC_R, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
    AdminUtils.createTopic(zkUtils, TOPIC_S, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:24,代码来源:KafkaUtilsTest.java

示例3: startKafkaBrokers

import kafka.utils.TestUtils; //导入依赖的package包/类
public static void startKafkaBrokers(int numberOfBrokers) {
  kafkaServers = new ArrayList<>(numberOfBrokers);
  kafkaProps = new HashMap<>();
  // setup Broker
  StringBuilder sb = new StringBuilder();
  for(int i = 0; i < numberOfBrokers; i ++) {
    int port = TestUtils.choosePort();
    Properties props = TestUtils.createBrokerConfig(i, port);
    props.put("auto.create.topics.enable", "false");
    kafkaServers.add(TestUtils.createServer(new KafkaConfig(props), new MockTime()));
    sb.append("localhost:").append(port).append(",");
  }
  metadataBrokerURI = sb.deleteCharAt(sb.length()-1).toString();
  LOG.info("Setting metadataBrokerList and auto.offset.reset for test case");
  kafkaProps.put("auto.offset.reset", "smallest");
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:KafkaTestUtil.java

示例4: setUp

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  randomPort = NetworkUtils.getRandomPort();

  sdcKafkaTestUtil.startZookeeper();
  sdcKafkaTestUtil.startKafkaBrokers(3);
  // create topic
  sdcKafkaTestUtil.createTopic(TOPIC1, PARTITIONS, REPLICATION_FACTOR);

  for (int i = 1; i <= 1 ; i++) {
    for (int j = 0; j < PARTITIONS; j++) {
      TestUtils.waitUntilMetadataIsPropagated(
          scala.collection.JavaConversions.asScalaBuffer(sdcKafkaTestUtil.getKafkaServers()),
          "TestHttpToKafka" + String.valueOf(i), j, 5000);
    }
  }
  kafkaStreams1 = sdcKafkaTestUtil.createKafkaStream(sdcKafkaTestUtil.getZkConnect(), TOPIC1, PARTITIONS);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestHttpToKafka.java

示例5: setUpClass

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    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);

    // create topic
    AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaDestinationProcessorTest.java

示例6: setUpClass

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
  int zkConnectionTimeout = 6000;
  int zkSessionTimeout = 6000;

  zookeeper = new EmbeddedZookeeper();
  zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
  zkUtils = ZkUtils.apply(
      zkConnect, zkSessionTimeout, zkConnectionTimeout,
      JaasUtils.isZkSecurityEnabled());

  port = NetworkUtils.getRandomPort();
  kafkaServer = TestUtil09.createKafkaServer(port, zkConnect);
  for (int i = 0; i < topics.length; i++) {
    topics[i] = UUID.randomUUID().toString();
    AdminUtils.createTopic(zkUtils, topics[i], 1, 1, new Properties());

    TestUtils.waitUntilMetadataIsPropagated(
        scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(kafkaServer)),
        topics[i], 0, 5000);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:23,代码来源:KafkaProducer09IT.java

示例7: setUp

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  sdcKafkaTestUtil.startZookeeper();
  sdcKafkaTestUtil.startKafkaBrokers(3);
  // create topic
  sdcKafkaTestUtil.createTopic(TOPIC1, PARTITIONS, REPLICATION_FACTOR);

  for (int i = 1; i <= 1 ; i++) {
    for (int j = 0; j < PARTITIONS; j++) {
      TestUtils.waitUntilMetadataIsPropagated(
          scala.collection.JavaConversions.asScalaBuffer(sdcKafkaTestUtil.getKafkaServers()),
          "TestUDPToKafkaSource" + String.valueOf(i), j, 5000);
    }
  }
  kafkaStreams1 = sdcKafkaTestUtil.createKafkaStream(sdcKafkaTestUtil.getZkConnect(), TOPIC1, PARTITIONS);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:TestUDPToKafkaSource.java

示例8: setUp

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  randomPort = NetworkUtils.getRandomPort();

  sdcKafkaTestUtil.startZookeeper();
  sdcKafkaTestUtil.startKafkaBrokers(3);
  // create topic
  sdcKafkaTestUtil.createTopic(TOPIC1, PARTITIONS, REPLICATION_FACTOR);

  for (int i = 1; i <= 1 ; i++) {
    for (int j = 0; j < PARTITIONS; j++) {
      TestUtils.waitUntilMetadataIsPropagated(
          scala.collection.JavaConversions.asScalaBuffer(sdcKafkaTestUtil.getKafkaServers()),
          "TestSdcIpcToKafka" + String.valueOf(i), j, 5000);
    }
  }
  kafkaStreams1 = sdcKafkaTestUtil.createKafkaStream(sdcKafkaTestUtil.getZkConnect(), TOPIC1, PARTITIONS);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestSdcIpcToKafka.java

示例9: start

import kafka.utils.TestUtils; //导入依赖的package包/类
public void start() throws IOException {

        String zkConnect = TestZKUtils.zookeeperConnect();
        zkServer = new EmbeddedZookeeper(zkConnect);
        zkClient =
                new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
        brokerPort = TestUtils.choosePort();
        logger.info("{}", brokerPort);;
        Properties props = TestUtils.createBrokerConfig(BROKER_ID, brokerPort, true);
        // props.setProperty("zookeeper.connect", String.valueOf(zkPort));
        props.setProperty("zookeeper.session.timeout.ms", "30000");
        props.setProperty("zookeeper.connection.timeout.ms", "30000");
        logger.info("{}", props);
        KafkaConfig config = new KafkaConfig(props);
        Time mock = new MockTime();
        kafkaServer = TestUtils.createServer(config, mock);
    }
 
开发者ID:trustedanalytics,项目名称:data-acquisition,代码行数:18,代码来源:KafkaEmbeded.java

示例10: startServer

import kafka.utils.TestUtils; //导入依赖的package包/类
public static void startServer() throws RuntimeException {
  if ( serverStarted && serverClosed ) {
    throw new RuntimeException("Kafka test server has already been closed. Cannot generate Kafka server twice.");
  }
  if (!serverStarted) {
    serverStarted = true;
    zkConnect = TestZKUtils.zookeeperConnect();
    zkServer = new EmbeddedZookeeper(zkConnect);
    zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);

    kafkaPort = TestUtils.choosePort();
    Properties props = TestUtils.createBrokerConfig(brokerId, kafkaPort, true);

    KafkaConfig config = new KafkaConfig(props);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:19,代码来源:KafkaTestBase.java

示例11: createKafkaCluster

import kafka.utils.TestUtils; //导入依赖的package包/类
public final String createKafkaCluster() throws IOException {
    System.setProperty("zookeeper.preAllocSize", Integer.toString(128));
    zkServer = new EmbeddedZookeeper();
    String zkConnect = ZK_HOST + ':' + zkServer.port();
    ZkClient zkClient = new ZkClient(zkConnect, SESSION_TIMEOUT, CONNECTION_TIMEOUT, ZKStringSerializer$.MODULE$);
    zkUtils = ZkUtils.apply(zkClient, false);
    brokerPort = getRandomPort();

    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://" + BROKER_HOST + ':' + brokerPort);
    brokerProps.setProperty("offsets.topic.replication.factor", "1");
    brokerProps.setProperty("offsets.topic.num.partitions", "1");
    // we need this due to avoid OOME while running tests, see https://issues.apache.org/jira/browse/KAFKA-3872
    brokerProps.setProperty("log.cleaner.dedupe.buffer.size", Long.toString(2 * 1024 * 1024L));
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    return BROKER_HOST + ':' + brokerPort;
}
 
开发者ID:hazelcast,项目名称:hazelcast-jet,代码行数:24,代码来源:KafkaTestSupport.java

示例12: initProducer

import kafka.utils.TestUtils; //导入依赖的package包/类
private void initProducer(String bootstrapServer) {
  producer = TestUtils.createNewProducer(
      bootstrapServer,
      1,
      60 * 1000L,
      1024L * 1024L,
      0,
      0L,
      5 * 1000L,
      SecurityProtocol.PLAINTEXT,
      null,
      Option$.MODULE$.apply(new Properties()),
      new StringSerializer(),
      new ByteArraySerializer(),
      Option$.MODULE$.apply(new Properties()));
}
 
开发者ID:apache,项目名称:samza,代码行数:17,代码来源:TestStreamProcessor.java

示例13: setUpClass

import kafka.utils.TestUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    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);

    // create topics        
    AdminUtils.createTopic(zkUtils, TOPIC_OOS, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaEntranceProcessorTest.java

示例14: publish

import kafka.utils.TestUtils; //导入依赖的package包/类
public void publish(String topic, List<String> messages)
{
  Properties producerProps = new Properties();
  producerProps.setProperty("bootstrap.servers", BROKERHOST + ":" + BROKERPORT);
  producerProps.setProperty("key.serializer", "org.apache.kafka.common.serialization.IntegerSerializer");
  producerProps.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");

  try (KafkaProducer<Integer, byte[]> producer = new KafkaProducer<>(producerProps)) {
    for (String message : messages) {
      ProducerRecord<Integer, byte[]> data = new ProducerRecord<>(topic, message.getBytes(StandardCharsets.UTF_8));
      producer.send(data);
    }
  }

  List<KafkaServer> servers = new ArrayList<KafkaServer>();
  servers.add(kafkaServer);
  TestUtils.waitUntilMetadataIsPropagated(scala.collection.JavaConversions.asScalaBuffer(servers), topic, 0, 30000);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:19,代码来源:EmbeddedKafka.java

示例15: startup

import kafka.utils.TestUtils; //导入依赖的package包/类
/**
 * Starts the Embedded Kafka and Zookeeper Servers.
 * @throws Exception - If an exeption occurs during startup.
 */
protected void startup() throws Exception {
    // Setup the embedded zookeeper
    logger.info("Starting up Embedded Zookeeper...");
    zkServer = new EmbeddedZookeeper();
    zookeperConnect = ZKHOST + ":" + zkServer.port();
    logger.info("Embedded Zookeeper started at: {}", zookeperConnect);

    // setup Broker
    logger.info("Starting up Embedded Kafka...");
    brokerPort = Integer.toString(PortUtils.getRandomFreePort());
    final Properties brokerProps = new Properties();
    brokerProps.setProperty(KafkaConfig$.MODULE$.BrokerIdProp(), "0");
    brokerProps.setProperty(KafkaConfig$.MODULE$.HostNameProp(), BROKERHOST);
    brokerProps.setProperty(KafkaConfig$.MODULE$.PortProp(), brokerPort);
    brokerProps.setProperty(KafkaConfig$.MODULE$.ZkConnectProp(), zookeperConnect);
    brokerProps.setProperty(KafkaConfig$.MODULE$.LogDirsProp(), Files.createTempDirectory(getClass().getSimpleName() + "-").toAbsolutePath().toString());
    final KafkaConfig config = new KafkaConfig(brokerProps);
    final Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    logger.info("Embedded Kafka Server started at: {}:{}", BROKERHOST, brokerPort);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:26,代码来源:EmbeddedKafkaInstance.java


注:本文中的kafka.utils.TestUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。