Search in sources :

Example 1 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.

the class FailureDeadlockTest method testUsingDeadConnection.

// https://jira.jboss.org/jira/browse/JBMESSAGING-1703
// Make sure that failing a connection removes it from the connection manager and can't be returned in a subsequent
// call
@Test
public void testUsingDeadConnection() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Connection conn1 = cf1.createConnection();
        Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection();
        rc1.fail(new ActiveMQNotConnectedException("blah"));
        try {
            conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Assert.fail("should throw exception");
        } catch (JMSException e) {
        // pass
        }
        conn1.close();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) Test(org.junit.Test)

Example 2 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.

the class GroupingTest method testGroupingRollbackOnClose.

@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.server.impl.ServerSessionImpl", targetMethod = "rollback", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.GroupingTest.pause();") })
public void testGroupingRollbackOnClose() throws Exception {
    Connection sendConnection = null;
    Connection connection = null;
    Connection connection2 = null;
    try {
        ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
        fact.setReconnectAttempts(0);
        // fact.setConsumerWindowSize(1000);
        // fact.setTransactionBatchSize(0);
        connection = fact.createConnection();
        RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
        connection2 = fact.createConnection();
        sendConnection = fact.createConnection();
        final Session sendSession = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
        final MessageProducer producer = sendSession.createProducer(queue);
        MessageConsumer consumer1 = session.createConsumer(queue);
        MessageConsumer consumer2 = session2.createConsumer(queue);
        connection.start();
        connection2.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    for (int j = 0; j < 10000; j++) {
                        TextMessage message = sendSession.createTextMessage();
                        message.setText("Message" + j);
                        message.setStringProperty("JMSXGroupID", "foo");
                        producer.send(message);
                    }
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
        // consume 5 msgs from 1st first consumer
        for (int j = 0; j < 5; j++) {
            TextMessage tm = (TextMessage) consumer1.receive(10000);
            assertNotNull(tm);
            assertEquals("Message" + j, tm.getText());
            assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
        }
        pause = true;
        rc.fail(new ActiveMQNotConnectedException());
        pause = false;
        for (int j = 0; j < 10000; j++) {
            TextMessage tm = (TextMessage) consumer2.receive(5000);
            assertNotNull(tm);
            assertEquals("Message" + j, tm.getText());
            assertEquals(tm.getStringProperty("JMSXGroupID"), "foo");
        }
    } finally {
        if (sendConnection != null) {
            sendConnection.close();
        }
        if (connection2 != null) {
            connection2.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) JMSException(javax.jms.JMSException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 3 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.

the class GroupingTest method testGroupingRollbackOnClose.

@Test
public void testGroupingRollbackOnClose() throws Exception {
    ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
    fact.setConsumerWindowSize(1000);
    fact.setTransactionBatchSize(0);
    Connection connection = fact.createConnection();
    RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
    Connection connection2 = fact.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(queue);
    MessageConsumer consumer1 = session.createConsumer(queue);
    MessageConsumer consumer2 = session2.createConsumer(queue);
    connection.start();
    connection2.start();
    String jmsxgroupID = null;
    for (int j = 0; j < 100; j++) {
        TextMessage message = session.createTextMessage();
        message.setText("Message" + j);
        setProperty(message);
        producer.send(message);
        String prop = message.getStringProperty("JMSXGroupID");
        assertNotNull(prop);
        if (jmsxgroupID != null) {
            assertEquals(jmsxgroupID, prop);
        } else {
            jmsxgroupID = prop;
        }
    }
    session.commit();
    // consume 5 msgs from 1st first consumer
    for (int j = 0; j < 1; j++) {
        TextMessage tm = (TextMessage) consumer1.receive(10000);
        assertNotNull(tm);
        assertEquals("Message" + j, tm.getText());
        assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
    }
    Thread.sleep(2000);
    // session.rollback();
    // session.close();
    // consume all msgs from 2nd first consumer
    // ClientSession amqs = ((ActiveMQSession) session).getCoreSession();
    // ((DelegatingSession) amqs).getChannel().close();
    rc.fail(new ActiveMQNotConnectedException());
    for (int j = 0; j < 10; j++) {
        TextMessage tm = (TextMessage) consumer2.receive(10000);
        assertNotNull(tm);
        long text = ((ActiveMQTextMessage) tm).getCoreMessage().getMessageID();
        System.out.println(tm.getJMSMessageID() + " text = " + text);
        // assertEquals("Message" + j, text);
        assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
    }
    connection.close();
    connection2.close();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) MessageProducer(javax.jms.MessageProducer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TextMessage(javax.jms.TextMessage) ActiveMQTextMessage(org.apache.activemq.artemis.jms.client.ActiveMQTextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 4 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.

the class ReattachTest method testReattachAttemptsFailsToReconnect.

@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 3;
    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);
    ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
    final int numMessages = 1000;
    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);
    }
    session.createConsumer(ReattachTest.ADDRESS);
    InVMConnector.failOnCreateConnection = true;
    RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    // Sleep for longer than max retries so should fail to reconnect
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(retryInterval * (reconnectAttempts + 1));
            } catch (InterruptedException ignore) {
            }
            InVMConnector.failOnCreateConnection = false;
        }
    };
    t.start();
    conn.fail(new ActiveMQNotConnectedException());
    try {
        session.start();
        Assert.fail("Should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
    sf.close();
    t.join();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 5 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException in project activemq-artemis by apache.

the class ReattachTest method testCreateQueue.

@Test
public void testCreateQueue() throws Exception {
    final long retryInterval = 100;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 300;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    // Sleep 3 times retryInterval, so it should at least have 3 retries
    RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    InVMConnector.failOnCreateConnection = false;
    conn.fail(new ActiveMQNotConnectedException());
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(retryInterval * 3);
            } catch (InterruptedException ignore) {
            }
            InVMConnector.failOnCreateConnection = false;
        }
    };
    t.start();
    for (int i = 0; i < 10; i++) {
        session.createQueue("address", RoutingType.ANYCAST, "queue" + i);
    }
    // 
    // InVMConnector.failOnCreateConnection = true;
    // 
    // //Should throw exception since didn't reconnect
    // 
    // try
    // {
    // session.start();
    // 
    // fail("Should throw exception");
    // }
    // catch (ActiveMQException e)
    // {
    // assertEquals(ActiveMQException.OBJECT_CLOSED, e.getCode());
    // }
    session.close();
    sf.close();
    t.join();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) Test(org.junit.Test)

Aggregations

ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)44 Test (org.junit.Test)38 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)20 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)19 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)19 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)16 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)15 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)14 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)14 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)11 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)11 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)6 Connection (javax.jms.Connection)5 Session (javax.jms.Session)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 MessageConsumer (javax.jms.MessageConsumer)4 MessageProducer (javax.jms.MessageProducer)4 Message (org.apache.activemq.artemis.api.core.Message)4