Search in sources :

Example 1 with SocketServer

use of kafka.network.SocketServer in project flink by apache.

the class KafkaTestEnvironmentImpl method prepare.

@Override
public void prepare(int numKafkaServers, Properties additionalServerProperties, boolean secureMode) {
    //increase the timeout since in Travis ZK connection takes long time for secure connection.
    if (secureMode) {
        //run only one kafka server to avoid multiple ZK connections from many instances - Travis timeout
        numKafkaServers = 1;
        zkTimeout = String.valueOf(Integer.parseInt(zkTimeout) * 15);
    }
    this.additionalServerProperties = additionalServerProperties;
    this.secureMode = secureMode;
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    tmpZkDir = new File(tempDir, "kafkaITcase-zk-dir-" + (UUID.randomUUID().toString()));
    assertTrue("cannot create zookeeper temp dir", tmpZkDir.mkdirs());
    tmpKafkaParent = new File(tempDir, "kafkaITcase-kafka-dir*" + (UUID.randomUUID().toString()));
    assertTrue("cannot create kafka temp dir", tmpKafkaParent.mkdirs());
    tmpKafkaDirs = new ArrayList<>(numKafkaServers);
    for (int i = 0; i < numKafkaServers; i++) {
        File tmpDir = new File(tmpKafkaParent, "server-" + i);
        assertTrue("cannot create kafka temp dir", tmpDir.mkdir());
        tmpKafkaDirs.add(tmpDir);
    }
    zookeeper = null;
    brokers = null;
    try {
        LOG.info("Starting Zookeeper");
        zookeeper = new TestingServer(-1, tmpZkDir);
        zookeeperConnectionString = zookeeper.getConnectString();
        LOG.info("zookeeperConnectionString: {}", zookeeperConnectionString);
        LOG.info("Starting KafkaServer");
        brokers = new ArrayList<>(numKafkaServers);
        for (int i = 0; i < numKafkaServers; i++) {
            brokers.add(getKafkaServer(i, tmpKafkaDirs.get(i)));
            SocketServer socketServer = brokers.get(i).socketServer();
            if (secureMode) {
                brokerConnectionString += hostAndPortToUrlString(KafkaTestEnvironment.KAFKA_HOST, brokers.get(i).socketServer().boundPort(SecurityProtocol.SASL_PLAINTEXT)) + ",";
            } else {
                brokerConnectionString += hostAndPortToUrlString(KafkaTestEnvironment.KAFKA_HOST, brokers.get(i).socketServer().boundPort(SecurityProtocol.PLAINTEXT)) + ",";
            }
        }
        LOG.info("ZK and KafkaServer started.");
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Test setup failed: " + t.getMessage());
    }
    LOG.info("brokerConnectionString --> {}", brokerConnectionString);
    standardProps = new Properties();
    standardProps.setProperty("zookeeper.connect", zookeeperConnectionString);
    standardProps.setProperty("bootstrap.servers", brokerConnectionString);
    standardProps.setProperty("group.id", "flink-tests");
    standardProps.setProperty("enable.auto.commit", "false");
    standardProps.setProperty("zookeeper.session.timeout.ms", zkTimeout);
    standardProps.setProperty("zookeeper.connection.timeout.ms", zkTimeout);
    // read from the beginning. (earliest is kafka 0.9 value)
    standardProps.setProperty("auto.offset.reset", "earliest");
    // make a lot of fetches (MESSAGES MUST BE SMALLER!)
    standardProps.setProperty("max.partition.fetch.bytes", "256");
}
Also used : TestingServer(org.apache.curator.test.TestingServer) SocketServer(kafka.network.SocketServer) Properties(java.util.Properties) File(java.io.File)

Aggregations

File (java.io.File)1 Properties (java.util.Properties)1 SocketServer (kafka.network.SocketServer)1 TestingServer (org.apache.curator.test.TestingServer)1