javaunit-testingapache-zookeeperjunit5

How to avoid "RuntimeException: My id 0 not in the peer list" when starting embedded Zookeeper?


I'm trying to start a zookeeper node with QuorumPeerMain.runFromConfig in a BeforeAll method so that I can use it in tests (it's embedded in the same JVM). I'm getting Invalid configuration, only one server specified (ignoring) followed by java.lang.RuntimeException: My id 0 not in the peer list.

My config is:

dataDir=/tmp/zookeeper
clientPort=2181
maxClientCnxns=0
server.0=127.0.0.1:2888:3888

That last line, which should reference the node itself, is getting discarded after the "Invalid configuration" error message, and then later zookeeper throws an Exception because its id is not in the list. Its id, 0, would have been in the list if zookeeper hadn't just discarded it. How can I avoid this RuntimeException?

Or, is there a better way to run zookeeper from a BeforeAll?


Solution

  • As indicated in the configuration, the ID must be unique and between 1 and 255. You have set an ID of 0 that is not in this set, which causes this error.

    Documentation: https://zookeeper.apache.org/doc/r3.1.2/zookeeperAdmin.html#sc_zkMulitServerSetup