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

blu*_*123 14 integration-testing unit-testing apache-zookeeper

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

Gam*_*uck 21

馆长框架有TestingServer和TestingCluster类(参见https://github.com/Netflix/curator/wiki/Utilities),其是在一个单独的行家伪影(馆长测试-看到的Maven的/伪影部分的https:// github上.com/Netflix/curator/wiki).

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

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


rav*_*iru 15

您可以使用可用于测试的进程内ZooKeeper服务器中提供的Apache Curator UtilitiesTestingServer.有了maven可以依赖项如下

    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-test</artifactId>
        <version>3.2.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

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

 TestingServer zkServer;

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

  @After
  public void tearDown() throws Exception
  {
    zkServer.stop();
  }
Run Code Online (Sandbox Code Playgroud)

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