Search in sources :

Example 26 with ActiveMQNotConnectedException

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

the class ReattachTest method testExponentialBackoff.

@Test
public void testExponentialBackoff() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 2d;
    final int reconnectAttempts = 60;
    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);
    }
    ClientConsumer consumer = session.createConsumer(ReattachTest.ADDRESS);
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = 3;
    RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    long start = System.currentTimeMillis();
    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);
    long end = System.currentTimeMillis();
    double wait = retryInterval + retryMultiplier * retryInterval + retryMultiplier * retryMultiplier * retryInterval;
    Assert.assertTrue(end - start >= wait);
    session.close();
    sf.close();
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 27 with ActiveMQNotConnectedException

use of org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException 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();
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 28 with ActiveMQNotConnectedException

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

the class NettyAsynchronousReattachTest method crash.

@Override
protected void crash(final ClientSession... sessions) throws Exception {
    for (ClientSession session : sessions) {
        log.debug("Crashing session " + session);
        ClientSessionInternal internalSession = (ClientSessionInternal) session;
        internalSession.getConnection().fail(new ActiveMQNotConnectedException("oops"));
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)

Example 29 with ActiveMQNotConnectedException

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

the class FailoverWithSharedStoreTest method testNoConnection.

@Test
public void testNoConnection() throws Exception {
    ServerLocator locator = ActiveMQClient.createServerLocatorWithHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
    try {
        createSessionFactory(locator);
        fail();
    } catch (ActiveMQNotConnectedException nce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 30 with ActiveMQNotConnectedException

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

the class ConnectionLimitTest method testInVMConnectionLimit.

@Test
public void testInVMConnectionLimit() throws Exception {
    ServerLocator locator = addServerLocator(createNonHALocator(false));
    ClientSessionFactory clientSessionFactory = locator.createSessionFactory();
    try {
        ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
        fail("creating a session factory here should fail");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQNotConnectedException);
    }
}
Also used : ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQConnectionTimedOutException(org.apache.activemq.artemis.api.core.ActiveMQConnectionTimedOutException) 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