use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.
the class BrokerQueueNetworkWithDisconnectTest method bridgeBrokers.
@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean dynamicOnly, int networkTTL, boolean conduit, boolean failover) throws Exception {
List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
URI remoteURI;
if (!transportConnectors.isEmpty()) {
remoteURI = transportConnectors.get(0).getConnectUri();
if (useSocketProxy) {
socketProxy = new SocketProxy(remoteURI);
remoteURI = socketProxy.getUrl();
}
DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:(" + remoteURI + "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")?useExponentialBackOff=false"));
connector.setDynamicOnly(dynamicOnly);
connector.setNetworkTTL(networkTTL);
localBroker.addNetworkConnector(connector);
maxSetupTime = 2000;
if (useDuplexNetworkBridge) {
connector.setDuplex(true);
}
return connector;
} else {
throw new Exception("Remote broker has no registered connectors.");
}
}
use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.
the class NetworkAsyncStartTest method testAsyncNetworkStartupWithSlowConnectionCreation.
public void testAsyncNetworkStartupWithSlowConnectionCreation() throws Exception {
final BrokerService brokerA = brokers.get("BrokerA").broker;
SocketProxy proxyToB = new SocketProxy();
// don't accept any connections so limited to one connection with backlog
proxyToB.setPauseAtStart(true);
proxyToB.setAcceptBacklog(1);
proxyToB.setTarget(new URI(brokerBUri));
proxyToB.open();
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, proxyToB.getUrl().toString());
bridgeBroker(brokerA, brokerCUri);
Executor e = Executors.newCachedThreadPool();
e.execute(new Runnable() {
@Override
public void run() {
LOG.info("starting A");
try {
brokerA.setNetworkConnectorStartAsync(true);
brokerA.start();
} catch (Exception e) {
LOG.error("start failed", e);
}
}
});
LOG.info("starting transport connector on C");
BrokerService brokerC = brokers.get("BrokerC").broker;
brokerC.addConnector(brokerCUri);
brokerC.start();
final long maxWaitMillis = 20 * 1000;
assertTrue("got bridge to C in 10 seconds", waitForBridgeFormation(brokerA, 1, 7, maxWaitMillis));
}
use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.
the class AbortSlowConsumer0Test method testAbortConsumerOnDeadConnection.
@Test
public void testAbortConsumerOnDeadConnection() throws Exception {
TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0");
transportConnector.setBrokerService(broker);
transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory());
transportConnector.start();
SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI());
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl());
ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
prefetchPolicy.setAll(4);
connectionFactory.setPrefetchPolicy(prefetchPolicy);
Connection c = connectionFactory.createConnection();
connections.add(c);
c.start();
Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE);
final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
startProducers(destination, 10);
messageconsumer.receive(4000).acknowledge();
assertNotNull(messageconsumer.receive(4000));
assertNotNull(messageconsumer.receive(4000));
assertNotNull(messageconsumer.receive(4000));
// close control command won't get through
socketProxy.pause();
ActiveMQDestination amqDest = (ActiveMQDestination) destination;
ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("DestView {} consumerCount {}", destView, destView.getConsumerCount());
return 0 == destView.getConsumerCount();
}
}));
socketProxy.goOn();
assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
boolean closed = false;
try {
messageconsumer.receive(400);
} catch (javax.jms.IllegalStateException expected) {
closed = expected.toString().contains("closed");
}
return closed;
}
}));
}
use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.
the class DurableSubscriberWithNetworkDisconnectTest method bridgeBrokers.
@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker, boolean l_dynamicOnly, int networkTTL, boolean l_conduit, boolean l_failover) throws Exception {
List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
URI remoteURI;
if (!transportConnectors.isEmpty()) {
remoteURI = transportConnectors.get(0).getConnectUri();
if (useSocketProxy) {
socketProxy = new SocketProxy(remoteURI);
remoteURI = socketProxy.getUrl();
}
String options = "";
if (failover) {
options = "static:(failover:(" + remoteURI;
} else {
options = "static:(" + remoteURI;
}
if (inactivity) {
options += "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")";
} else {
options += ")";
}
if (failover) {
options += "?maxReconnectAttempts=0)";
}
options += "?useExponentialBackOff=" + exponentialBackOff;
DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI(options));
connector.setDynamicOnly(dynamicOnly);
connector.setNetworkTTL(networkTTL);
localBroker.addNetworkConnector(connector);
maxSetupTime = 2000;
if (useDuplexNetworkBridge) {
connector.setDuplex(true);
}
return connector;
} else {
throw new Exception("Remote broker has no registered connectors.");
}
}
use of org.apache.activemq.util.SocketProxy in project activemq-artemis by apache.
the class FailoverTransactionTest method testFailoverConnectionSendReplyLost.
@Test
@BMRules(rules = { @BMRule(name = "set no return response and stop the broker", targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", targetMethod = "processMessage", targetLocation = "EXIT", action = "org.apache.activemq.transport.failover.FailoverTransactionTest.holdResponseAndStopProxyOnFirstSend($0)") })
public void testFailoverConnectionSendReplyLost() throws Exception {
LOG.info(this + " running test testFailoverConnectionSendReplyLost");
broker = createBroker();
proxy = new SocketProxy();
firstSend = true;
startBrokerWithDurableQueue();
proxy.setTarget(new URI(url));
proxy.open();
doByteman.set(true);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + proxy.getUrl().toASCIIString() + ")?jms.watchTopicAdvisories=false");
configureConnectionFactory(cf);
Connection connection = cf.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue destination = session.createQueue(QUEUE_NAME);
MessageConsumer consumer = session.createConsumer(destination);
final CountDownLatch sendDoneLatch = new CountDownLatch(1);
// proxy connection will die on send reply so this will hang on failover reconnect till open
new Thread() {
@Override
public void run() {
LOG.info("doing async send...");
try {
produceMessage(session, destination);
} catch (JMSException e) {
// assertTrue(e instanceof TransactionRolledBackException);
LOG.info("got send exception: ", e);
}
sendDoneLatch.countDown();
LOG.info("done async send");
}
}.start();
// will be closed by the plugin
Assert.assertTrue("proxy was closed", proxy.waitUntilClosed(30));
LOG.info("restarting proxy");
proxy.open();
Assert.assertTrue("message sent through failover", sendDoneLatch.await(30, TimeUnit.SECONDS));
Message msg = consumer.receive(20000);
LOG.info("Received: " + msg);
Assert.assertNotNull("we got the message", msg);
Assert.assertNull("we got just one message", consumer.receive(2000));
consumer.close();
connection.close();
// ensure no dangling messages with fresh broker etc
broker.stop();
LOG.info("Checking for remaining/hung messages with restart..");
broker = createBroker();
broker.start();
// after restart, ensure no dangling messages
cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
configureConnectionFactory(cf);
connection = cf.createConnection();
connection.start();
Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session2.createConsumer(destination);
msg = consumer.receive(1000);
if (msg == null) {
msg = consumer.receive(5000);
}
LOG.info("Received: " + msg);
Assert.assertNull("no messges left dangling but got: " + msg, msg);
connection.close();
proxy.close();
}
Aggregations