mirror of https://github.com/apache/activemq.git
Clean up the test, use more sensible waits and don't create JMX
connectors since not needed, reduces runtime by one third.
This commit is contained in:
parent
85b9c81a3f
commit
05b401993b
|
@ -47,8 +47,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
/**
|
||||
* Test cases used to test the JMS message consumer.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JMSConsumerTest extends JmsTestSupport {
|
||||
|
||||
|
@ -110,16 +108,15 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
|
||||
// Send a message, but should not get delivered.
|
||||
sendMessages(session, destination, 1);
|
||||
assertFalse(done2.await(1, TimeUnit.SECONDS));
|
||||
assertFalse(done2.await(500, TimeUnit.MILLISECONDS));
|
||||
assertEquals(1, counter.get());
|
||||
|
||||
// Start the consumer, and the message should now get delivered.
|
||||
consumer.start();
|
||||
assertTrue(done2.await(1, TimeUnit.SECONDS));
|
||||
assertTrue(done2.await(500, TimeUnit.MILLISECONDS));
|
||||
assertEquals(2, counter.get());
|
||||
}
|
||||
|
||||
|
||||
public void testMessageListenerWithConsumerCanBeStoppedConcurently() throws Exception {
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
@ -132,7 +129,6 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
// preload the queue
|
||||
sendMessages(session, destination, 2000);
|
||||
|
||||
|
||||
final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(destination);
|
||||
|
||||
final Map<Thread, Throwable> exceptions =
|
||||
|
@ -183,12 +179,14 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
});
|
||||
|
||||
assertTrue(closeDone.await(20, TimeUnit.SECONDS));
|
||||
|
||||
// await possible exceptions
|
||||
Thread.sleep(1000);
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(1, TimeUnit.SECONDS);
|
||||
|
||||
assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
public void initCombosForTestMutiReceiveWithPrefetch1() {
|
||||
addCombinationValues("deliveryMode", new Object[] {Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
|
||||
addCombinationValues("ackMode", new Object[] {Integer.valueOf(Session.AUTO_ACKNOWLEDGE), Integer.valueOf(Session.DUPS_OK_ACKNOWLEDGE),
|
||||
|
@ -661,7 +659,6 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
}
|
||||
message.acknowledge();
|
||||
assertNull(consumer.receiveNoWait());
|
||||
|
||||
}
|
||||
|
||||
public void initCombosForTestPrefetch1MessageNotDispatched() {
|
||||
|
@ -704,7 +701,6 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
session2.commit();
|
||||
|
||||
assertNull(consumer.receiveNoWait());
|
||||
|
||||
}
|
||||
|
||||
public void initCombosForTestDontStart() {
|
||||
|
@ -771,7 +767,6 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
assertNull(consumer.receiveNoWait());
|
||||
}
|
||||
|
||||
|
||||
public void testDupsOkConsumer() throws Exception {
|
||||
|
||||
// Receive a message with the JMS API
|
||||
|
@ -788,13 +783,13 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
Message m = consumer.receive(1000);
|
||||
assertNotNull(m);
|
||||
}
|
||||
assertNull(consumer.receive(1000));
|
||||
assertNull(consumer.receive(500));
|
||||
|
||||
// Close out the consumer.. no other messages should be left on the queue.
|
||||
consumer.close();
|
||||
|
||||
consumer = session.createConsumer(destination);
|
||||
assertNull(consumer.receive(1000));
|
||||
assertNull(consumer.receive(500));
|
||||
}
|
||||
|
||||
public void testRedispatchOfUncommittedTx() throws Exception {
|
||||
|
@ -831,7 +826,6 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
redispatchSession.close();
|
||||
}
|
||||
|
||||
|
||||
public void testRedispatchOfRolledbackTx() throws Exception {
|
||||
|
||||
connection.start();
|
||||
|
@ -865,10 +859,9 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
redispatchSession.close();
|
||||
}
|
||||
|
||||
|
||||
public void initCombosForTestAckOfExpired() {
|
||||
addCombinationValues("destinationType",
|
||||
new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)});
|
||||
new Object[] {Byte.valueOf(ActiveMQDestination.QUEUE_TYPE), Byte.valueOf(ActiveMQDestination.TOPIC_TYPE)});
|
||||
}
|
||||
|
||||
public void testAckOfExpired() throws Exception {
|
||||
|
@ -886,7 +879,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
|
||||
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = sendSession.createProducer(destination);
|
||||
producer.setTimeToLive(1000);
|
||||
producer.setTimeToLive(500);
|
||||
final int count = 4;
|
||||
for (int i = 0; i < count; i++) {
|
||||
TextMessage message = sendSession.createTextMessage("" + i);
|
||||
|
@ -894,7 +887,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
}
|
||||
|
||||
// let first bunch in queue expire
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(1000);
|
||||
|
||||
producer.setTimeToLive(0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
@ -904,7 +897,7 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
|
||||
ActiveMQMessageConsumer amqConsumer = (ActiveMQMessageConsumer) consumer;
|
||||
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i=0; i<count; i++) {
|
||||
TextMessage msg = (TextMessage) amqConsumer.receive();
|
||||
assertNotNull(msg);
|
||||
assertTrue("message has \"no expiry\" text: " + msg.getText(), msg.getText().contains("no expiry"));
|
||||
|
@ -924,14 +917,13 @@ public class JMSConsumerTest extends JmsTestSupport {
|
|||
|
||||
protected DestinationViewMBean createView(ActiveMQDestination destination) throws Exception {
|
||||
|
||||
String domain = "org.apache.activemq";
|
||||
ObjectName name;
|
||||
String domain = "org.apache.activemq";
|
||||
ObjectName name;
|
||||
if (destination.isQueue()) {
|
||||
name = new ObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=test");
|
||||
} else {
|
||||
name = new ObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Topic,destinationName=test");
|
||||
}
|
||||
return (DestinationViewMBean)broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
|
||||
return (DestinationViewMBean) broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,9 +111,12 @@ public class JmsTestSupport extends CombinationTestSupport {
|
|||
}
|
||||
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
return BrokerFactory.createBroker(new URI("broker://()/localhost?persistent=false"));
|
||||
BrokerService service = BrokerFactory.createBroker(new URI("broker://()/localhost?persistent=false"));
|
||||
service.getManagementContext().setCreateConnector(false);;
|
||||
return service;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
@ -129,6 +132,7 @@ public class JmsTestSupport extends CombinationTestSupport {
|
|||
connections.add(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
for (Iterator<Connection> iter = connections.iterator(); iter.hasNext();) {
|
||||
Connection conn = iter.next();
|
||||
|
|
Loading…
Reference in New Issue