org.apache.qpid.test.utils
Class QpidBrokerTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.qpid.test.utils.QpidTestCase
              extended by org.apache.qpid.test.utils.QpidBrokerTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AbstractACLTestCase, AbstractTestLogging, AbstractXATestCase, AddressBasedDestinationTest, AMQConnectionTest, AMQPEncodedMapMessageTest, AMQProtocolSessionTest, AMQQueueDeferredOrderingTest, AMQSessionTest, BytesMessageTest, CancelTest, ChannelCloseOkTest, ChannelCloseTest, CloseAfterConnectionFailureTest, CloseBeforeAckTest, CloseTest, CloseWithBlockingReceiveTest, CombinedTest, CommitRollbackTest, ConflationQueueTest, ConnectionCloseTest, ConnectionStartTest, ConnectionTest, DeepQueueConsumeWithSelector, DispatcherTest, DupsOkTest, DurableSubscriberTest, DurableSubscriptionTest, DynamicQueueExchangeCreateTest, ExceptionListenerTest, FailoverBaseCase, FieldTableMessageTest, FirewallConfigTest, FlowControlTest, FrameworkBaseCase, InvalidDestinationTest, JavaServerCloseRaceConditionTest, JMSDestinationTest, JMSPropertiesTest, LargeMessageTest, LVQTest, MapMessageTest, MessageListenerMultiConsumerTest, MessageListenerTest, MessageRequeueTest, MessageToStringTest, ModelTest, MultipleConnectionTest, MultipleJCAProviderRegistrationTest, NoLocalAfterRecoveryTest, ObjectMessageTest, ObjectMessageTest, ObjectMessageTest, PersistentStoreTest, PriorityTest, PropertyValueTest, PubSubTwoConnectionTest, QpidClientConnection, QueuePolicyTest, QuickAcking, ReceiveTest, ResetMessageListenerTest, ReturnUnroutableMandatoryMessageTest, RollbackOrderTest, SelectorTest, ServerConfigurationFileTest, SessionCreateTest, SessionStartTest, SSLTest, StreamMessageTest, SyncWaitDelayTest, TemporaryQueueTest, TestingBaseCase, TextMessageTest, TimeToLiveTest, TopicPublisherCloseTest, TopicPublisherTest, TopicSessionTest, TransactedTest, UTF8Test

public class QpidBrokerTestCase
extends org.apache.qpid.test.utils.QpidTestCase

Qpid base class for system testing test cases.


Nested Class Summary
protected static class QpidBrokerTestCase.MessageType
          Type of message
 
Field Summary
protected  String _broker
           
protected  String _brokerLanguage
           
protected static String _brokerLogPrefix
           
protected  PrintStream _brokerOutputStream
           
protected  Boolean _brokerPersistent
           
protected  Map<Integer,Process> _brokers
           
protected  File _configFile
           
protected  org.apache.qpid.client.AMQConnectionFactory _connectionFactory
           
protected  List<Connection> _connections
           
protected  InitialContext _initialContext
           
protected static boolean _interleaveBrokerLog
           
protected static org.apache.log4j.Logger _logger
           
protected  String _output
           
protected  File _outputFile
           
protected  String _testName
           
protected static String BROKER_READY
           
protected static String CONTENT
           
protected static String CPP
           
static int DEFAULT_MANAGEMENT_PORT
           
protected static int DEFAULT_MESSAGE_SIZE
          Ensure our messages have some sort of size
static int DEFAULT_PORT
           
static int DEFAULT_SSL_PORT
           
static int DEFAULT_VM_PORT
           
protected static String EXTERNAL
           
protected static String INDEX
           
protected static String JAVA
           
protected static int LOGMONITOR_TIMEOUT
           
protected static String QPID_HOME
           
protected  String QpidHome
           
static String QUEUE
           
protected  long RECEIVE_TIMEOUT
           
static String TOPIC
           
protected static String VM
           
 
Fields inherited from class org.apache.qpid.test.utils.QpidTestCase
MEMORY_STORE_CLASS_NAME, MS_CLASS_NAME_KEY
 
