嵌入式zookeeper用于单元/集成测试

时间:2012-12-28 06:18:26

标签: unit-testing integration-testing apache-zookeeper

是否有嵌入式zookeeper,以便我们可以在单元测试中使用它?它可以与测试一起发货,并且开箱即用。也许我们可以模拟一些服务并注册到嵌入式zookeeper

4 个答案:

答案 0 :(得分:21)

Curator框架具有TestingServer和TestingCluster类(请参阅https://github.com/Netflix/curator/wiki/Utilities),这些类位于单独的maven工件中(策展人测试 - 请参阅https://github.com/Netflix/curator/wiki的Maven / Artifacts部分)。 / p>

他们非常自我解释,或者您可以下载策展人代码库,看看他们如何在自己的测试用例中内部使用。

我们在$ DAY_JOB的单元测试中成功使用了两者。

答案 1 :(得分:14)

您可以使用可用于测试的进程内ZooKeeper服务器TestingServer中提供的Apache Curator Utilities。 使用maven,您可以依赖以下

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-test</artifactId>
        <version>3.2.1</version>
    </dependency>

您可以在进程zookeeper服务器中创建folows

 TestingServer zkServer;

  @Before
  public void setUp() throws Exception
  {
    zkServer = new TestingServer(2181, true);
  }

  @After
  public void tearDown() throws Exception
  {
    zkServer.stop();
  }

对于测试群集使用可以使用TestingCluster,这将创建一个内部运行的ZooKeeper服务器集合

答案 2 :(得分:0)

您可以使用记录为zookeeper-maven-pluginhere

答案 3 :(得分:0)

动物园管理员项目生产一个&#34;胖罐&#34;它用于系统测试。

有一篇文章README,显示了它的启动有多容易,但遗憾的是它不是作为工件制作的,因此无法链接到maven。

相关问题