use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class SessionTest method testGetNodeId.
@Test
public void testGetNodeId() throws Exception {
cf = createSessionFactory(locator);
ClientSession clientSession = addClientSession(cf.createSession(false, true, true));
String nodeId = ((ClientSessionInternal) clientSession).getNodeId();
assertNotNull(nodeId);
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal 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);
}
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ExceptionListenerTest method testListenerCalledForOneConnectionAndSessions.
@Test
public void testListenerCalledForOneConnectionAndSessions() throws Exception {
Connection conn = cf.createConnection();
CountDownLatch latch = new CountDownLatch(1);
MyExceptionListener listener = new MyExceptionListener(latch);
conn.setExceptionListener(listener);
Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sess3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSessionInternal coreSession0 = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession();
ClientSessionInternal coreSession1 = (ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession();
ClientSessionInternal coreSession2 = (ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession();
ClientSessionInternal coreSession3 = (ClientSessionInternal) ((ActiveMQSession) sess3).getCoreSession();
coreSession0.getConnection().fail(new ActiveMQInternalErrorException("blah"));
coreSession1.getConnection().fail(new ActiveMQInternalErrorException("blah"));
coreSession2.getConnection().fail(new ActiveMQInternalErrorException("blah"));
coreSession3.getConnection().fail(new ActiveMQInternalErrorException("blah"));
latch.await(5, TimeUnit.SECONDS);
// Listener should only be called once even if all sessions connections die
Assert.assertEquals(1, listener.numCalls);
conn.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class ExceptionListenerTest method testListenerCalledForOneConnection.
@Test
public void testListenerCalledForOneConnection() throws Exception {
Connection conn = cf.createConnection();
CountDownLatch latch = new CountDownLatch(1);
MyExceptionListener listener = new MyExceptionListener(latch);
conn.setExceptionListener(listener);
ClientSessionInternal coreSession = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession();
coreSession.getConnection().fail(new ActiveMQInternalErrorException("blah"));
latch.await(5, TimeUnit.SECONDS);
Assert.assertEquals(1, listener.numCalls);
conn.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal in project activemq-artemis by apache.
the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
List<TransportConfiguration> connectorConfigs = new ArrayList<>();
connectorConfigs.add(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jmsServer.createConnectionFactory("cffoo", false, JMSFactoryType.CF, registerConnectors(server, connectorConfigs), null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, 0, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/cffoo");
cf = (ConnectionFactory) namingContext.lookup("/cffoo");
Connection conn = cf.createConnection();
Queue queue = createQueue("testQueue");
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue);
MessageConsumer cons = session.createConsumer(queue);
conn.start();
prod.send(session.createMessage());
Assert.assertNotNull(cons.receive());
// Now fail the underlying connection
RemotingConnection connection = ((ClientSessionInternal) ((ActiveMQSession) session).getCoreSession()).getConnection();
connection.fail(new ActiveMQNotConnectedException());
try {
prod.send(session.createMessage());
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
try {
cons.receive();
Assert.fail("Should throw exception");
} catch (JMSException e) {
// assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
}
session.close();
conn.close();
} finally {
try {
conn.close();
} catch (Throwable igonred) {
}
}
}
Aggregations