Constructor Summary
QpidBrokerTestCase()
           
QpidBrokerTestCase(String name)
           
 
Method Summary
 void cleanBroker()
           
 Message createMessage(Session session, int messageSize)
           
 Message createNextMessage(Session session, int msgCount)
           
protected  int drainQueue(Queue queue)
          Consume all the messages in the specified queue.
 org.apache.qpid.jms.BrokerDetails getBroker()
           
protected  String getBrokerCommand(int port)
           
 Connection getClientConnection(String username, String password, String id)
           
protected  String getConfigurationStringProperty(String property)
          Get a property value from the current configuration file.
 Connection getConnection()
           
 Connection getConnection(org.apache.qpid.jms.ConnectionURL url)
           
 Connection getConnection(String username, String password)
          Get a connection (remote or in-VM)
 org.apache.qpid.client.AMQConnectionFactory getConnectionFactory()
          Get the default connection factory for the currently used broker Default factory is "local"
 org.apache.qpid.client.AMQConnectionFactory getConnectionFactory(String factoryName)
          Get a connection factory for the currently used broker
 org.apache.qpid.jms.ConnectionURL getConnectionURL()
           
 InitialContext getInitialContext()
          we assume that the environment is correctly set i.e.
 org.apache.log4j.Logger getLogger()
           
protected  int getManagementPort(int mainPort)
          Return the management portin use by the broker on this main port
protected  int getMessageSize()
           
protected  int getPort()
          Get the Port that is use by the current broker
protected  int getPort(int port)
           
 String getTestConfigFile()
           
 Queue getTestQueue()
          Return a Queue specific for this test.
protected  String getTestQueueName()
          Return a uniqueName for this test.
 String getTestVirtualhostsFile()
           
 boolean isBroker010()
           
 boolean isBroker08()
          Check whether the broker is an 0.8
protected  boolean isBrokerStorePersistent()
           
protected  boolean isCppBroker()
           
protected  boolean isExternalBroker()
           
protected  boolean isJavaBroker()
           
protected  void makeVirtualHostPersistent(String virtualhost)
          Attempt to set the Java Broker to use the BDBMessageStore for persistence Falling back to the DerbyMessageStore if
 void reloadBrokerSecurityConfig()
          Reloads the broker security configuration using the ApplicationRegistry (InVM brokers) or the ConfigurationManagementMBean via the JMX interface (Standalone brokers, management must be enabled before calling the method).
 void restartBroker()
           
 void restartBroker(int port)
           
protected  void revertLoggingLevels()
          Restore the logging levels defined by this test.
protected  void revertSystemProperties()
          Restore the System property values that were set before this test run.
 void runBare()
           
protected  void saveTestConfiguration()
           
protected  void saveTestVirtualhosts()
           
 List<Message> sendMessage(Session session, Destination destination, int count)
          Send messages to the given destination.
 List<Message> sendMessage(Session session, Destination destination, int count, int batchSize)
          Send messages to the given destination.
 List<Message> sendMessage(Session session, Destination destination, int count, int offset, int batchSize)
          Send messages to the given destination.
protected  void setBrokerEnvironment(String property, String value)
          Add an environtmen variable for the external broker environment
protected  void setBrokerOnlySystemProperty(String property, String value)
          Set a System property that is to be applied only to the external test broker.
protected  void setConfigurationProperty(String property, String value)
          Set a configuration Property for this test run.
protected  void setLoggerLevel(org.apache.log4j.Logger logger, org.apache.log4j.Level level)
          Adjust the VMs Log4j Settings just for this test run
protected  void setMessageSize(int byteSize)
           
protected  void setSystemProperty(String property)
          Set a System (-D) property for this test run.
protected  void setSystemProperty(String property, String value)
          Set a System property for the duration of this test.
protected  void setTestClientSystemProperty(String property, String value)
          Set a System (-D) property for the external Broker of this test.
protected  void setUp()
           
 void startBroker()
           
 void startBroker(int port)
           
 void stopBroker()
           
 void stopBroker(int port)
           
