From 4caad1a058d58b6618093ba7d20081bc141c2b03 Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Thu, 3 Dec 2009 12:12:37 +0000 Subject: [PATCH] investigating JDBCSpringTest intermittent failures git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@886751 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/usecases/ConsumerThread.java | 16 ++-------------- .../apache/activemq/usecases/JDBCSpringTest.java | 15 +++------------ .../apache/activemq/usecases/ProducerThread.java | 3 ++- .../src/test/resources/log4j.properties | 2 ++ 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/activemq-pool/src/test/java/org/apache/activemq/usecases/ConsumerThread.java b/activemq-pool/src/test/java/org/apache/activemq/usecases/ConsumerThread.java index f82e25d3fd..b7a188e6fb 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/usecases/ConsumerThread.java +++ b/activemq-pool/src/test/java/org/apache/activemq/usecases/ConsumerThread.java @@ -53,7 +53,7 @@ public class ConsumerThread extends Thread { while (run) { try { - Thread.sleep(3000); + Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } @@ -66,7 +66,7 @@ public class ConsumerThread extends Thread { ((SingleConnectionFactory)connectionFactory).destroy(); } - log.info("ConsumerThread1 closing down"); + log.info("ConsumerThread closing down"); } private DefaultMessageListenerContainer createContainer() { @@ -82,18 +82,6 @@ public class ConsumerThread extends Thread { container.setConcurrentConsumers(concurrentConsumers); container.setSessionTransacted(sessionTransacted); - //container.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); - //container.setMaxConcurrentConsumers(concurrentConsumers); - //container.setAcceptMessagesWhileStopping(false); - //container.setAutoStartup(false); - //without setting a tx manager, this will use local JMS tx. - - /* - if (durable) { - container.setSubscriptionDurable(true); - container.setDurableSubscriptionName("ConsumerThread1" + Thread.currentThread().getId()); - } - */ container.afterPropertiesSet(); log.info("subscribing to " + destination + queueSuffix); return container; diff --git a/activemq-pool/src/test/java/org/apache/activemq/usecases/JDBCSpringTest.java b/activemq-pool/src/test/java/org/apache/activemq/usecases/JDBCSpringTest.java index 9b66890bbc..80a5e07d84 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/usecases/JDBCSpringTest.java +++ b/activemq-pool/src/test/java/org/apache/activemq/usecases/JDBCSpringTest.java @@ -88,7 +88,7 @@ public class JDBCSpringTest extends TestCase { thread.setNumberOfQueues(numberOfQueues); thread.setQueuePrefix("AMQ-2436.queue."); thread.setConnectionFactory(connectionFactory); - thread.setSendDelay(100); + //thread.setSendDelay(100); ProducerThreads.add(thread); } @@ -106,13 +106,7 @@ public class JDBCSpringTest extends TestCase { thread.setConsumerName("consumer" + i); ConsumerThreads.add(thread); thread.start(); - - while (!thread.isRunning()) { - Thread.sleep(200); - } - } - - Thread.sleep(5000); + } for (ProducerThread thread : ProducerThreads) { @@ -120,12 +114,10 @@ public class JDBCSpringTest extends TestCase { } boolean finished = false; - int retry = 0; int previous = 0; while (!finished) { int totalMessages = 0; - retry++; for (Thread thread : ConsumerThreads) { totalMessages += ((ConsumerThread)thread).getMessageDrivenPojo().getMessageCount(); } @@ -134,7 +126,6 @@ public class JDBCSpringTest extends TestCase { for (Thread thread : ConsumerThreads) { ((ConsumerThread)thread).setRun(false); } - Thread.sleep(3000); fail("Received " + totalMessages + ", expected " + (numberOfMessages * numberOfProducerThreads)); } previous = totalMessages; @@ -151,7 +142,7 @@ public class JDBCSpringTest extends TestCase { } } else { - Thread.sleep(10000); + Thread.sleep(1000); } } } diff --git a/activemq-pool/src/test/java/org/apache/activemq/usecases/ProducerThread.java b/activemq-pool/src/test/java/org/apache/activemq/usecases/ProducerThread.java index cb8bb90b52..f30d75c363 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/usecases/ProducerThread.java +++ b/activemq-pool/src/test/java/org/apache/activemq/usecases/ProducerThread.java @@ -34,7 +34,7 @@ public class ProducerThread extends Thread { private int numberOfTopics; private int numberOfMessagesToSend; private int messagesSent; - private Random generator = new Random(); + private Random generator; private String queuePrefix; private ConnectionFactory connectionFactory; private String message; @@ -45,6 +45,7 @@ public class ProducerThread extends Thread { @Override public void run() { initialize(); + Random generator = new Random(Thread.currentThread().getName().hashCode()); while (messagesSent < numberOfMessagesToSend) { int queueSuffix = generator.nextInt(numberOfTopics); diff --git a/activemq-pool/src/test/resources/log4j.properties b/activemq-pool/src/test/resources/log4j.properties index d95fe6f509..9d67ba1f0b 100755 --- a/activemq-pool/src/test/resources/log4j.properties +++ b/activemq-pool/src/test/resources/log4j.properties @@ -21,6 +21,8 @@ log4j.rootLogger=INFO, out, stdout log4j.logger.org.apache.activemq.spring=WARN +#log4j.logger.org.apache.activemq.usecases=DEBUG +#log4j.logger.org.apache.activemq.broker.region=DEBUG # CONSOLE appender not used by default log4j.appender.stdout=org.apache.log4j.ConsoleAppender