mirror of https://github.com/apache/activemq.git
[AMQ-8981] Fix CustomBridgeFactoryTest
This commit is contained in:
parent
1afe72e666
commit
82a2374764
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
<networkConnectors>
|
||||
<networkConnector uri="static:(tcp://localhost:61617)" name="networkConnector">
|
||||
<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>
|
||||
</networkConnector>
|
||||
</networkConnectors>
|
||||
|
|
Loading…
Reference in New Issue