use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class ReattachTest method testImmediateReattach.
/*
* Test failure on connection, but server is still up so should immediately reconnect
*/
@Test
public void testImmediateReattach() throws Exception {
final long retryInterval = 50;
final double retryMultiplier = 1d;
final int reconnectAttempts = 10;
locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
final int numIterations = 10;
for (int j = 0; j < numIterations; j++) {
ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
message.putIntProperty(new SimpleString("count"), i);
message.getBodyBuffer().writeString("aardvarks");
producer.send(message);
}
ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
conn.fail(new ActiveMQNotConnectedException());
session.start();
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(500);
Assert.assertNotNull(message);
Assert.assertEquals("aardvarks", message.getBodyBuffer().readString());
Assert.assertEquals(i, message.getObjectProperty(new SimpleString("count")));
message.acknowledge();
}
ClientMessage message = consumer.receiveImmediate();
Assert.assertNull(message);
producer.close();
consumer.close();
}
session.close();
sf.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class AsynchronousFailoverTest method runTest.
private void runTest(final TestRunner runnable) throws Throwable {
final int numIts = 1;
try {
for (int i = 0; i < numIts; i++) {
AsynchronousFailoverTest.log.info("Iteration " + i);
ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(15).setConfirmationWindowSize(10 * 1024 * 1024);
sf = createSessionFactoryAndWaitForTopology(locator, 2);
try {
ClientSession createSession = sf.createSession(true, true);
createSession.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, (SimpleString) null, true);
RemotingConnection conn = ((ClientSessionInternal) createSession).getConnection();
Thread t = new Thread(runnable);
t.setName("MainTEST");
t.start();
long randomDelay = (long) (2000 * Math.random());
AsynchronousFailoverTest.log.info("Sleeping " + randomDelay);
Thread.sleep(randomDelay);
AsynchronousFailoverTest.log.info("Failing asynchronously");
// Simulate failure on connection
synchronized (lockFail) {
if (log.isDebugEnabled()) {
log.debug("#test crashing test");
}
crash(createSession);
}
/*if (listener != null)
{
boolean ok = listener.latch.await(10000, TimeUnit.MILLISECONDS);
Assert.assertTrue(ok);
}*/
runnable.setFailed();
AsynchronousFailoverTest.log.info("Fail complete");
t.join(TimeUnit.SECONDS.toMillis(60));
if (t.isAlive()) {
System.out.println(threadDump("Thread still running from the test"));
t.interrupt();
fail("Test didn't complete successful, thread still running");
}
runnable.checkForExceptions();
createSession.close();
Assert.assertEquals(0, sf.numSessions());
locator.close();
} finally {
locator.close();
Assert.assertEquals(0, sf.numConnections());
}
if (i != numIts - 1) {
tearDown();
runnable.checkForExceptions();
runnable.reset();
setUp();
}
}
} finally {
}
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class PingTest method testNoFailureNoPinging.
/*
* Test that no failure listeners are triggered in a non failure case with no pinging going on
*/
@Test
public void testNoFailureNoPinging() throws Exception {
TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
locator.setClientFailureCheckPeriod(-1);
locator.setConnectionTTL(-1);
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
Listener clientListener = new Listener();
session.addFailureListener(clientListener);
RemotingConnection serverConn = null;
while (serverConn == null) {
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty()) {
serverConn = server.getRemotingService().getConnections().iterator().next();
} else {
// It's async so need to wait a while
Thread.sleep(10);
}
}
Listener serverListener = new Listener();
serverConn.addFailureListener(serverListener);
Thread.sleep(ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD);
Assert.assertNull(clientListener.getException());
Assert.assertNull(serverListener.getException());
RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
PingTest.log.info("Serverconn2 is " + serverConn2);
Assert.assertTrue(serverConn == serverConn2);
session.close();
csf.close();
locator.close();
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class OpenwirePluginTest method createServer.
@Override
protected ActiveMQServer createServer(boolean realFiles, Configuration configuration, long pageSize, long maxAddressSize, Map<String, AddressSettings> settings) {
ActiveMQServer server = super.createServer(realFiles, configuration, pageSize, maxAddressSize, settings);
server.registerBrokerPlugin(verifier);
server.registerBrokerPlugin(new ActiveMQServerPlugin() {
@Override
public void afterCreateConnection(RemotingConnection connection) throws ActiveMQException {
try {
// Verify that calling getClientID() before initialized doesn't cause an error
// Test for ARTEMIS-1713
connection.getClientID();
} catch (Exception e) {
throw new ActiveMQException(e.getMessage());
}
}
});
configuration.getAddressesSettings().put("autoCreated", new AddressSettings().setAutoDeleteAddresses(true).setAutoDeleteQueues(true).setAutoCreateQueues(true).setAutoCreateAddresses(true));
return server;
}
use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.
the class SessionTest method testCloseSessionOnDestroyedConnection.
// Closing a session if the underlying remoting connection is dead should cleanly
// release all resources
@Test
public void testCloseSessionOnDestroyedConnection() throws Exception {
// Make sure we have a short connection TTL so sessions will be quickly closed on the server
server.stop();
long ttl = 500;
server.getConfiguration().setConnectionTTLOverride(ttl);
server.start();
cf = createSessionFactory(locator);
ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
/**
* keep unused variables in order to maintain references to both objects
*/
@SuppressWarnings("unused") ClientProducer producer = clientSession.createProducer();
@SuppressWarnings("unused") ClientConsumer consumer = clientSession.createConsumer(queueName);
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
RemotingConnection rc = clientSession.getConnection();
rc.fail(new ActiveMQInternalErrorException());
clientSession.close();
long start = System.currentTimeMillis();
while (true) {
int cons = server.getRemotingService().getConnections().size();
if (cons == 0) {
break;
}
long now = System.currentTimeMillis();
if (now - start > 10000) {
throw new Exception("Timed out waiting for connections to close");
}
Thread.sleep(50);
}
}
Aggregations