protected  void tearDown()
           
 
Methods inherited from class org.apache.qpid.test.utils.QpidTestCase
, getTestProfileMessageStoreClassName, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

QpidHome

protected final String QpidHome

_configFile

protected File _configFile

_logger

protected static final org.apache.log4j.Logger _logger

LOGMONITOR_TIMEOUT

protected static final int LOGMONITOR_TIMEOUT
See Also:
Constant Field Values

RECEIVE_TIMEOUT

protected long RECEIVE_TIMEOUT

INDEX

protected static final String INDEX
See Also:
Constant Field Values

CONTENT

protected static final String CONTENT
See Also:
Constant Field Values

BROKER_READY

protected static final String BROKER_READY
See Also:
Constant Field Values

JAVA

protected static final String JAVA
See Also:
Constant Field Values

CPP

protected static final String CPP
See Also:
Constant Field Values

VM

protected static final String VM
See Also:
Constant Field Values

EXTERNAL

protected static final String EXTERNAL
See Also:
Constant Field Values

QPID_HOME

protected static final String QPID_HOME
See Also:
Constant Field Values

DEFAULT_VM_PORT

public static final int DEFAULT_VM_PORT
See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT

DEFAULT_MANAGEMENT_PORT

public static final int DEFAULT_MANAGEMENT_PORT

DEFAULT_SSL_PORT

public static final int DEFAULT_SSL_PORT

_brokerLanguage

protected String _brokerLanguage

_broker

protected String _broker

_output

protected String _output

_brokerPersistent

protected Boolean _brokerPersistent

_brokerLogPrefix

protected static String _brokerLogPrefix

_interleaveBrokerLog

protected static boolean _interleaveBrokerLog

_outputFile

protected File _outputFile

_brokerOutputStream

protected PrintStream _brokerOutputStream

_brokers

protected Map<Integer,Process> _brokers

_initialContext

protected InitialContext _initialContext

_connectionFactory

protected org.apache.qpid.client.AMQConnectionFactory _connectionFactory

_testName

protected String _testName

_connections

protected List<Connection> _connections

QUEUE

public static final String QUEUE
See Also:
Constant Field Values

TOPIC

public static final String TOPIC
See Also:
Constant Field Values

DEFAULT_MESSAGE_SIZE

protected static final int DEFAULT_MESSAGE_SIZE
Ensure our messages have some sort of size

See Also:
Constant Field Values
Constructor Detail

QpidBrokerTestCase

public QpidBrokerTestCase(String name)

QpidBrokerTestCase

public QpidBrokerTestCase()
Method Detail

getLogger

public org.apache.log4j.Logger getLogger()

runBare

public void runBare()
             throws Throwable
Overrides:
runBare in class junit.framework.TestCase
Throws:
Throwable

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception

startBroker

public void startBroker()
                 throws Exception
Throws:
Exception

getManagementPort

protected int getManagementPort(int mainPort)
Return the management portin use by the broker on this main port

Parameters:
mainPort - the broker's main port.
Returns:
the management port that corresponds to the broker on the given port

getPort

protected int getPort()
Get the Port that is use by the current broker

Returns:
the current port

getPort

protected int getPort(int port)

getBrokerCommand

protected String getBrokerCommand(int port)
                           throws MalformedURLException
Throws:
MalformedURLException

startBroker

public void startBroker(int port)
                 throws Exception
Throws:
Exception

getTestConfigFile

public String getTestConfigFile()

getTestVirtualhostsFile

public String getTestVirtualhostsFile()

saveTestConfiguration

protected void saveTestConfiguration()
                              throws ConfigurationException
Throws:
ConfigurationException

saveTestVirtualhosts

protected void saveTestVirtualhosts()
                             throws ConfigurationException
Throws:
ConfigurationException

cleanBroker

public void cleanBroker()

stopBroker

public void stopBroker()
                throws Exception
Throws:
Exception

stopBroker

public void stopBroker(int port)
                throws Exception
