diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/BaseNetworkTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/BaseNetworkTest.java index e5cd967f6f..161591420a 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/BaseNetworkTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/BaseNetworkTest.java @@ -53,10 +53,17 @@ public class BaseNetworkTest { } protected void doTearDown() throws Exception { - localConnection.close(); - remoteConnection.close(); - localBroker.stop(); - remoteBroker.stop(); + if(localConnection != null) + localConnection.close(); + + if(remoteConnection != null) + remoteConnection.close(); + + if(localBroker != null) + localBroker.stop(); + + if(remoteBroker != null) + remoteBroker.stop(); } protected void doSetUp(boolean deleteAllMessages) throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompositeNetworkBridgeListener.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompositeNetworkBridgeListener.java new file mode 100644 index 0000000000..e9fdfcf38e --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CompositeNetworkBridgeListener.java @@ -0,0 +1,49 @@ +package org.apache.activemq.network; + +import java.util.Arrays; +import java.util.List; + +import org.apache.activemq.command.Message; + +public class CompositeNetworkBridgeListener implements NetworkBridgeListener { + private final List listeners; + + public CompositeNetworkBridgeListener(NetworkBridgeListener... wrapped) { + this.listeners = Arrays.asList(wrapped); + } + + @Override + public void bridgeFailed() { + for (NetworkBridgeListener listener : listeners) { + listener.bridgeFailed(); + } + } + + @Override + public void onStart(NetworkBridge bridge) { + for (NetworkBridgeListener listener : listeners) { + listener.onStart(bridge); + } + } + + @Override + public void onStop(NetworkBridge bridge) { + for (NetworkBridgeListener listener : listeners) { + listener.onStop(bridge); + } + } + + @Override + public void onOutboundMessage(NetworkBridge bridge, Message message) { + for (NetworkBridgeListener listener : listeners) { + listener.onOutboundMessage(bridge, message); + } + } + + @Override + public void onInboundMessage(NetworkBridge bridge, Message message) { + for (NetworkBridgeListener listener : listeners) { + listener.onInboundMessage(bridge, message); + } + } +} diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomBridgeFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomBridgeFactoryTest.java index c142253526..79dedab3b0 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomBridgeFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomBridgeFactoryTest.java @@ -42,7 +42,6 @@ import javax.jms.TextMessage; /** * Basic test which verify if custom bridge factory receives any interactions when configured. */ -@Ignore // AMQ-8977 -- can't find class due to xbean or mockito upgrade public class CustomBridgeFactoryTest extends BaseNetworkTest { private ActiveMQQueue outgoing = new ActiveMQQueue("outgoing"); @@ -50,7 +49,7 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest { /** * Verification of outgoing communication - from local broker (with customized bridge configured) to remote one. */ - @Test(timeout = 60000) + @Test(timeout = 10000) public void verifyOutgoingCommunication() throws JMSException { CustomNetworkBridgeFactory bridgeFactory = getCustomNetworkBridgeFactory(); NetworkBridgeListener listener = bridgeFactory.getListener(); @@ -68,7 +67,7 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest { /** * Additional test which makes sure that custom bridge receives notification about broker shutdown. */ - @Test(timeout = 60000) + @Test(timeout = 10000) public void verifyBrokerShutdown() { shutdownTest(() -> { try { @@ -83,7 +82,7 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest { /** * Verification of network connector shutdown. */ - @Test(timeout = 60000) + @Test(timeout = 10000) public void verifyConnectorShutdown() { shutdownTest(() -> { try { @@ -145,75 +144,4 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest { protected String getLocalBrokerURI() { return "org/apache/activemq/network/localBroker-custom-factory.xml"; } - - // test classes - static class CustomNetworkBridgeFactory implements BridgeFactory { - - private final NetworkBridgeListener listener; - - CustomNetworkBridgeFactory() { - this(Mockito.mock(NetworkBridgeListener.class)); - } - - CustomNetworkBridgeFactory(NetworkBridgeListener listener) { - this.listener = listener; - } - - public NetworkBridgeListener getListener() { - return listener; - } - - @Override - public DemandForwardingBridge createNetworkBridge(NetworkBridgeConfiguration configuration, Transport localTransport, Transport remoteTransport, NetworkBridgeListener listener) { - DemandForwardingBridge bridge = new DemandForwardingBridge(configuration, localTransport, remoteTransport); - bridge.setNetworkBridgeListener(new CompositeNetworkBridgeListener(this.listener, listener)); - return bridge; - } - - } - - static class CompositeNetworkBridgeListener implements NetworkBridgeListener { - - private final List listeners; - - public CompositeNetworkBridgeListener(NetworkBridgeListener ... wrapped) { - this.listeners = Arrays.asList(wrapped); - } - - @Override - public void bridgeFailed() { - for (NetworkBridgeListener listener : listeners) { - listener.bridgeFailed(); - } - } - - @Override - public void onStart(NetworkBridge bridge) { - for (NetworkBridgeListener listener : listeners) { - listener.onStart(bridge); - } - } - - @Override - public void onStop(NetworkBridge bridge) { - for (NetworkBridgeListener listener : listeners) { - listener.onStop(bridge); - } - } - - @Override - public void onOutboundMessage(NetworkBridge bridge, Message message) { - for (NetworkBridgeListener listener : listeners) { - listener.onOutboundMessage(bridge, message); - } - } - - @Override - public void onInboundMessage(NetworkBridge bridge, Message message) { - for (NetworkBridgeListener listener : listeners) { - listener.onInboundMessage(bridge, message); - } - } - } - } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomNetworkBridgeFactory.java b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomNetworkBridgeFactory.java new file mode 100644 index 0000000000..eecefe1aa4 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/network/CustomNetworkBridgeFactory.java @@ -0,0 +1,29 @@ +package org.apache.activemq.network; + +import org.apache.activemq.transport.Transport; +import org.mockito.Mockito; + +public class CustomNetworkBridgeFactory implements BridgeFactory { + + private final NetworkBridgeListener listener; + + public CustomNetworkBridgeFactory() { + this(Mockito.mock(NetworkBridgeListener.class)); + } + + public CustomNetworkBridgeFactory(NetworkBridgeListener listener) { + this.listener = listener; + } + + public NetworkBridgeListener getListener() { + return listener; + } + + @Override + public DemandForwardingBridge createNetworkBridge(NetworkBridgeConfiguration configuration, Transport localTransport, Transport remoteTransport, NetworkBridgeListener listener) { + DemandForwardingBridge bridge = new DemandForwardingBridge(configuration, localTransport, remoteTransport); + bridge.setNetworkBridgeListener(new CompositeNetworkBridgeListener(this.listener, listener)); + return bridge; + } + + } diff --git a/activemq-unit-tests/src/test/resources/org/apache/activemq/network/localBroker-custom-factory.xml b/activemq-unit-tests/src/test/resources/org/apache/activemq/network/localBroker-custom-factory.xml index 9dc8c61beb..d8f30fe87e 100644 --- a/activemq-unit-tests/src/test/resources/org/apache/activemq/network/localBroker-custom-factory.xml +++ b/activemq-unit-tests/src/test/resources/org/apache/activemq/network/localBroker-custom-factory.xml @@ -27,7 +27,7 @@ - +