mirror of https://github.com/apache/activemq.git
AMQ-9193 - Improve broker shutdown in unit tests
This should improve test reliability for the unit tests so brokers don't
hang around after the end of a test on error. Also increase the surefire
re-run count to 3 times before failing.
(cherry picked from commit a083ff4d23
)
This commit is contained in:
parent
164568aab4
commit
5e12551a4a
|
@ -75,7 +75,7 @@ pipeline {
|
|||
echo 'Running tests'
|
||||
// all tests is very very long (10 hours on Apache Jenkins)
|
||||
// sh 'mvn -B -e test -pl activemq-unit-tests -Dactivemq.tests=all'
|
||||
sh 'mvn -B -e -fae test -Dsurefire.rerunFailingTestsCount=2'
|
||||
sh 'mvn -B -e -fae test -Dsurefire.rerunFailingTestsCount=3'
|
||||
}
|
||||
post {
|
||||
always {
|
||||
|
|
|
@ -467,6 +467,8 @@ public class MDBTest {
|
|||
public void testErrorOnNoMessageDeliveryBrokerZeroPrefetchConfig() throws Exception {
|
||||
|
||||
final BrokerService brokerService = new BrokerService();
|
||||
|
||||
try {
|
||||
final String brokerUrl = "vm://zeroPrefetch?create=false";
|
||||
brokerService.setBrokerName("zeroPrefetch");
|
||||
brokerService.setPersistent(false);
|
||||
|
@ -478,7 +480,8 @@ public class MDBTest {
|
|||
brokerService.start();
|
||||
|
||||
final AtomicReference<String> errorMessage = new AtomicReference<String>();
|
||||
final var appender = new AbstractAppender("test", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
|
||||
final var appender = new AbstractAppender("test", new AbstractFilter() {
|
||||
}, new MessageLayout(), false, new Property[0]) {
|
||||
@Override
|
||||
public void append(LogEvent event) {
|
||||
if (event.getLevel().isMoreSpecificThan(Level.ERROR)) {
|
||||
|
@ -489,16 +492,19 @@ public class MDBTest {
|
|||
};
|
||||
appender.start();
|
||||
|
||||
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
|
||||
final var logger = org.apache.logging.log4j.core.Logger.class.cast(
|
||||
LogManager.getRootLogger());
|
||||
logger.addAppender(appender);
|
||||
logger.get().addAppender(appender, Level.INFO, new AbstractFilter() {});
|
||||
logger.get().addAppender(appender, Level.INFO, new AbstractFilter() {
|
||||
});
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerUrl);
|
||||
Connection connection = factory.createConnection();
|
||||
connection.start();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
MessageConsumer advisory = session.createConsumer(AdvisorySupport.getConsumerAdvisoryTopic(new ActiveMQQueue("TEST")));
|
||||
MessageConsumer advisory = session.createConsumer(
|
||||
AdvisorySupport.getConsumerAdvisoryTopic(new ActiveMQQueue("TEST")));
|
||||
|
||||
ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter();
|
||||
adapter.setServerUrl(brokerUrl);
|
||||
|
@ -511,7 +517,9 @@ public class MDBTest {
|
|||
public void onMessage(Message message) {
|
||||
super.onMessage(message);
|
||||
messageDelivered.countDown();
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
};
|
||||
|
||||
ActiveMQActivationSpec activationSpec = new ActiveMQActivationSpec();
|
||||
|
@ -522,7 +530,8 @@ public class MDBTest {
|
|||
|
||||
MessageEndpointFactory messageEndpointFactory = new MessageEndpointFactory() {
|
||||
@Override
|
||||
public MessageEndpoint createEndpoint(XAResource resource) throws UnavailableException {
|
||||
public MessageEndpoint createEndpoint(XAResource resource)
|
||||
throws UnavailableException {
|
||||
endpoint.xaresource = resource;
|
||||
return endpoint;
|
||||
}
|
||||
|
@ -538,7 +547,8 @@ public class MDBTest {
|
|||
|
||||
ActiveMQMessage msg = (ActiveMQMessage) advisory.receive(4000);
|
||||
if (msg != null) {
|
||||
assertEquals("Prefetch size hasn't been set", 0, ((ConsumerInfo)msg.getDataStructure()).getPrefetchSize());
|
||||
assertEquals("Prefetch size hasn't been set", 0,
|
||||
((ConsumerInfo) msg.getDataStructure()).getPrefetchSize());
|
||||
} else {
|
||||
fail("Consumer hasn't been created");
|
||||
}
|
||||
|
@ -557,13 +567,15 @@ public class MDBTest {
|
|||
adapter.stop();
|
||||
|
||||
assertNotNull("We got an error message", errorMessage.get());
|
||||
assertTrue("correct message: " + errorMessage.get(), errorMessage.get().contains("zero"));
|
||||
assertTrue("correct message: " + errorMessage.get(),
|
||||
errorMessage.get().contains("zero"));
|
||||
|
||||
logger.removeAppender(appender);
|
||||
logger.get().removeAppender("test");
|
||||
|
||||
} finally {
|
||||
brokerService.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageExceptionReDelivery() throws Exception {
|
||||
|
|
|
@ -99,8 +99,12 @@ public class ExpiredAckAsyncConsumerTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
connectionConsumer.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
broker.stop();
|
||||
broker.waitUntilStopped();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,11 @@ public class VirtualTopicWildcardTest {
|
|||
|
||||
@After
|
||||
public void afer() throws Exception {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
brokerService.stop();
|
||||
}
|
||||
|
||||
|
|
|
@ -105,8 +105,12 @@ public class AMQ2801Test
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
conn1.close();
|
||||
conn2.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
if (broker != null) {
|
||||
broker.stop();
|
||||
}
|
||||
|
|
|
@ -72,12 +72,16 @@ public class AMQ3145Test {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
if (consumer != null) {
|
||||
consumer.close();
|
||||
}
|
||||
session.close();
|
||||
connection.stop();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
broker.stop();
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,11 @@ public class AMQ3732Test {
|
|||
|
||||
@After
|
||||
public void stopBroker() throws Exception {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
|
||||
broker.stop();
|
||||
broker.waitUntilStopped();
|
||||
|
|
|
@ -65,8 +65,10 @@ public class AMQ6815Test {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
brokerService.stop();
|
||||
}
|
||||
|
|
|
@ -68,8 +68,12 @@ public class OutOfOrderTestCase extends TestCase {
|
|||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
session.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
brokerService.stop();
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,11 @@ public class ProxyTestSupport extends BrokerTestSupport {
|
|||
protected void tearDown() throws Exception {
|
||||
for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
|
||||
StubConnection connection = iter.next();
|
||||
try {
|
||||
connection.stop();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
iter.remove();
|
||||
}
|
||||
remoteBroker.stop();
|
||||
|
|
|
@ -149,7 +149,11 @@ public class JMXRemoveQueueThenSendIgnoredTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
brokerService.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,10 +285,14 @@ public class TopicSubscriptionZeroPrefetchTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
try {
|
||||
consumer.close();
|
||||
producer.close();
|
||||
session.close();
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
//swallow any error so broker can still be stopped
|
||||
}
|
||||
brokerService.stop();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue