Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

embedded zookeeper for unit/integration test

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 the embedded zookeeper

like image 867
blue123 Avatar asked Dec 28 '12 06:12

blue123


2 Answers

The Curator framework has TestingServer and TestingCluster classes (see https://github.com/Netflix/curator/wiki/Utilities) that are in a separate maven artifact (curator-test - see the Maven/Artifacts section of https://github.com/Netflix/curator/wiki).

They're pretty self explanatory, or you can download the curator code base and see how they're used internally in their own test cases.

We've used both successfully within unit tests at $DAY_JOB.

like image 65
GamingBuck Avatar answered Nov 10 '22 23:11

GamingBuck


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

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

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

like image 29
ravthiru Avatar answered Nov 10 '22 22:11

ravthiru