public final class BrokerRunningSupport extends Object
If you wish to enforce the broker being available, for example, on a CI server,
set the environment variable "RABBITMQ_SERVER_REQUIRED" to true
and the
tests will fail fast.
Modifier and Type | Class and Description |
---|---|
static class |
BrokerRunningSupport.BrokerNotAliveException
The
RuntimeException thrown when broker is not available
on the provided host port. |
Modifier and Type | Field and Description |
---|---|
static String |
BROKER_ADMIN_PW |
static String |
BROKER_ADMIN_URI |
static String |
BROKER_ADMIN_USER |
static String |
BROKER_HOSTNAME |
static String |
BROKER_PORT |
static String |
BROKER_PW |
static String |
BROKER_REQUIRED |
static String |
BROKER_USER |
static String |
DEFAULT_QUEUE_NAME |
Modifier and Type | Method and Description |
---|---|
static void |
clearEnvironmentVariableOverrides()
Clear any environment variable overrides set in
setEnvironmentVariableOverrides(Map) . |
void |
deleteExchanges(String... exchanges)
Delete arbitrary exchanges from the broker.
|
void |
deleteQueues(String... queuesToDelete)
Delete arbitrary queues from the broker.
|
static boolean |
fatal() |
String |
generateId()
Generate the connection id for the connection used by the rule's
connection factory.
|
String |
getAdminPassword()
Return the admin password.
|
String |
getAdminUri()
Return the admin uri.
|
String |
getAdminUser()
Return the admin user.
|
com.rabbitmq.client.ConnectionFactory |
getConnectionFactory()
Get the connection factory used by this rule.
|
String |
getHostName()
Return the port.
|
String |
getPassword()
Return the password.
|
int |
getPort()
Return the port.
|
String |
getUser()
Return the user.
|
static BrokerRunningSupport |
isBrokerAndManagementRunning() |
static BrokerRunningSupport |
isBrokerAndManagementRunningWithEmptyQueues(String... queues) |
static BrokerRunningSupport |
isNotRunning() |
boolean |
isPurgeAfterEach() |
static BrokerRunningSupport |
isRunning() |
static BrokerRunningSupport |
isRunningWithEmptyQueues(String... names)
Ensure the broker is running and has a empty queue(s) with the specified name(s) in the
default exchange.
|
void |
purgeTestQueues()
Delete and re-declare all the configured queues.
|
void |
removeTestQueues(String... additionalQueues)
Remove any test queues that were created by an
isRunningWithEmptyQueues(String...) method. |
void |
setAdminPassword(String password)
Set the password for the management REST API connection default "guest".
|
void |
setAdminUri(String adminUri)
Set the uri for the REST API.
|
void |
setAdminUser(String user)
Set the user for the management REST API connection default "guest".
|
static void |
setEnvironmentVariableOverrides(Map<String,String> environmentVariables)
Set environment variable overrides for host, port etc.
|
void |
setHostName(String hostName) |
void |
setPassword(String password)
Set the password for the amqp connection default "guest".
|
void |
setPort(int port) |
void |
setPurgeAfterEach(boolean purgeAfterEach)
Purge the test queues after each test (JUnit 5).
|
void |
setUser(String user)
Set the user for the amqp connection default "guest".
|
void |
test() |
public static final String BROKER_ADMIN_URI
public static final String BROKER_HOSTNAME
public static final String BROKER_PORT
public static final String BROKER_USER
public static final String BROKER_PW
public static final String BROKER_ADMIN_USER
public static final String BROKER_ADMIN_PW
public static final String BROKER_REQUIRED
public static final String DEFAULT_QUEUE_NAME
public static void setEnvironmentVariableOverrides(Map<String,String> environmentVariables)
The variables will only apply to rule instances that are created after this method is called. The overrides will remain until
environmentVariables
- the variables.public static void clearEnvironmentVariableOverrides()
setEnvironmentVariableOverrides(Map)
.public static BrokerRunningSupport isRunningWithEmptyQueues(String... names)
names
- the queues to declare for the test.public static BrokerRunningSupport isRunning()
public static BrokerRunningSupport isNotRunning()
public static BrokerRunningSupport isBrokerAndManagementRunning()
public static BrokerRunningSupport isBrokerAndManagementRunningWithEmptyQueues(String... queues)
queues
- the queues.public void setPort(int port)
port
- the port to setpublic void setHostName(String hostName)
hostName
- the hostName to setpublic void setUser(String user)
user
- the user.public void setPassword(String password)
password
- the password.public void setAdminUri(String adminUri)
adminUri
- the uri.public void setAdminUser(String user)
user
- the user.public void setAdminPassword(String password)
password
- the password.public int getPort()
public String getHostName()
public String getUser()
public String getPassword()
public String getAdminUser()
public String getAdminPassword()
public boolean isPurgeAfterEach()
public void setPurgeAfterEach(boolean purgeAfterEach)
purgeAfterEach
- true to purge.public void test()
public static boolean fatal()
public String generateId()
public void removeTestQueues(String... additionalQueues)
isRunningWithEmptyQueues(String...)
method.additionalQueues
- additional queues to remove that might have been created by
tests.public void purgeTestQueues()
public void deleteQueues(String... queuesToDelete)
queuesToDelete
- the queues to delete.public void deleteExchanges(String... exchanges)
exchanges
- the exchanges to delete.public com.rabbitmq.client.ConnectionFactory getConnectionFactory()
public String getAdminUri()