mirror of https://github.com/apache/activemq.git
Fix another test that fails because of https://issues.apache.org/jira/browse/AMQ-4237
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1431123 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3dd24195e6
commit
ac23437828
|
@ -39,7 +39,6 @@ import javax.management.ObjectName;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.BrokerTestSupport;
|
||||
import org.apache.activemq.broker.StubConnection;
|
||||
|
@ -72,9 +71,6 @@ import org.slf4j.LoggerFactory;
|
|||
* and {@link BrokerTestSupport} because more control was needed over how brokers
|
||||
* and connectors are created. Also, this test asserts message counts via JMX on
|
||||
* each broker.
|
||||
*
|
||||
* @author bsnyder
|
||||
*
|
||||
*/
|
||||
public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSupport*/ {
|
||||
|
||||
|
@ -85,7 +81,7 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
private DemandForwardingBridge bridge;
|
||||
|
||||
protected Map<String, BrokerService> brokers = new HashMap<String, BrokerService>();
|
||||
protected ArrayList connections = new ArrayList();
|
||||
protected ArrayList<StubConnection> connections = new ArrayList<StubConnection>();
|
||||
|
||||
protected TransportConnector connector;
|
||||
protected TransportConnector remoteConnector;
|
||||
|
@ -98,6 +94,7 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
|
||||
protected String amqDomain = "org.apache.activemq";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
// For those who want visual confirmation:
|
||||
|
@ -140,8 +137,9 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
protected void waitForBridgeFormation() throws Exception {
|
||||
for (final BrokerService broker : brokers.values()) {
|
||||
if (!broker.getNetworkConnectors().isEmpty()) {
|
||||
// Max wait here is 30 secs
|
||||
// Max wait here is 30 secs
|
||||
Wait.waitFor(new Wait.Condition() {
|
||||
@Override
|
||||
public boolean isSatisified() throws Exception {
|
||||
return !broker.getNetworkConnectors().get(0).activeBridges().isEmpty();
|
||||
}});
|
||||
|
@ -149,6 +147,7 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
bridge.stop();
|
||||
localBroker.stop();
|
||||
|
@ -385,52 +384,53 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
return connection;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "unused" })
|
||||
private Object[] browseQueueWithJms(BrokerService broker) throws Exception {
|
||||
Object[] messages = null;
|
||||
Connection connection = null;
|
||||
Session session = null;
|
||||
Object[] messages = null;
|
||||
Connection connection = null;
|
||||
Session session = null;
|
||||
|
||||
try {
|
||||
URI brokerUri = connector.getUri();
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri.toString());
|
||||
connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Queue destination = session.createQueue(queueName);
|
||||
QueueBrowser browser = session.createBrowser(destination);
|
||||
List<Message> list = new ArrayList<Message>();
|
||||
for (Enumeration<Message> enumn = browser.getEnumeration(); enumn.hasMoreElements();) {
|
||||
list.add(enumn.nextElement());
|
||||
}
|
||||
messages = list.toArray();
|
||||
}
|
||||
finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
LOG.info("+Browsed with JMS: " + messages.length);
|
||||
try {
|
||||
URI brokerUri = connector.getUri();
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri.toString());
|
||||
connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Queue destination = session.createQueue(queueName);
|
||||
QueueBrowser browser = session.createBrowser(destination);
|
||||
List<Message> list = new ArrayList<Message>();
|
||||
for (Enumeration<Message> enumn = browser.getEnumeration(); enumn.hasMoreElements();) {
|
||||
list.add(enumn.nextElement());
|
||||
}
|
||||
messages = list.toArray();
|
||||
}
|
||||
finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
LOG.info("+Browsed with JMS: " + messages.length);
|
||||
|
||||
return messages;
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
private Object[] browseQueueWithJmx(BrokerService broker) throws Exception {
|
||||
Hashtable<String, String> params = new Hashtable<String, String>();
|
||||
params.put("BrokerName", broker.getBrokerName());
|
||||
params.put("Type", "Queue");
|
||||
params.put("Destination", queueName);
|
||||
params.put("brokerName", broker.getBrokerName());
|
||||
params.put("type", "Broker");
|
||||
params.put("destinationType", "Queue");
|
||||
params.put("destinationName", queueName);
|
||||
ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);
|
||||
|
||||
ManagementContext mgmtCtx = broker.getManagementContext();
|
||||
QueueViewMBean queueView = (QueueViewMBean)mgmtCtx.newProxyInstance(queueObjectName, QueueViewMBean.class, true);
|
||||
|
||||
Object[] messages = (Object[]) queueView.browse();
|
||||
Object[] messages = queueView.browse();
|
||||
|
||||
LOG.info("+Browsed with JMX: " + messages.length);
|
||||
LOG.info("+Browsed with JMX: " + messages.length);
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
@ -530,5 +530,4 @@ public class BrokerNetworkWithStuckMessagesTest extends TestCase /*NetworkTestSu
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue