use of org.apache.activemq.artemis.jms.client.ActiveMQSession 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) {
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQSession in project activemq-artemis by apache.
the class JMSReconnectTest method testReconnectOrReattachSameNode.
private void testReconnectOrReattachSameNode(boolean reattach) throws Exception {
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
jbcf.setReconnectAttempts(-1);
if (reattach) {
jbcf.setConfirmationWindowSize(1024 * 1024);
}
// Note we set consumer window size to a value so we can verify that consumer credit re-sending
// works properly on failover
// The value is small enough that credits will have to be resent several time
final int numMessages = 10;
final int bodySize = 1000;
jbcf.setConsumerWindowSize(numMessages * bodySize / 10);
Connection conn = jbcf.createConnection();
MyExceptionListener listener = new MyExceptionListener();
conn.setExceptionListener(listener);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
RemotingConnection coreConn = ((ClientSessionInternal) coreSession).getConnection();
SimpleString jmsQueueName = new SimpleString("myqueue");
coreSession.createQueue(jmsQueueName, RoutingType.ANYCAST, jmsQueueName, null, true);
Queue queue = sess.createQueue("myqueue");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
MessageConsumer consumer = sess.createConsumer(queue);
byte[] body = RandomUtil.randomBytes(bodySize);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = sess.createBytesMessage();
bm.writeBytes(body);
producer.send(bm);
}
conn.start();
Thread.sleep(2000);
ActiveMQException me = new ActiveMQNotConnectedException();
coreConn.fail(me);
for (int i = 0; i < numMessages; i++) {
BytesMessage bm = (BytesMessage) consumer.receive(1000);
Assert.assertNotNull(bm);
Assert.assertEquals(body.length, bm.getBodyLength());
}
TextMessage tm = (TextMessage) consumer.receiveNoWait();
Assert.assertNull(tm);
conn.close();
Assert.assertNotNull(listener.e);
Assert.assertTrue(me == listener.e.getCause());
}
use of org.apache.activemq.artemis.jms.client.ActiveMQSession in project activemq-artemis by apache.
the class JMSReconnectTest method testNoReconnectCloseAfterFailToReconnectWithTopicConsumer.
// If the server is shutdown after a non durable sub is created, then close on the connection should proceed normally
@Test
public void testNoReconnectCloseAfterFailToReconnectWithTopicConsumer() throws Exception {
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
jbcf.setReconnectAttempts(0);
Connection conn = jbcf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
coreSession.createQueue("mytopic", "blahblah", null, false);
Topic topic = ActiveMQJMSClient.createTopic("mytopic");
// Create a non durable subscriber
sess.createConsumer(topic);
Thread.sleep(2000);
this.server.stop();
this.server.start();
sess.close();
conn.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQSession in project activemq-artemis by apache.
the class JMSFailoverTest method testCreateQueue.
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testCreateQueue() throws Exception {
liveJMSServer.createQueue(true, "queue1", null, true, "/queue/queue1");
assertNotNull(ctx1.lookup("/queue/queue1"));
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc);
jbcf.setReconnectAttempts(-1);
Connection conn = null;
try {
conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
JMSUtil.crash(liveServer, coreSession);
assertNotNull(ctx2.lookup("/queue/queue1"));
} finally {
if (conn != null) {
conn.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQSession in project activemq-artemis by apache.
the class JMSFailoverTest method testCreateTopic.
@Test
public void testCreateTopic() throws Exception {
liveJMSServer.createTopic(true, "topic", "/topic/t1");
assertNotNull(ctx1.lookup("//topic/t1"));
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc);
jbcf.setReconnectAttempts(-1);
Connection conn = null;
try {
conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
JMSUtil.crash(liveServer, coreSession);
assertNotNull(ctx2.lookup("/topic/t1"));
} finally {
if (conn != null) {
conn.close();
}
}
}
Aggregations