Merge pull request #899 from mattrpav/AMQ-8981b

[AMQ-8981] Fix CustomBridgeFactoryTest
This commit is contained in:
Jean-Baptiste Onofré 2022-08-23 07:11:58 +02:00 committed by GitHub
commit 81ee88d911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 80 deletions

View File

@ -53,10 +53,17 @@ public class BaseNetworkTest {
} }
protected void doTearDown() throws Exception { protected void doTearDown() throws Exception {
localConnection.close(); if(localConnection != null)
remoteConnection.close(); localConnection.close();
localBroker.stop();
remoteBroker.stop(); if(remoteConnection != null)
remoteConnection.close();
if(localBroker != null)
localBroker.stop();
if(remoteBroker != null)
remoteBroker.stop();
} }
protected void doSetUp(boolean deleteAllMessages) throws Exception { protected void doSetUp(boolean deleteAllMessages) throws Exception {

View File

@ -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<NetworkBridgeListener> 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);
}
}
}

View File

@ -42,7 +42,6 @@ import javax.jms.TextMessage;
/** /**
* Basic test which verify if custom bridge factory receives any interactions when configured. * 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 { public class CustomBridgeFactoryTest extends BaseNetworkTest {
private ActiveMQQueue outgoing = new ActiveMQQueue("outgoing"); 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. * 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 { public void verifyOutgoingCommunication() throws JMSException {
CustomNetworkBridgeFactory bridgeFactory = getCustomNetworkBridgeFactory(); CustomNetworkBridgeFactory bridgeFactory = getCustomNetworkBridgeFactory();
NetworkBridgeListener listener = bridgeFactory.getListener(); 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. * Additional test which makes sure that custom bridge receives notification about broker shutdown.
*/ */
@Test(timeout = 60000) @Test(timeout = 10000)
public void verifyBrokerShutdown() { public void verifyBrokerShutdown() {
shutdownTest(() -> { shutdownTest(() -> {
try { try {
@ -83,7 +82,7 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest {
/** /**
* Verification of network connector shutdown. * Verification of network connector shutdown.
*/ */
@Test(timeout = 60000) @Test(timeout = 10000)
public void verifyConnectorShutdown() { public void verifyConnectorShutdown() {
shutdownTest(() -> { shutdownTest(() -> {
try { try {
@ -145,75 +144,4 @@ public class CustomBridgeFactoryTest extends BaseNetworkTest {
protected String getLocalBrokerURI() { protected String getLocalBrokerURI() {
return "org/apache/activemq/network/localBroker-custom-factory.xml"; 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<NetworkBridgeListener> 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);
}
}
}
} }

View File

@ -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;
}
}

View File

@ -27,7 +27,7 @@
<networkConnectors> <networkConnectors>
<networkConnector uri="static:(tcp://localhost:61617)" name="networkConnector"> <networkConnector uri="static:(tcp://localhost:61617)" name="networkConnector">
<bridgeFactory> <bridgeFactory>
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.network.CustomBridgeFactoryTest.CustomNetworkBridgeFactory" /> <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.network.CustomNetworkBridgeFactory" />
</bridgeFactory> </bridgeFactory>
</networkConnector> </networkConnector>
</networkConnectors> </networkConnectors>