embedded zookeeper for unit/integration test

后端 未结 4 991
我寻月下人不归
我寻月下人不归 2021-02-07 10:56

Is there an embedded zookeeper so that we could use it in unit testing? It can be shipped with the test and run out of the box. Maybe we could mock some service and register to

4条回答
  •  情歌与酒
    2021-02-07 11:33

    You could use Apache Curator Utilities provided in-process ZooKeeper server TestingServer that can be used for testing. With maven you can dependency as follows

        
            org.apache.curator
            curator-test
            3.2.1
        
    

    And you can create in process zookeeper server as folows

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

    For testing Cluster use can use TestingCluster, which creates an internally running ensemble of ZooKeeper servers

提交回复
热议问题