Throws:
Exception

makeVirtualHostPersistent

protected void makeVirtualHostPersistent(String virtualhost)
                                  throws ConfigurationException,
                                         IOException
Attempt to set the Java Broker to use the BDBMessageStore for persistence Falling back to the DerbyMessageStore if

Parameters:
virtualhost - - The virtualhost to modify
Throws:
ConfigurationException - - when reading/writing existing configuration
IOException - - When creating a temporary file.

getConfigurationStringProperty

protected String getConfigurationStringProperty(String property)
                                         throws ConfigurationException
Get a property value from the current configuration file.

Parameters:
property - the property to lookup
Returns:
the requested String Value
Throws:
ConfigurationException

setConfigurationProperty

protected void setConfigurationProperty(String property,
                                        String value)
                                 throws ConfigurationException,
                                        IOException
Set a configuration Property for this test run. This creates a new configuration based on the current configuration with the specified property change. Multiple calls to this method will result in multiple temporary configuration files being created.

Parameters:
property - the configuration property to set
value - the new value
Throws:
ConfigurationException - when loading the current config file
IOException - when writing the new config file

setBrokerOnlySystemProperty

protected void setBrokerOnlySystemProperty(String property,
                                           String value)
Set a System property that is to be applied only to the external test broker. This is a convenience method to enable the setting of a -Dproperty=value entry in QPID_OPTS This is only useful for the External Java Broker tests.

Parameters:
property - the property name
value - the value to set the property to

setSystemProperty

protected void setSystemProperty(String property)
Set a System (-D) property for this test run. This convenience method copies the current VMs System Property for the external VM Broker.

Parameters:
property - the System property to set

setSystemProperty

protected void setSystemProperty(String property,
                                 String value)
Set a System property for the duration of this test. When the test run is complete the value will be reverted. The values set using this method will also be propogated to the external Java Broker via a -D value defined in QPID_OPTS. If the value should not be set on the broker then use setTestClientSystemProperty().

Parameters:
property - the property to set
value - the new value to use

setTestClientSystemProperty

protected void setTestClientSystemProperty(String property,
                                           String value)
Set a System (-D) property for the external Broker of this test.

Parameters:
property - The property to set
value - the value to set it to.

revertSystemProperties

protected void revertSystemProperties()
Restore the System property values that were set before this test run.


setBrokerEnvironment

protected void setBrokerEnvironment(String property,
                                    String value)
Add an environtmen variable for the external broker environment

Parameters:
property - the property to set
value - the value to set it to

setLoggerLevel

protected void setLoggerLevel(org.apache.log4j.Logger logger,
                              org.apache.log4j.Level level)
Adjust the VMs Log4j Settings just for this test run

Parameters:
logger - the logger to change
level - the level to set

revertLoggingLevels

protected void revertLoggingLevels()
Restore the logging levels defined by this test.


isBroker08

public boolean isBroker08()
Check whether the broker is an 0.8

Returns:
true if the broker is an 0_8 version, false otherwise.

isBroker010

public boolean isBroker010()

isJavaBroker

protected boolean isJavaBroker()

isCppBroker

protected boolean isCppBroker()

isExternalBroker

protected boolean isExternalBroker()

isBrokerStorePersistent

protected boolean isBrokerStorePersistent()

restartBroker

public void restartBroker()
                   throws Exception
Throws:
Exception

restartBroker

public void restartBroker(int port)
                   throws Exception
Throws:
Exception

getInitialContext

public InitialContext getInitialContext()
                                 throws NamingException
we assume that the environment is correctly set i.e. -Djava.naming.provider.url="..//example010.properties" TODO should be a way of setting that through maven

Returns:
an initial context
Throws:
NamingException - if there is an error getting the context

getConnectionFactory

public org.apache.qpid.client.AMQConnectionFactory getConnectionFactory()
                                                                 throws NamingException
Get the default connection factory for the currently used broker Default factory is "local"

Returns:
A conection factory
Throws:
Exception - if there is an error getting the tactory
NamingException

getConnectionFactory

