Search in sources :

Example 11 with TestingServer

use of org.apache.curator.test.TestingServer 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)

Example 12 with TestingServer

use of org.apache.curator.test.TestingServer in project chassis by Kixeye.

the class DynamicZookeeperConfigurationSourceTest method beforeClass.

@Before
public void beforeClass() throws Exception {
    zookeeper = new TestingServer(SocketUtils.findAvailableTcpPort());
    curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), new RetryOneTime(1000));
    curatorFramework.start();
    curatorFramework.create().forPath(CONFIG_BASE_PATH);
    Map<String, Object> defaults = new HashMap<>();
    defaults.put(DEF_KEY1, DEF_VAL1);
    defaults.put(DEF_KEY2, DEF_VAL2);
    defaultConfiguration = new MapConfiguration(defaults);
    node = UUID.randomUUID().toString();
    config = new ConcurrentCompositeConfiguration();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryOneTime(org.apache.curator.retry.RetryOneTime) HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Before(org.junit.Before)

Example 13 with TestingServer

use of org.apache.curator.test.TestingServer in project drill by apache.

the class TestEphemeralStore method setUp.

@Before
public void setUp() throws Exception {
    server = new TestingServer();
    final RetryPolicy policy = new RetryNTimes(2, 1000);
    curator = CuratorFrameworkFactory.newClient(server.getConnectString(), policy);
    config = Mockito.mock(TransientStoreConfig.class);
    Mockito.when(config.getName()).thenReturn(root);
    Mockito.when(config.getSerializer()).thenReturn(new InstanceSerializer<String>() {

        @Override
        public byte[] serialize(final String instance) throws IOException {
            if (instance == null) {
                return null;
            }
            return instance.getBytes();
        }

        @Override
        public String deserialize(final byte[] raw) throws IOException {
            if (raw == null) {
                return null;
            }
            return new String(raw);
        }
    });
    store = new ZkEphemeralStore<>(config, curator);
    server.start();
    curator.start();
    store.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryNTimes(org.apache.curator.retry.RetryNTimes) TransientStoreConfig(org.apache.drill.exec.coord.store.TransientStoreConfig) IOException(java.io.IOException) RetryPolicy(org.apache.curator.RetryPolicy) Before(org.junit.Before)

Example 14 with TestingServer

use of org.apache.curator.test.TestingServer in project heron by twitter.

the class DynamicBrokersReaderTest method setUp.

@Before
public void setUp() throws Exception {
    server = new TestingServer();
    String connectionString = server.getConnectString();
    Map<String, Object> conf = new HashMap<>();
    conf.put(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT, 1000);
    conf.put(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT, 1000);
    conf.put(Config.STORM_ZOOKEEPER_RETRY_TIMES, 4);
    conf.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL, 5);
    ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
    zookeeper = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
    dynamicBrokersReader = new DynamicBrokersReader(conf, connectionString, masterPath, topic);
    Map<String, Object> conf2 = new HashMap<>();
    conf2.putAll(conf);
    conf2.put("kafka.topic.wildcard.match", true);
    wildCardBrokerReader = new DynamicBrokersReader(conf2, connectionString, masterPath, "^test.*$");
    zookeeper.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) HashMap(java.util.HashMap) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Before(org.junit.Before)

Example 15 with TestingServer

use of org.apache.curator.test.TestingServer in project hadoop by apache.

the class TestZKRMStateStoreZKClientConnections method setupZKServer.

@Before
public void setupZKServer() throws Exception {
    testingServer = new TestingServer();
    testingServer.start();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) Before(org.junit.Before)

Aggregations

TestingServer (org.apache.curator.test.TestingServer)42 Before (org.junit.Before)17 Test (org.junit.Test)7 File (java.io.File)6 RetryOneTime (org.apache.curator.retry.RetryOneTime)6 BeforeClass (org.junit.BeforeClass)6 IOException (java.io.IOException)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)5 HashMap (java.util.HashMap)4 Configuration (org.apache.hadoop.conf.Configuration)4 Properties (java.util.Properties)3 ActorSystem (akka.actor.ActorSystem)2 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 SimpleConsumer (kafka.javaapi.consumer.SimpleConsumer)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2