Class MiniZooKeeperCluster
java.lang.Object
org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster
TODO: Most of the code in this class is ripped from ZooKeeper tests. Instead of redoing it, we
should contribute updates to their code which let us more easily access testing helper objects.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final org.apache.hadoop.conf.Configurationprivate intprivate static final intprivate intThe default port.static final Stringprivate static final org.slf4j.Loggerstatic final Stringprivate final List<org.apache.zookeeper.server.NIOServerCnxnFactory>private booleanprivate static final intprivate intprivate static final intprivate final List<org.apache.zookeeper.server.ZooKeeperServer> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientPort(int clientPort) Add a client port to the list.private voidReturns Address for this cluster instance.intintGet the list of client ports.private StringgetServerConfigurationOnOneLine(org.apache.zookeeper.server.ZooKeeperServer server) int(package private) List<org.apache.zookeeper.server.ZooKeeperServer>private booleanhasValidClientPortInList(int index) Check whether the client port in a specific position of the client port list is valid.intvoidKill one back up ZK servers.private intselectClientPort(int seedPort) Selects a ZK client port.voidsetDefaultClientPort(int clientPort) voidsetTickTime(int tickTime) private static voidvoidshutdown()intintprivate static booleanwaitForServerDown(int port, long timeout) private static booleanwaitForServerUp(int port, long timeout)
-
Field Details
-
LOG
-
TICK_TIME
- See Also:
-
TIMEOUT
- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
- See Also:
-
connectionTimeout
-
LOOPBACK_HOST
-
HOST
-
started
-
defaultClientPort
The default port. If zero, we use a random port. -
standaloneServerFactoryList
-
zooKeeperServers
-
clientPortList
-
activeZKServerIndex
-
tickTime
-
configuration
-
-
Constructor Details
-
MiniZooKeeperCluster
public MiniZooKeeperCluster() -
MiniZooKeeperCluster
-
-
Method Details
-
addClientPort
Add a client port to the list.- Parameters:
clientPort- the specified port
-
getClientPortList
Get the list of client ports.- Returns:
- clientPortList the client port list
-
hasValidClientPortInList
Check whether the client port in a specific position of the client port list is valid.- Parameters:
index- the specified position
-
setDefaultClientPort
-
selectClientPort
Selects a ZK client port.- Parameters:
seedPort- the seed port to start with; -1 means first time.- Returns:
- a valid and unused client port
-
setTickTime
-
getBackupZooKeeperServerNum
-
getZooKeeperServerNum
-
setupTestEnv
-
startup
- Throws:
IOExceptionInterruptedException
-
startup
- Parameters:
baseDir- the base directory to usenumZooKeeperServers- the number of ZooKeeper servers- Returns:
- ClientPort server bound to, -1 if there was a binding problem and we couldn't pick another port.
- Throws:
IOException- if an operation fails during the startupInterruptedException- if the startup fails
-
getServerConfigurationOnOneLine
-
createDir
- Throws:
IOException
-
shutdown
- Throws:
IOException- if waiting for the shutdown of a server fails
-
killCurrentActiveZooKeeperServer
- Returns:
- clientPort return clientPort if there is another ZK backup can run when killing the current active; return -1, if there is no backups.
- Throws:
IOException- if waiting for the shutdown of a server failsInterruptedException
-
killOneBackupZooKeeperServer
Kill one back up ZK servers.- Throws:
IOException- if waiting for the shutdown of a server failsInterruptedException
-
waitForServerDown
- Throws:
IOException
-
waitForServerUp
- Throws:
IOException
-
getClientPort
-
getAddress
Returns Address for this cluster instance. -
getZooKeeperServers
List<org.apache.zookeeper.server.ZooKeeperServer> getZooKeeperServers()
-