Search in sources :

Example 46 with ClientSessionInternal

use of org.apache.activemq.artemis.core.client.impl.ClientSessionInternal 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());
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) MessageConsumer(javax.jms.MessageConsumer) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) BytesMessage(javax.jms.BytesMessage) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession)

Aggregations

ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)46 Test (org.junit.Test)35 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)21 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)20 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 Connection (javax.jms.Connection)12 Session (javax.jms.Session)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)11 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)10 MessageConsumer (javax.jms.MessageConsumer)8 MessageProducer (javax.jms.MessageProducer)8 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 TextMessage (javax.jms.TextMessage)7 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)7 XAConnection (javax.jms.XAConnection)5 XASession (javax.jms.XASession)5