【问题标题】:embedded zookeeper for unit/integration test用于单元/集成测试的嵌入式 Zookeeper
【发布时间】:2012-12-13 11:29:32
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    Curator 框架具有 TestingServer 和 TestingCluster 类(请参阅 https://github.com/Netflix/curator/wiki/Utilities),它们位于单独的 Maven 工件(curator-test - 请参阅 https://github.com/Netflix/curator/wiki 的 Maven/Artifacts 部分)中。

    它们很容易解释,或者您可以下载 curator 代码库,看看它们是如何在自己的测试用例内部使用的。

    我们已经在 $DAY_JOB 的单元测试中成功使用了这两种方法。

    【讨论】:

    • Curator 测试服务器也可以在没有 Curator 客户端的情况下工作(直接使用 Zookeper 客户端)!
    【解决方案2】:

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

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

    您可以按如下方式在进程中创建 Zookeeper 服务器

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

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

    【讨论】:

      【解决方案3】:

      您可以使用zookeeper-maven-plugin,记录在here

      【讨论】:

        【解决方案4】:

        zookeeper 项目会生成一个“fat-jar”,用于系统测试。

        有一个书面的README,显示它是多么容易启动,但不幸的是它不是作为工件制作的,因此无法链接到maven。

        【讨论】:

          猜你喜欢
          • 2011-08-19
          • 2017-02-17
          • 1970-01-01
          • 2011-02-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多