public org.apache.qpid.client.AMQConnectionFactory getConnectionFactory(String factoryName)
                                                                 throws NamingException
Get a connection factory for the currently used broker

Parameters:
factoryName - The factory name
Returns:
A conection factory
Throws:
Exception - if there is an error getting the tactory
NamingException

getConnection

public Connection getConnection()
                         throws JMSException,
                                NamingException
Throws:
JMSException
NamingException

getConnection

public Connection getConnection(org.apache.qpid.jms.ConnectionURL url)
                         throws JMSException
Throws:
JMSException

getConnection

public Connection getConnection(String username,
                                String password)
                         throws JMSException,
                                NamingException
Get a connection (remote or in-VM)

Parameters:
username - The user name
password - The user password
Returns:
a newly created connection
Throws:
Exception - if there is an error getting the connection
JMSException
NamingException

getClientConnection

public Connection getClientConnection(String username,
                                      String password,
                                      String id)
                               throws JMSException,
                                      org.apache.qpid.url.URLSyntaxException,
                                      org.apache.qpid.AMQException,
                                      NamingException
Throws:
JMSException
org.apache.qpid.url.URLSyntaxException
org.apache.qpid.AMQException
NamingException

getTestQueueName

protected String getTestQueueName()
Return a uniqueName for this test. In this case it returns a queue Named by the TestCase and TestName

Returns:
String name for a queue

getTestQueue

public Queue getTestQueue()
Return a Queue specific for this test. Uses getTestQueueName() as the name of the queue

Returns:

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

drainQueue

protected int drainQueue(Queue queue)
                  throws Exception
Consume all the messages in the specified queue. Helper to ensure persistent tests don't leave data behind.

Parameters:
queue - the queue to purge
Returns:
the count of messages drained
Throws:
Exception - if a problem occurs

sendMessage

public List<Message> sendMessage(Session session,
                                 Destination destination,
                                 int count)
                          throws Exception
Send messages to the given destination. If session is transacted then messages will be commited before returning

Parameters:
session - the session to use for sending
destination - where to send them to
count - no. of messages to send
Returns:
the sent messges
Throws:
Exception

sendMessage

public List<Message> sendMessage(Session session,
                                 Destination destination,
                                 int count,
                                 int batchSize)
                          throws Exception
Send messages to the given destination. If session is transacted then messages will be commited before returning

Parameters:
session - the session to use for sending
destination - where to send them to
count - no. of messages to send
batchSize - the batchSize in which to commit, 0 means no batching, but a single commit at the end
Returns:
the sent messgse
Throws:
Exception

sendMessage

public List<Message> sendMessage(Session session,
                                 Destination destination,
                                 int count,
                                 int offset,
                                 int batchSize)
                          throws Exception
Send messages to the given destination. If session is transacted then messages will be commited before returning

Parameters:
session - the session to use for sending
destination - where to send them to
count - no. of messages to send
offset - offset allows the INDEX value of the message to be adjusted.
batchSize - the batchSize in which to commit, 0 means no batching, but a single commit at the end
Returns:
the sent messgse
Throws:
Exception

createNextMessage

public Message createNextMessage(Session session,
                                 int msgCount)
                          throws JMSException
Throws:
JMSException

createMessage

public Message createMessage(Session session,
                             int messageSize)
                      throws JMSException
Throws:
JMSException

getMessageSize

protected int getMessageSize()

setMessageSize

protected void setMessageSize(int byteSize)

getConnectionURL

public org.apache.qpid.jms.ConnectionURL getConnectionURL()
                                                   throws NamingException
Throws:
NamingException

getBroker

public org.apache.qpid.jms.BrokerDetails getBroker()

reloadBrokerSecurityConfig

public void reloadBrokerSecurityConfig()
                                throws Exception
Reloads the broker security configuration using the ApplicationRegistry (InVM brokers) or the ConfigurationManagementMBean via the JMX interface (Standalone brokers, management must be enabled before calling the method).

Throws:
Exception


Licensed to the Apache Software Foundation