https://issues.apache.org/jira/browse/AMQ-4237 - resolve unit test regressions for dynamic networkBridge mbeans

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1430266 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2013-01-08 13:13:27 +00:00
parent 4cbd91d494
commit e3626e19bc
5 changed files with 22 additions and 31 deletions

View File

@ -17,6 +17,7 @@
package org.apache.activemq.network;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javax.management.MalformedObjectNameException;
@ -82,18 +83,9 @@ public class MBeanNetworkListener implements NetworkBridgeListener {
}
protected ObjectName createNetworkBridgeObjectName(NetworkBridge bridge) throws MalformedObjectNameException {
Map<String, String> map = new HashMap<String, String>(connectorName.getKeyPropertyList());
StringBuilder objectNameStr = new StringBuilder();
objectNameStr.append(connectorName.getDomain()).append(":");
objectNameStr.append("type=Broker").append(",");
objectNameStr.append("brokerName=" + JMXSupport.encodeObjectNamePart(map.get("brokerName"))).append(",");
objectNameStr.append("service=NetworkBridge").append(",");
objectNameStr.append("networkConnectorName=" + JMXSupport.encodeObjectNamePart(map.get("networkConnectorName"))).append(",");
objectNameStr.append("networkBridgeName=" + JMXSupport.encodeObjectNamePart(bridge.getRemoteAddress()));
return new ObjectName(objectNameStr.toString());
Hashtable<String, String> map = new Hashtable<String, String>(connectorName.getKeyPropertyList());
map.put("networkBridge", JMXSupport.encodeObjectNamePart(bridge.getRemoteAddress()));
return new ObjectName(connectorName.getDomain(), map);
}
public void setCreatedByDuplex(boolean createdByDuplex) {

View File

@ -414,7 +414,6 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
WRITE_CHECK_TIMER = null;
READ_CHECK_TIMER = null;
ThreadPoolUtils.shutdown(ASYNC_TASKS);
ASYNC_TASKS = null;
}
}
}

View File

@ -64,18 +64,18 @@ public class DuplexNetworkMBeanTest {
networkedBroker = createNetworkedBroker();
try {
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "service=NetworkBridge", 2000));
assertEquals(1, countMbeans(broker, "service=NetworkBridge", 2000));
assertEquals(1, countMbeans(networkedBroker, "networkBridge", 2000));
assertEquals(1, countMbeans(broker, "networkBridge", 2000));
assertEquals(1, countMbeans(broker, "connectionName"));
} finally {
networkedBroker.stop();
networkedBroker.waitUntilStopped();
}
assertEquals(0, countMbeans(networkedBroker, "stopped"));
assertEquals(0, countMbeans(broker, "service=NetworkBridge"));
assertEquals(0, countMbeans(broker, "networkBridge"));
}
assertEquals(0, countMbeans(networkedBroker, "service=NetworkBridge"));
assertEquals(0, countMbeans(networkedBroker, "networkBridge"));
assertEquals(0, countMbeans(networkedBroker, "connector"));
assertEquals(0, countMbeans(networkedBroker, "connectionName"));
assertEquals(1, countMbeans(broker, "connector"));
@ -99,7 +99,7 @@ public class DuplexNetworkMBeanTest {
broker = createBroker();
try {
broker.start();
assertEquals(1, countMbeans(networkedBroker, "service=NetworkBridge", 5000));
assertEquals(1, countMbeans(networkedBroker, "networkBridge", 5000));
assertEquals("restart number: " + i, 1, countMbeans(broker, "connectionName", 10000));
} finally {
broker.stop();

View File

@ -191,8 +191,8 @@ public class FailoverStaticNetworkTest {
private Set<String> getNetworkBridgeMBeanName(BrokerService brokerB) throws Exception {
Set<String> names = new HashSet<String>();
for (ObjectName objectName : brokerB.getManagementContext().queryNames(null, null)) {
if ("NetworkBridge".equals(objectName.getKeyProperty("service"))) {
names.add(objectName.getKeyProperty("networkBridgeName"));
if (objectName.getKeyProperty("networkBridge") != null) {
names.add(objectName.getKeyProperty("networkBridge"));
}
}
return names;

View File

@ -75,12 +75,11 @@ public class DiscoveryNetworkReconnectTest {
ObjectName mine = (ObjectName) name;
LOG.info("Match: " + mine + " vs: " + other);
if (other.getKeyProperty("service") == null) {
if (!"networkConnectors".equals(other.getKeyProperty("connector"))) {
return false;
}
return other.getKeyProperty("service").equals(mine.getKeyProperty("service")) &&
other.getKeyProperty("networkConnectorName").equals(mine.getKeyProperty("networkConnectorName"));
return other.getKeyProperty("connector").equals(mine.getKeyProperty("connector")) &&
other.getKeyProperty("networkBridge") != null && mine.getKeyProperty("networkBridge") != null;
}
@Override
@ -129,17 +128,17 @@ public class DiscoveryNetworkReconnectTest {
new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=jobScheduler,jobSchedulerName=JMS"))));
atLeast(maxReconnects - 1).of (managementContext).registerMBean(with(any(Object.class)), with(new NetworkBridgeObjectNameMatcher<ObjectName>(
new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=NetworkBridge,networkConnectorName=NC,networkBridgeName=localhost/127.0.0.1_"
new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_"
+ proxy.getUrl().getPort())))); will(new CustomAction("signal register network mbean") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
LOG.info("Mbean Registered: " + invocation.getParameter(0));
mbeanRegistered.release();
return new ObjectInstance((ObjectName)invocation.getParameter(1), "dscription");
return new ObjectInstance((ObjectName)invocation.getParameter(1), "discription");
}
});
atLeast(maxReconnects - 1).of (managementContext).unregisterMBean(with(new NetworkBridgeObjectNameMatcher<ObjectName>(
new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=NetworkBridge,networkConnectorName=NC,networkBridgeName=localhost/127.0.0.1_"
new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_"
+ proxy.getUrl().getPort())))); will(new CustomAction("signal unregister network mbean") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
@ -186,21 +185,22 @@ public class DiscoveryNetworkReconnectTest {
@Test
public void testMulicastReconnect() throws Exception {
brokerB.addNetworkConnector(discoveryAddress + "&discovered.trace=true&discovered.wireFormat.maxInactivityDuration=1000&discovered.wireFormat.maxInactivityDurationInitalDelay=1000");
brokerB.start();
brokerB.waitUntilStarted();
// control multicast advertise agent to inject proxy
agent = MulticastDiscoveryAgentFactory.createDiscoveryAgent(new URI(discoveryAddress));
agent.registerService(proxy.getUrl().toString());
agent.start();
brokerB.addNetworkConnector(discoveryAddress + "&wireFormat.maxInactivityDuration=1000&wireFormat.maxInactivityDurationInitalDelay=1000");
brokerB.start();
brokerB.waitUntilStarted();
doReconnect();
}
@Test
public void testSimpleReconnect() throws Exception {
brokerB.addNetworkConnector("simple://(" + proxy.getUrl()
+ ")?useExponentialBackOff=false&initialReconnectDelay=500&wireFormat.maxInactivityDuration=1000&wireFormat.maxInactivityDurationInitalDelay=1000");
+ ")?useExponentialBackOff=false&initialReconnectDelay=500&discovered.wireFormat.maxInactivityDuration=1000&discovered.wireFormat.maxInactivityDurationInitalDelay=1000");
brokerB.start();
brokerB.waitUntilStarted();
doReconnect();