Add autofail to prevent test hang

see: https://issues.apache.org/jira/browse/AMQ-3842

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1340275 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-05-18 22:05:05 +00:00
parent 53fff528a7
commit fa62da8601
1 changed files with 27 additions and 21 deletions

View File

@ -38,6 +38,12 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(DiscoveryTransportNoBrokerTest.class); private static final Logger LOG = LoggerFactory.getLogger(DiscoveryTransportNoBrokerTest.class);
@Override
public void setUp() throws Exception {
setAutoFail(true);
super.setUp();
}
public void testNoExtraThreads() throws Exception { public void testNoExtraThreads() throws Exception {
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
TransportConnector tcp = broker.addConnector("tcp://localhost:0?transport.closeAsync=false"); TransportConnector tcp = broker.addConnector("tcp://localhost:0?transport.closeAsync=false");
@ -46,7 +52,7 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
tcp.setDiscoveryUri(discoveryUri); tcp.setDiscoveryUri(discoveryUri);
broker.start(); broker.start();
broker.waitUntilStarted(); broker.waitUntilStarted();
Vector<String> existingNames = new Vector<String>(); Vector<String> existingNames = new Vector<String>();
Thread[] threads = getThreads(); Thread[] threads = getThreads();
for (Thread t : threads) { for (Thread t : threads) {
@ -54,14 +60,14 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
} }
final int idleThreadCount = threads.length; final int idleThreadCount = threads.length;
LOG.info("Broker started - thread Count:" + idleThreadCount); LOG.info("Broker started - thread Count:" + idleThreadCount);
final int noConnectionToCreate = 10; final int noConnectionToCreate = 10;
for (int i=0; i<10;i++) { for (int i=0; i<10;i++) {
ActiveMQConnectionFactory factory = ActiveMQConnectionFactory factory =
new ActiveMQConnectionFactory("discovery:(multicast://239.255.2.3:6155?group=" + group +")?closeAsync=false"); new ActiveMQConnectionFactory("discovery:(multicast://239.255.2.3:6155?group=" + group +")?closeAsync=false");
LOG.info("Connecting."); LOG.info("Connecting.");
Connection connection = factory.createConnection(); Connection connection = factory.createConnection();
connection.setClientID("test"); connection.setClientID("test");
connection.close(); connection.close();
} }
Thread.sleep(2000); Thread.sleep(2000);
@ -73,8 +79,8 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
} }
assertTrue("no extra threads per connection", Thread.activeCount() - idleThreadCount < noConnectionToCreate); assertTrue("no extra threads per connection", Thread.activeCount() - idleThreadCount < noConnectionToCreate);
} }
private Thread[] getThreads() { private Thread[] getThreads() {
Thread[] threads = new Thread[Thread.activeCount()]; Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads); Thread.enumerate(threads);
@ -94,7 +100,7 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
assertTrue("reason is java.io.IOException, was: " + expected.getCause(), expected.getCause() instanceof java.io.IOException); assertTrue("reason is java.io.IOException, was: " + expected.getCause(), expected.getCause() instanceof java.io.IOException);
} }
} }
public void testInitialConnectDelayWithNoBroker() throws Exception { public void testInitialConnectDelayWithNoBroker() throws Exception {
// the initialReconnectDelay only kicks in once a set of connect URL have // the initialReconnectDelay only kicks in once a set of connect URL have
// been returned from the discovery agent. // been returned from the discovery agent.
@ -104,7 +110,7 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
long startT = System.currentTimeMillis(); long startT = System.currentTimeMillis();
String groupId = "WillNotMatch" + startT; String groupId = "WillNotMatch" + startT;
try { try {
String urlStr = "discovery:(multicast://default?group=" + groupId + String urlStr = "discovery:(multicast://default?group=" + groupId +
")?useExponentialBackOff=false&maxReconnectAttempts=2&reconnectDelay=" + initialReconnectDelay; ")?useExponentialBackOff=false&maxReconnectAttempts=2&reconnectDelay=" + initialReconnectDelay;
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlStr); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlStr);
LOG.info("Connecting."); LOG.info("Connecting.");
@ -117,20 +123,20 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
assertTrue("took at least initialReconnectDelay time: " + duration + " e:" + expected, duration >= initialReconnectDelay); assertTrue("took at least initialReconnectDelay time: " + duration + " e:" + expected, duration >= initialReconnectDelay);
} }
} }
public void testSetDiscoveredBrokerProperties() throws Exception { public void testSetDiscoveredBrokerProperties() throws Exception {
final String extraParameterName = "connectionTimeout"; final String extraParameterName = "connectionTimeout";
final String extraParameterValue = "3000"; final String extraParameterValue = "3000";
final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&" final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&"
+ DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue); + DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue);
CompositeData compositeData = URISupport.parseComposite(uri); CompositeData compositeData = URISupport.parseComposite(uri);
StubCompositeTransport compositeTransport = new StubCompositeTransport(); StubCompositeTransport compositeTransport = new StubCompositeTransport();
DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters()); DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());
discoveryTransport.onServiceAdd(new DiscoveryEvent("tcp://localhost:61616")); discoveryTransport.onServiceAdd(new DiscoveryEvent("tcp://localhost:61616"));
assertEquals("expected added URI after discovery event", compositeTransport.getTransportURIs().length, 1); assertEquals("expected added URI after discovery event", compositeTransport.getTransportURIs().length, 1);
URI discoveredServiceURI = compositeTransport.getTransportURIs()[0]; URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI); Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName)); assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
@ -157,17 +163,17 @@ public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {
} }
public void testAddRemoveDiscoveredBroker() throws Exception { public void testAddRemoveDiscoveredBroker() throws Exception {
final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&connectionTimeout=3000"); final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&connectionTimeout=3000");
CompositeData compositeData = URISupport.parseComposite(uri); CompositeData compositeData = URISupport.parseComposite(uri);
StubCompositeTransport compositeTransport = new StubCompositeTransport(); StubCompositeTransport compositeTransport = new StubCompositeTransport();
DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters()); DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());
final String serviceName = "tcp://localhost:61616"; final String serviceName = "tcp://localhost:61616";
discoveryTransport.onServiceAdd(new DiscoveryEvent(serviceName)); discoveryTransport.onServiceAdd(new DiscoveryEvent(serviceName));
assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length); assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length);
discoveryTransport.onServiceRemove(new DiscoveryEvent(serviceName)); discoveryTransport.onServiceRemove(new DiscoveryEvent(serviceName));
assertEquals("expected URI removed after discovery event", 0, compositeTransport.getTransportURIs().length); assertEquals("expected URI removed after discovery event", 0, compositeTransport.getTransportURIs().length);
} }
} }