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