public class ClusterTestSupport extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ClusterTestSupport.TestDirectoryFilenameFilter
TestDirectoryFilenameFilter provides a file name filter to locate test
directories left behind.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
The default MongoDB port.
|
static String |
DIR_SUFFIX
The suffix for the test directories.
|
static String |
REPLICA_SET_ROOT
The prefix for replica set test directories.
|
static String |
SHARDED_ROOT
The prefix for sharded test directories.
|
static String |
STANDALONE_ROOT
The prefix for standalone test directories.
|
Constructor and Description |
---|
ClusterTestSupport()
Creates a new ClusterTestSupport.
|
Modifier and Type | Method and Description |
---|---|
void |
delete(File file)
Deletes the files.
|
protected void |
fail(String message)
Fails with the message and exception.
|
protected void |
fail(String message,
Throwable cause)
Fails with the message and exception.
|
void |
repairReplicaSet()
Repairs a MongoDB instance running in a replica set mode.
|
protected void |
repairReplicaSet(File workingDirectory,
int startPort,
int replicas)
Repairs a replica set on the specified start port.
|
ManagedProcess |
run(File workingDirectory,
String executable,
String... args)
Runs a process and returns the merged stderr and stdout.
|
protected void |
sleep(long millis)
Sleeps for the specified number of milliseconds.
|
void |
startReplicaSet()
Starts a MongoDB instance running in a replica set mode.
|
protected void |
startReplicaSet(File workingDirectory,
int startPort,
int replicas)
Starts a replica set on the specified start port.
|
void |
startSharded()
Starts a MongoDB instance running in a sharded mode.
|
protected void |
startSharded(File workingDirectory,
int startPort,
int mongos,
int shards)
Starts a sharded cluster on the specified start port.
|
void |
startShardedReplicaSets()
Starts a MongoDB instance running in a sharded mode.
|
protected void |
startShardedReplicaSets(File workingDirectory,
int startPort,
int mongos,
int shards)
Starts a sharded cluster on the specified start port.
|
void |
startStandAlone()
Starts a MongoDB instance running in a standalone mode.
|
protected void |
startStandAlone(File workingDirectory,
int port)
Starts a mongod on the specified port.
|
void |
stopAll()
Stops all of the running processes for the cluster.
|
protected void |
waitFor(File log,
int port,
long waitMs)
Waits for the log file to contain the standard message that mongod is
waiting on the specified port.
|
protected void |
waitFor(File log,
String token,
int count,
long waitMs)
Waits for the log file to contain the specified token
count
times. |
protected void |
waitFor(File log,
String token,
long waitMs)
Waits for the log file to contain the specified token.
|
public static final int DEFAULT_PORT
public static final String DIR_SUFFIX
public static final String REPLICA_SET_ROOT
public static final String SHARDED_ROOT
public static final String STANDALONE_ROOT
public void delete(File file)
file
- The file to delete. Will delete all sub directories and files
if a directory.public void repairReplicaSet()
public ManagedProcess run(File workingDirectory, String executable, String... args) throws AssertionError
workingDirectory
- The working directory for the executable.executable
- The program to run.args
- The arguments to the executable.AssertionError
- On a failure to launch the executable.public void startReplicaSet()
public void startSharded()
public void startShardedReplicaSets()
public void startStandAlone()
public void stopAll()
protected void fail(String message) throws AssertionError
message
- The failure message.AssertionError
- Always.protected void fail(String message, Throwable cause) throws AssertionError
message
- The failure message.cause
- The failure cause.AssertionError
- Always.protected void repairReplicaSet(File workingDirectory, int startPort, int replicas) throws AssertionError
workingDirectory
- The work directory for the replica set.startPort
- The starting port for the replica set.replicas
- The number of replicas in the replica set.AssertionError
- On a failure starting the replica set.protected void sleep(long millis)
millis
- The number of milliseconds to sleep.protected void startReplicaSet(File workingDirectory, int startPort, int replicas) throws AssertionError
workingDirectory
- The work directory for the replica set.startPort
- The starting port for the replica set.replicas
- The number of replicas in the replica set.AssertionError
- On a failure starting the replica set.protected void startSharded(File workingDirectory, int startPort, int mongos, int shards) throws AssertionError
workingDirectory
- The work directory for the shards.startPort
- The starting port for the shards.mongos
- The number of mongos servers to start.shards
- The number of shards to start.AssertionError
- On a failure starting the cluster.protected void startShardedReplicaSets(File workingDirectory, int startPort, int mongos, int shards) throws AssertionError
workingDirectory
- The work directory for the shards.startPort
- The starting port for the shards.mongos
- The number of mongos servers to start.shards
- The number of shards to start.AssertionError
- On a failure starting the cluster.protected void startStandAlone(File workingDirectory, int port) throws AssertionError
workingDirectory
- The work directory for the mongod.port
- The port for the mongod.AssertionError
- On a failure starting the cluster.protected void waitFor(File log, int port, long waitMs)
log
- The log file to scan.port
- The port to search for.waitMs
- How long to wait before giving up.protected void waitFor(File log, String token, int count, long waitMs)
count
times.log
- The log file to scan.token
- The token to search for.count
- The number of instances of the token to find.waitMs
- How long to wait before giving up.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.