ClientBase.setupTestEnv();
File zkTmpDir = File.createTempFile("zookeeper", "test");
zkTmpDir.delete();
zkTmpDir.mkdir();
ZooKeeperServer zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, 2181);
NIOServerCnxnFactory serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(new InetSocketAddress(2181), 100);
serverFactory.startup(zks);
boolean b = ClientBase.waitForServerUp("127.0.0.1:2181", 5000);
ServerConfiguration serverConf = new ServerConfiguration();
serverConf.loadConf(hedwigConfigFile.toURI().toURL());
logger.info("Zookeeper server up and running!");
ZooKeeper zkc = new ZooKeeper("127.0.0.1", 2181, null);
// initialize the zk client with (fake) values
zkc.create("/ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zkc.create("/ledgers/available", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zkc.close();
PubSubServer hedwigServer = null;
try {
logger.info("starting hedwig broker!");
hedwigServer = new PubSubServer(serverConf);
hedwigServer.start();
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotNull("failed to instantiate hedwig pub sub server", hedwigServer);
hedwigServer.shutdown();
serverFactory.shutdown();
zks.shutdown();
zkTmpDir.delete();
ClientBase.waitForServerDown("localhost:2181", 10000);