use of org.apache.activemq.transport.TransportListener in project fabric8 by jboss-fuse.
the class ServiceFactoryTest method testDeletedStopsBroker.
@Test
public void testDeletedStopsBroker() throws Exception {
underTest = new ActiveMQServiceFactory();
underTest.curator = curator;
Properties props = new Properties();
props.put("config", "amq.xml");
props.put("broker-name", "amq");
props.put("connectors", "openwire");
for (int i = 0; i < 10; i++) {
underTest.updated("b", props);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616)?useExponentialBackOff=false&timeout=10000");
final ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
connection.start();
assertTrue("is connected", connection.getTransport().isConnected());
final CountDownLatch interrupted = new CountDownLatch(1);
connection.getTransport().setTransportListener(new TransportListener() {
@Override
public void onCommand(Object o) {
}
@Override
public void onException(IOException e) {
}
@Override
public void transportInterupted() {
interrupted.countDown();
}
@Override
public void transportResumed() {
}
});
underTest.deleted("b");
assertTrue("Broker stopped - failover transport interrupted", interrupted.await(5, TimeUnit.SECONDS));
connection.close();
}
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class FailoverTransactionTest method testPoolingNConsumesAfterReconnect.
@Test
@BMRules(rules = { @BMRule(name = "set no return response and stop the broker", targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", targetMethod = "processRemoveConsumer", targetLocation = "ENTRY", action = "org.apache.activemq.transport.failover.FailoverTransactionTest.stopBrokerOnCounter()") })
public void testPoolingNConsumesAfterReconnect() throws Exception {
LOG.info(this + " running test testPoolingNConsumesAfterReconnect");
count = 0;
broker = createBroker();
startBrokerWithDurableQueue();
doByteman.set(true);
Vector<Connection> connections = new Vector<>();
final ExecutorService executorService = Executors.newCachedThreadPool();
try {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
configureConnectionFactory(cf);
Connection connection = cf.createConnection();
connection.start();
Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue destination = producerSession.createQueue(QUEUE_NAME + "?consumer.prefetchSize=1");
produceMessage(producerSession, destination);
connection.close();
connection = cf.createConnection();
connection.start();
connections.add(connection);
final Session consumerSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
final int sessionCount = 10;
final Stack<Session> sessions = new Stack<>();
for (int i = 0; i < sessionCount; i++) {
sessions.push(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
}
final int consumerCount = 1000;
final Deque<MessageConsumer> consumers = new ArrayDeque<>();
for (int i = 0; i < consumerCount; i++) {
consumers.push(consumerSession.createConsumer(destination));
}
final FailoverTransport failoverTransport = ((ActiveMQConnection) connection).getTransport().narrow(FailoverTransport.class);
final TransportListener delegate = failoverTransport.getTransportListener();
failoverTransport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
delegate.onCommand(command);
}
@Override
public void onException(IOException error) {
delegate.onException(error);
}
@Override
public void transportInterupted() {
LOG.error("Transport interrupted: " + failoverTransport, new RuntimeException("HERE"));
for (int i = 0; i < consumerCount && !consumers.isEmpty(); i++) {
executorService.execute(new Runnable() {
@Override
public void run() {
MessageConsumer localConsumer = null;
try {
synchronized (delegate) {
localConsumer = consumers.pop();
}
localConsumer.receive(1);
LOG.info("calling close() " + ((ActiveMQMessageConsumer) localConsumer).getConsumerId());
localConsumer.close();
} catch (NoSuchElementException nse) {
} catch (Exception ignored) {
LOG.error("Ex on: " + ((ActiveMQMessageConsumer) localConsumer).getConsumerId(), ignored);
}
}
});
}
delegate.transportInterupted();
}
@Override
public void transportResumed() {
delegate.transportResumed();
}
});
MessageConsumer consumer = null;
synchronized (delegate) {
consumer = consumers.pop();
}
LOG.info("calling close to trigger broker stop " + ((ActiveMQMessageConsumer) consumer).getConsumerId());
consumer.close();
LOG.info("waiting latch: " + brokerStopLatch.getCount());
// will be stopped by the plugin
Assert.assertTrue(brokerStopLatch.await(60, TimeUnit.SECONDS));
doByteman.set(false);
broker = createBroker();
broker.start();
consumer = consumerSession.createConsumer(destination);
LOG.info("finally consuming message: " + ((ActiveMQMessageConsumer) consumer).getConsumerId());
Message msg = null;
for (int i = 0; i < 4 && msg == null; i++) {
msg = consumer.receive(1000);
}
LOG.info("post: from consumer1 received: " + msg);
Assert.assertNotNull("got message after failover", msg);
msg.acknowledge();
} finally {
executorService.shutdown();
for (Connection c : connections) {
c.close();
}
}
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class FailoverTransportBrokerTest method testNoBrokersInBrokerInfo.
public void testNoBrokersInBrokerInfo() throws Exception {
final BrokerInfo[] info = new BrokerInfo[1];
TransportListener listener = new TransportListener() {
@Override
public void onCommand(Object command) {
LOG.info("Got command: " + command);
if (command instanceof BrokerInfo) {
info[0] = (BrokerInfo) command;
}
}
@Override
public void onException(IOException error) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void transportInterupted() {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void transportResumed() {
// To change body of implemented methods use File | Settings | File Templates.
}
};
@SuppressWarnings("unused") StubConnection c = createFailoverConnection(listener);
int count = 0;
while (count++ < 20 && info[0] == null) {
TimeUnit.SECONDS.sleep(1);
}
Assert.assertNotNull("got a valid brokerInfo after 20 secs", info[0]);
Assert.assertNull("no peer brokers present", info[0].getPeerBrokerInfos());
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class FailoverTransportTest method testLocalhostPortSyntax.
@Test
public void testLocalhostPortSyntax() throws Exception {
transport = TransportFactory.connect(new URI("failover://(tcp://localhost:1111/localhost:2111)"));
transport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
}
@Override
public void onException(IOException error) {
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
failoverTransport = transport.narrow(FailoverTransport.class);
transport.start();
}
use of org.apache.activemq.transport.TransportListener in project activemq-artemis by apache.
the class FailoverTransportTest method testReconnectUnlimited.
@Test(timeout = 30000)
@Ignore("Test fails on windows")
public void testReconnectUnlimited() throws Exception {
Transport transport = TransportFactory.connect(new URI("failover://(tcp://0.0.0.0:61616)?useExponentialBackOff=false&reconnectDelay=0&initialReconnectDelay=0"));
transport.setTransportListener(new TransportListener() {
@Override
public void onCommand(Object command) {
}
@Override
public void onException(IOException error) {
}
@Override
public void transportInterupted() {
}
@Override
public void transportResumed() {
}
});
transport.start();
this.failoverTransport = transport.narrow(FailoverTransport.class);
assertTrue("no implicit limit of 1000", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return failoverTransport.getConnectFailures() > 1002;
}
}));
}
Aggregations