是否可以在进程中启动 zookeeper 服务器实例,例如用于单元测试? [英] Is it possible to start a zookeeper server instance in process, say for unit tests?

查看:20
本文介绍了是否可以在进程中启动 zookeeper 服务器实例,例如用于单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用 org.apache.zookeeper.server.quorum.QuorumPeerMain.main() 不起作用.

Calling org.apache.zookeeper.server.quorum.QuorumPeerMain.main() isn't working.

推荐答案

要启动 ZooKeeper,您必须执行 ZooKeeperServerMain 类.

To start ZooKeeper you have to execute ZooKeeperServerMain class.

您可以使用以下代码以嵌入模式启动 ZooKeeper.

You can use following code to start ZooKeeper in embedded mode.

Properties startupProperties = ...

QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
    quorumConfiguration.parseProperties(startupProperties);
} catch(Exception e) {
    throw new RuntimeException(e);
}

zooKeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);

new Thread() {
    public void run() {
        try {
            zooKeeperServer.runFromConfig(configuration);
        } catch (IOException e) {
            log.error("ZooKeeper Failed", e);
        }
    }
}.start();

这篇关于是否可以在进程中启动 zookeeper 服务器实例,例如用于单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