renamed to follow Test naming convention

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@903487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2010-01-26 23:31:06 +00:00
parent 8eeedce809
commit 8b1e16de48
2 changed files with 118 additions and 117 deletions

View File

@ -27,7 +27,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService;
public class AMQ2571 extends EmbeddedBrokerTestSupport {
public class AMQ2571Test extends EmbeddedBrokerTestSupport {
public void testTempQueueClosing() {
try {

View File

@ -50,24 +50,24 @@ import org.apache.activemq.CombinationTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.store.amq.AMQPersistenceAdapterFactory;
import org.apache.activemq.util.ThreadTracker;
import org.apache.activemq.store.kahadb.KahaDBStore;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @version $Revision: 1.5 $
* A Test case for AMQ-1479
* @version $Revision: 1.5 $ A Test case for AMQ-1479
*/
public class DurableConsumerTest extends CombinationTestSupport {
public class DurableConsumerTest extends CombinationTestSupport{
private static final Log LOG = LogFactory.getLog(DurableConsumerTest.class);
private static int COUNT = 1024*10;
private static int COUNT = 1024 * 10;
private static String CONSUMER_NAME = "DURABLE_TEST";
protected BrokerService broker;
protected String bindAddress="tcp://localhost:61616";
protected String bindAddress = "tcp://localhost:61616";
protected byte[] payload = new byte[1024*32];
protected byte[] payload = new byte[1024 * 32];
protected ConnectionFactory factory;
protected Vector<Exception> exceptions = new Vector<Exception>();
@ -75,18 +75,17 @@ public class DurableConsumerTest extends CombinationTestSupport {
private static final String CONNECTION_URL = "failover:(tcp://localhost:61616,tcp://localhost:61617)";
public boolean useDedicatedTaskRunner = false;
private class SimpleTopicSubscriber implements MessageListener, ExceptionListener {
private class SimpleTopicSubscriber implements MessageListener,ExceptionListener{
private TopicConnection topicConnection = null;
public SimpleTopicSubscriber(String connectionURL, String clientId, String topicName) {
public SimpleTopicSubscriber(String connectionURL,String clientId,String topicName) {
ActiveMQConnectionFactory topicConnectionFactory = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
topicConnectionFactory = new ActiveMQConnectionFactory(connectionURL);
try {
@ -104,10 +103,10 @@ public class DurableConsumerTest extends CombinationTestSupport {
}
}
public void onMessage(Message arg0) {
public void onMessage(Message arg0){
}
public void closeConnection() {
public void closeConnection(){
if (topicConnection != null) {
try {
topicConnection.close();
@ -116,15 +115,15 @@ public class DurableConsumerTest extends CombinationTestSupport {
}
}
public void onException(JMSException exception) {
public void onException(JMSException exception){
exceptions.add(exception);
}
}
private class MessagePublisher implements Runnable {
private class MessagePublisher implements Runnable{
private boolean shouldPublish = true;
public void run() {
public void run(){
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
@ -132,7 +131,6 @@ public class DurableConsumerTest extends CombinationTestSupport {
TopicPublisher topicPublisher = null;
Message message = null;
topicConnectionFactory = new ActiveMQConnectionFactory(CONNECTION_URL);
try {
topic = new ActiveMQTopic(TOPIC_NAME);
@ -140,7 +138,7 @@ public class DurableConsumerTest extends CombinationTestSupport {
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topicPublisher = topicSession.createPublisher(topic);
message = topicSession.createMessage();
} catch( Exception ex ) {
} catch (Exception ex) {
exceptions.add(ex);
}
while (shouldPublish) {
@ -157,30 +155,30 @@ public class DurableConsumerTest extends CombinationTestSupport {
}
}
private void configurePersistence(BrokerService broker) throws Exception {
File dataDirFile = new File("target/"+ getName());
private void configurePersistence(BrokerService broker) throws Exception{
File dataDirFile = new File("target/" + getName());
AMQPersistenceAdapterFactory fact = new AMQPersistenceAdapterFactory();
fact.setDataDirectory(dataDirFile);
fact.setForceRecoverReferenceStore(true);
broker.setPersistenceAdapter(fact.createPersistenceAdapter());
}
public void testFailover() throws Exception {
public void testFailover() throws Exception{
configurePersistence(broker);
broker.start();
Thread publisherThread = new Thread( new MessagePublisher() );
Thread publisherThread = new Thread(new MessagePublisher());
publisherThread.start();
for( int i = 0; i < 100; i++ ) {
for (int i = 0; i < 100; i++) {
final int id = i;
Thread thread = new Thread( new Runnable() {
public void run() {
new SimpleTopicSubscriber(CONNECTION_URL, System.currentTimeMillis()+"-"+id, TOPIC_NAME);
Thread thread = new Thread(new Runnable(){
public void run(){
new SimpleTopicSubscriber(CONNECTION_URL, System.currentTimeMillis() + "-" + id, TOPIC_NAME);
}
} );
});
thread.start();
}
@ -196,40 +194,37 @@ public class DurableConsumerTest extends CombinationTestSupport {
// makes heavy use of threads and can demonstrate https://issues.apache.org/activemq/browse/AMQ-2028
// with use dedicatedTaskRunner=true and produce OOM
public void initCombosForTestConcurrentDurableConsumer() {
addCombinationValues("useDedicatedTaskRunner", new Object[] {Boolean.TRUE, Boolean.FALSE});
public void initCombosForTestConcurrentDurableConsumer(){
addCombinationValues("useDedicatedTaskRunner", new Object[] { Boolean.TRUE, Boolean.FALSE });
}
public void testConcurrentDurableConsumer() throws Exception {
public void testConcurrentDurableConsumer() throws Exception{
broker.start();
factory = createConnectionFactory();
final String topicName = getName();
final int numMessages = 500;
int numConsumers = 20;
int numConsumers = 1;
final CountDownLatch counsumerStarted = new CountDownLatch(0);
final AtomicInteger receivedCount = new AtomicInteger();
Runnable consumer = new Runnable() {
public void run() {
Runnable consumer = new Runnable(){
public void run(){
final String consumerName = Thread.currentThread().getName();
int acked = 0;
int received = 0;
try {
while (acked < numMessages/2) {
while (acked < numMessages / 2) {
// take one message and close, ack on occasion
Connection consumerConnection = factory.createConnection();
((ActiveMQConnection)consumerConnection).setWatchTopicAdvisories(false);
((ActiveMQConnection) consumerConnection).setWatchTopicAdvisories(false);
consumerConnection.setClientID(consumerName);
Session consumerSession = consumerConnection.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
Session consumerSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Topic topic = consumerSession.createTopic(topicName);
consumerConnection.start();
MessageConsumer consumer = consumerSession
.createDurableSubscriber(topic, consumerName);
MessageConsumer consumer = consumerSession.createDurableSubscriber(topic, consumerName);
counsumerStarted.countDown();
Message msg = null;
@ -256,23 +251,23 @@ public class DurableConsumerTest extends CombinationTestSupport {
ExecutorService executor = Executors.newFixedThreadPool(numConsumers);
for (int i=0; i<numConsumers ; i++) {
for (int i = 0; i < numConsumers; i++) {
executor.execute(consumer);
}
assertTrue(counsumerStarted.await(30, TimeUnit.SECONDS));
Connection producerConnection = factory.createConnection();
((ActiveMQConnection)producerConnection).setWatchTopicAdvisories(false);
((ActiveMQConnection) producerConnection).setWatchTopicAdvisories(false);
Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = producerSession.createTopic(topicName);
MessageProducer producer = producerSession.createProducer(topic);
producerConnection.start();
for (int i =0; i < numMessages; i++) {
for (int i = 0; i < numMessages; i++) {
BytesMessage msg = producerSession.createBytesMessage();
msg.writeBytes(payload);
producer.send(msg);
if (i != 0 && i%100==0) {
if (i != 0 && i % 100 == 0) {
LOG.info("Sent msg " + i);
}
}
@ -280,20 +275,20 @@ public class DurableConsumerTest extends CombinationTestSupport {
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);
Wait.waitFor(new Wait.Condition() {
public boolean isSatisified() throws Exception {
Wait.waitFor(new Wait.Condition(){
public boolean isSatisified() throws Exception{
return receivedCount.get() > numMessages;
}
}, 60*1000);
}, 60 * 1000);
assertTrue("got some messages: " + receivedCount.get(), receivedCount.get() > numMessages);
assertTrue("no exceptions, but: " + exceptions, exceptions.isEmpty());
}
public void testConsumerRecover() throws Exception {
public void testConsumerRecover() throws Exception{
doTestConsumer(true);
}
public void testConsumer() throws Exception {
public void testConsumer() throws Exception{
doTestConsumer(false);
}
@ -325,11 +320,11 @@ public class DurableConsumerTest extends CombinationTestSupport {
MessageProducer producer = producerSession.createProducer(topic);
producerConnection.start();
for (int i =0; i < COUNT;i++) {
for (int i = 0; i < COUNT; i++) {
BytesMessage msg = producerSession.createBytesMessage();
msg.writeBytes(payload);
producer.send(msg);
if (i != 0 && i%1000==0) {
if (i != 0 && i % 1000 == 0) {
LOG.info("Sent msg " + i);
}
}
@ -347,20 +342,19 @@ public class DurableConsumerTest extends CombinationTestSupport {
consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = consumerSession.createDurableSubscriber(topic, CONSUMER_NAME);
for (int i =0; i < COUNT;i++) {
for (int i = 0; i < COUNT; i++) {
Message msg = consumer.receive(5000);
assertNotNull("Missing message: "+i, msg);
if (i != 0 && i%1000==0) {
assertNotNull("Missing message: " + i, msg);
if (i != 0 && i % 1000 == 0) {
LOG.info("Received msg " + i);
}
}
consumerConnection.close();
}
protected void setUp() throws Exception {
protected void setUp() throws Exception{
if (broker == null) {
broker = createBroker(true);
}
@ -368,7 +362,7 @@ public class DurableConsumerTest extends CombinationTestSupport {
super.setUp();
}
protected void tearDown() throws Exception {
protected void tearDown() throws Exception{
super.tearDown();
if (broker != null) {
broker.stop();
@ -376,7 +370,7 @@ public class DurableConsumerTest extends CombinationTestSupport {
}
}
protected Topic creatTopic(Session s, String destinationName) throws JMSException {
protected Topic creatTopic(Session s,String destinationName) throws JMSException{
return s.createTopic(destinationName);
}
@ -385,15 +379,22 @@ public class DurableConsumerTest extends CombinationTestSupport {
*
* @throws Exception
*/
protected BrokerService createBroker(boolean deleteStore) throws Exception {
protected BrokerService createBroker(boolean deleteStore) throws Exception{
BrokerService answer = new BrokerService();
configureBroker(answer,deleteStore);
configureBroker(answer, deleteStore);
return answer;
}
protected void configureBroker(BrokerService answer,boolean deleteStore) throws Exception {
protected void configureBroker(BrokerService answer,boolean deleteStore) throws Exception{
answer.setDeleteAllMessagesOnStartup(deleteStore);
KahaDBStore kaha = new KahaDBStore();
File directory = new File("target/activemq-data/kahadb");
if (deleteStore) {
IOHelper.deleteChildren(directory);
}
kaha.setDirectory(directory);
answer.setPersistenceAdapter(kaha);
answer.addConnector(bindAddress);
answer.setUseShutdownHook(false);
answer.setUseJmx(false);
@ -401,17 +402,17 @@ public class DurableConsumerTest extends CombinationTestSupport {
answer.setDedicatedTaskRunner(useDedicatedTaskRunner);
}
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception{
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(bindAddress);
factory.setUseDedicatedTaskRunner(useDedicatedTaskRunner);
return factory;
}
public static Test suite() {
public static Test suite(){
return suite(DurableConsumerTest.class);
}
public static void main(String[] args) {
public static void main(String[] args){
junit.textui.TestRunner.run(suite());
}
}