org.apache.qpid.test.unit.ack
Class AcknowledgeOnMessageTest

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
                  extended by org.apache.qpid.test.utils.FailoverBaseCase
                      extended by org.apache.qpid.test.unit.ack.AcknowledgeTest
                          extended by org.apache.qpid.test.unit.ack.AcknowledgeOnMessageTest
All Implemented Interfaces:
MessageListener, junit.framework.Test
Direct Known Subclasses:
AcknowledgeAfterFailoverOnMessageTest

public class AcknowledgeOnMessageTest
extends AcknowledgeTest
implements MessageListener

This test extends the synchronous AcknowledgeTest to use a MessageListener and receive messages asynchronously.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
QpidBrokerTestCase.MessageType
 
Field Summary
protected  AtomicReference<Exception> _causeOfFailure
           
protected  CountDownLatch _receivedAll
           
 
Fields inherited from class org.apache.qpid.test.unit.ack.AcknowledgeTest
_connection, _consumer, _consumerSession, _producer, _queue, NUM_MESSAGES
 
Fields inherited from class org.apache.qpid.test.utils.FailoverBaseCase
_logger, DEFAULT_FAILOVER_TIME, FAILING_PORT, FAILING_VM_PORT, failingPort
 
Fields inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
_broker, _brokerLanguage, _brokerLogPrefix, _brokerOutputStream, _brokerPersistent, _brokers, _configFile, _connectionFactory, _connections, _initialContext, _interleaveBrokerLog, _output, _outputFile, _testName, BROKER_READY, CONTENT, CPP, DEFAULT_MANAGEMENT_PORT, DEFAULT_MESSAGE_SIZE, DEFAULT_PORT, DEFAULT_SSL_PORT, DEFAULT_VM_PORT, EXTERNAL, INDEX, JAVA, LOGMONITOR_TIMEOUT, QPID_HOME, QpidHome, QUEUE, RECEIVE_TIMEOUT, TOPIC, VM
 
Fields inherited from class org.apache.qpid.test.utils.QpidTestCase
MEMORY_STORE_CLASS_NAME, MS_CLASS_NAME_KEY
 
Constructor Summary
AcknowledgeOnMessageTest()
           
 
Method Summary
protected  void fail(Exception e)
          Pass the given exception back to the waiting thread to fail the test run.
 void init(boolean transacted, int mode)
          Override the synchronous AcknowledgeTest init to provide the _receivedAll CountDownLatch init and ensure that we set the MessageListener.
 void onMessage(Message message)
          The MessageListener interface that recieves the message and counts down the _receivedAll CountDownLatch.
 void setUp()
           
protected  void testAcking(boolean transacted, int mode)
          This test overrides the testAcking from the simple recieve() model to all for asynchronous receiving of messages.
 
Methods inherited from class org.apache.qpid.test.unit.ack.AcknowledgeTest
doAcknowlegement, testAutoAck, testClientAck, testDupsOk, testNoAck, testPreAck, testTransacted
 
Methods inherited from class org.apache.qpid.test.utils.FailoverBaseCase
failBroker, getConnectionFactory, getFailingPort, tearDown
 
Methods inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
cleanBroker, createMessage, createNextMessage, drainQueue, getBroker, getBrokerCommand, getClientConnection, getConfigurationStringProperty, getConnection, getConnection, getConnection, getConnectionFactory, getConnectionURL, getInitialContext, getLogger, getManagementPort, getMessageSize, getPort, getPort, getTestConfigFile, getTestQueue, getTestQueueName, getTestVirtualhostsFile, isBroker010, isBroker08, isBrokerStorePersistent, isCppBroker, isExternalBroker, isJavaBroker, makeVirtualHostPersistent, reloadBrokerSecurityConfig, restartBroker, restartBroker, revertLoggingLevels, revertSystemProperties, runBare, saveTestConfiguration, saveTestVirtualhosts, sendMessage, sendMessage, sendMessage, setBrokerEnvironment, setBrokerOnlySystemProperty, setConfigurationProperty, setLoggerLevel, setMessageSize, setSystemProperty, setSystemProperty, setTestClientSystemProperty, startBroker, startBroker, stopBroker, stopBroker
 
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

_receivedAll

protected CountDownLatch _receivedAll

_causeOfFailure

protected AtomicReference<Exception> _causeOfFailure
Constructor Detail

AcknowledgeOnMessageTest

public AcknowledgeOnMessageTest()
Method Detail

setUp

public void setUp()
           throws Exception
Overrides:
setUp in class AcknowledgeTest
Throws:
Exception

init

public void init(boolean transacted,
                 int mode)
          throws Exception
Override the synchronous AcknowledgeTest init to provide the _receivedAll CountDownLatch init and ensure that we set the MessageListener.

Overrides:
init in class AcknowledgeTest
Parameters:
transacted -
mode -
Throws:
Exception

testAcking

protected void testAcking(boolean transacted,
                          int mode)
                   throws Exception
This test overrides the testAcking from the simple recieve() model to all for asynchronous receiving of messages. Again the transaction/ack mode is provided to this main test run The init method is called which will setup the listener so that we can then sit and await using the _receivedAll CountDownLatch. We wait for up to 10s if no messages have been received in the last 10s then test will fail. If the test fails then it will attempt to retrieve any exception that the asynchronous delivery thread may have recorded.

Overrides:
testAcking in class AcknowledgeTest
Parameters:
transacted -
mode -
Throws:
Exception

onMessage

public void onMessage(Message message)
The MessageListener interface that recieves the message and counts down the _receivedAll CountDownLatch. Again like AcknowledgeTest acknowledgement is actually handled in doAcknowlegement. The message INDEX is validated to ensure the correct message order is preserved.

Specified by:
onMessage in interface MessageListener
Parameters:
message -

fail

protected void fail(Exception e)
Pass the given exception back to the waiting thread to fail the test run.

Parameters:
e - The exception that is causing the test to fail.


Licensed to the Apache Software Foundation