@InterfaceAudience.Private public abstract class HBaseCluster extends Object implements Closeable
HBaseCluster unifies the way tests interact with the cluster, so that the same test can be run against a mini-cluster during unit test execution, or a distributed cluster having tens/hundreds of nodes during execution of integration tests.
HBaseCluster exposes client-side public interfaces to tests, so that tests does not assume running in a particular mode. Not all the tests are suitable to be run on an actual cluster, and some tests will still need to mock stuff and introspect internal state. For those use cases from unit tests, or if more control is needed, you can use the subclasses directly. In that sense, this class does not abstract away every interface that MiniHBaseCluster or DistributedHBaseCluster provide.
Modifier and Type | Field and Description |
---|---|
protected Configuration |
conf |
protected ClusterStatus |
initialClusterStatus
the status of the cluster before we begin
|
Constructor and Description |
---|
HBaseCluster(Configuration conf)
Construct an HBaseCluster
|
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Closes all the resources held open for this cluster.
|
abstract AdminProtos.AdminService.BlockingInterface |
getAdminProtocol(ServerName serverName)
Returns an AdminProtocol interface to the regionserver
|
abstract ClientProtos.ClientService.BlockingInterface |
getClientProtocol(ServerName serverName)
Returns a ClientProtocol interface to the regionserver
|
abstract ClusterStatus |
getClusterStatus()
Returns a ClusterStatus for this HBase cluster.
|
Configuration |
getConf() |
ClusterStatus |
getInitialClusterStatus()
Returns a ClusterStatus for this HBase cluster as observed at the
starting of the HBaseCluster
|
abstract MasterProtos.MasterService.BlockingInterface |
getMasterAdminService()
Returns an
MasterService.BlockingInterface to the active master |
ServerName |
getServerHoldingMeta()
Get the ServerName of region server serving the first hbase:meta region
|
abstract ServerName |
getServerHoldingRegion(TableName tn,
byte[] regionName)
Get the ServerName of region server serving the specified region
|
boolean |
isDistributedCluster() |
abstract void |
killMaster(ServerName serverName)
Kills the master process if this is a distributed cluster, otherwise,
this causes master to exit doing basic clean up only.
|
abstract void |
killRegionServer(ServerName serverName)
Kills the region server process if this is a distributed cluster, otherwise
this causes the region server to exit doing basic clean up only.
|
boolean |
restoreClusterStatus(ClusterStatus desiredStatus)
Restores the cluster to given state if this is a real cluster,
otherwise does nothing.
|
boolean |
restoreInitialStatus()
Restores the cluster to it's initial state if this is a real cluster,
otherwise does nothing.
|
void |
setConf(Configuration conf) |
abstract void |
shutdown()
Shut down the HBase cluster
|
abstract void |
startMaster(String hostname,
int port)
Starts a new master on the given hostname or if this is a mini/local cluster,
starts a master locally.
|
abstract void |
startRegionServer(String hostname,
int port)
Starts a new region server on the given hostname or if this is a mini/local cluster,
starts a region server locally.
|
abstract void |
stopMaster(ServerName serverName)
Stops the given master, by attempting a gradual stop.
|
abstract void |
stopRegionServer(ServerName serverName)
Stops the given region server, by attempting a gradual stop.
|
boolean |
waitForActiveAndReadyMaster()
Blocks until there is an active master and that master has completed
initialization.
|
abstract boolean |
waitForActiveAndReadyMaster(long timeout)
Blocks until there is an active master and that master has completed
initialization.
|
void |
waitForDatanodesRegistered(int nbDN) |
abstract void |
waitForMasterToStop(ServerName serverName,
long timeout)
Wait for the specified master to stop the thread / process.
|
void |
waitForNamenodeAvailable()
Wait for the namenode.
|
void |
waitForRegionServerToStart(String hostname,
int port,
long timeout)
Wait for the specified region server to join the cluster
|
abstract void |
waitForRegionServerToStop(ServerName serverName,
long timeout)
Wait for the specified region server to stop the thread / process.
|
abstract void |
waitUntilShutDown()
Wait for HBase Cluster to shut down.
|
protected Configuration conf
protected ClusterStatus initialClusterStatus
public HBaseCluster(Configuration conf)
conf
- Configuration to be used for clusterpublic void setConf(Configuration conf)
public Configuration getConf()
public abstract ClusterStatus getClusterStatus() throws IOException
IOException
getInitialClusterStatus()
public ClusterStatus getInitialClusterStatus() throws IOException
IOException
public abstract MasterProtos.MasterService.BlockingInterface getMasterAdminService() throws IOException
MasterService.BlockingInterface
to the active masterIOException
public abstract AdminProtos.AdminService.BlockingInterface getAdminProtocol(ServerName serverName) throws IOException
IOException
public abstract ClientProtos.ClientService.BlockingInterface getClientProtocol(ServerName serverName) throws IOException
IOException
public abstract void startRegionServer(String hostname, int port) throws IOException
hostname
- the hostname to start the regionserver onIOException
- if something goes wrongpublic abstract void killRegionServer(ServerName serverName) throws IOException
IOException
- if something goes wrongpublic abstract void stopRegionServer(ServerName serverName) throws IOException
IOException
- if something goes wrongpublic void waitForRegionServerToStart(String hostname, int port, long timeout) throws IOException
IOException
- if something goes wrong or timeout occurspublic abstract void waitForRegionServerToStop(ServerName serverName, long timeout) throws IOException
IOException
- if something goes wrong or timeout occurspublic abstract void startMaster(String hostname, int port) throws IOException
hostname
- the hostname to start the master onIOException
- if something goes wrongpublic abstract void killMaster(ServerName serverName) throws IOException
IOException
- if something goes wrongpublic abstract void stopMaster(ServerName serverName) throws IOException
IOException
- if something goes wrongpublic abstract void waitForMasterToStop(ServerName serverName, long timeout) throws IOException
IOException
- if something goes wrong or timeout occurspublic boolean waitForActiveAndReadyMaster() throws IOException
IOException
- if something goes wrong or timeout occurspublic abstract boolean waitForActiveAndReadyMaster(long timeout) throws IOException
timeout
- the timeout limit in msIOException
public abstract void waitUntilShutDown() throws IOException
IOException
public abstract void shutdown() throws IOException
IOException
public boolean restoreInitialStatus() throws IOException
IOException
public boolean restoreClusterStatus(ClusterStatus desiredStatus) throws IOException
IOException
public ServerName getServerHoldingMeta() throws IOException
IOException
public abstract ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException
regionName
- Name of the region in bytestn
- Table name that has the region.IOException
public boolean isDistributedCluster()
public abstract void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
shutdown()
public void waitForNamenodeAvailable() throws InterruptedException
InterruptedException