Search in sources :

Example 21 with ActiveMQNotConnectedException

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

the class ServerLocatorConnectTest method testMultipleConnectorSingleServerNoConnect.

@Test
public void testMultipleConnectorSingleServerNoConnect() throws Exception {
    ServerLocatorInternal locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(1, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(2, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(3, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(4, isNetty())), createTransportConfiguration(isNetty(), false, generateParams(5, isNetty())));
    ClientSessionFactoryInternal csf = null;
    try {
        csf = locator.connect();
    } catch (ActiveMQNotConnectedException nce) {
    // ok
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        fail("Invalid Exception type:" + ((ActiveMQException) e).getType());
    }
    assertNull(csf);
    locator.close();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 22 with ActiveMQNotConnectedException

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

the class OrderReattachTest method doTestOrderOnSend.

public void doTestOrderOnSend(final boolean isNetty) throws Throwable {
    server = createServer(false, isNetty);
    server.start();
    ServerLocator locator = createFactory(isNetty).setReconnectAttempts(15).setConfirmationWindowSize(1024 * 1024).setBlockOnNonDurableSend(false).setBlockOnAcknowledge(false);
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, true, true);
    final LinkedBlockingDeque<Boolean> failureQueue = new LinkedBlockingDeque<>();
    final CountDownLatch ready = new CountDownLatch(1);
    // this test will use a queue. Whenever the test wants a failure.. it can just send TRUE to failureQueue
    // This Thread will be reading the queue
    Thread failer = new Thread() {

        @Override
        public void run() {
            ready.countDown();
            while (true) {
                try {
                    Boolean poll = false;
                    try {
                        poll = failureQueue.poll(60, TimeUnit.SECONDS);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        break;
                    }
                    Thread.sleep(1);
                    final RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection();
                    // True means... fail session
                    if (poll) {
                        conn.fail(new ActiveMQNotConnectedException("poop"));
                    } else {
                        // false means... finish thread
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };
    failer.start();
    ready.await();
    try {
        doSend2(1, sf, failureQueue);
    } finally {
        try {
            session.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            locator.close();
        } catch (Exception e) {
        // 
        }
        try {
            sf.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        failureQueue.put(false);
        failer.join();
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) RemotingConnectionImpl(org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl) CountDownLatch(java.util.concurrent.CountDownLatch) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)

Example 23 with ActiveMQNotConnectedException

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

the class ReattachTest method testAsyncFailureWhileReattaching.

// Test an async (e.g. pinger) failure coming in while a connection manager is already reconnecting
@Test
public void testAsyncFailureWhileReattaching() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 60;
    final long asyncFailDelay = 200;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    ClientSession session2 = sf.createSession(false, true, true);
    class MyFailureListener implements SessionFailureListener {

        volatile boolean failed;

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver) {
            failed = true;
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }

        @Override
        public void beforeReconnect(final ActiveMQException exception) {
        }
    }
    MyFailureListener listener = new MyFailureListener();
    session2.addFailureListener(listener);
    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.numberOfFailures = 10;
    InVMConnector.failOnCreateConnection = true;
    final RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    final RemotingConnection conn2 = ((ClientSessionInternal) session2).getConnection();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(asyncFailDelay);
            } catch (InterruptedException ignore) {
            }
            conn2.fail(new ActiveMQNotConnectedException("Did not receive pong from server"));
        }
    };
    t.start();
    conn.fail(new ActiveMQNotConnectedException());
    Assert.assertTrue(listener.failed);
    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.getIntProperty("count").intValue());
        message.acknowledge();
    }
    ClientMessage message = consumer.receiveImmediate();
    Assert.assertNull(message);
    session.close();
    session2.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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) 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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 24 with ActiveMQNotConnectedException

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

the class ReattachTest method testExponentialBackoffMaxRetryInterval.

@Test
public void testExponentialBackoffMaxRetryInterval() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 2d;
    final int reconnectAttempts = 60;
    final long maxRetryInterval = 100;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setMaxRetryInterval(maxRetryInterval).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.getIntProperty("count").intValue());
        message.acknowledge();
    }
    ClientMessage message = consumer.receiveImmediate();
    Assert.assertNull(message);
    long end = System.currentTimeMillis();
    double wait = retryInterval + retryMultiplier * 2 * retryInterval + retryMultiplier;
    Assert.assertTrue(end - start >= wait);
    Assert.assertTrue(end - start < wait + 500);
    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 25 with ActiveMQNotConnectedException

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

the class ReattachTest method testCreateSessionFailAfterSendSeveralThreads.

@Test
public void testCreateSessionFailAfterSendSeveralThreads() throws Throwable {
    Timer timer = new Timer();
    ClientSession session = null;
    try {
        final long retryInterval = 100;
        final double retryMultiplier = 1d;
        final int reconnectAttempts = 300;
        locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
        final ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
        session = sf.createSession();
        final RemotingConnection connFailure = ((ClientSessionInternal) session).getConnection();
        int numberOfThreads = 100;
        final int numberOfSessionsToCreate = 10;
        final CountDownLatch alignLatch = new CountDownLatch(numberOfThreads);
        final CountDownLatch startFlag = new CountDownLatch(1);
        class CreateSessionThread extends Thread {

            Throwable failure;

            @Override
            public void run() {
                try {
                    alignLatch.countDown();
                    startFlag.await();
                    for (int i = 0; i < numberOfSessionsToCreate; i++) {
                        Thread.yield();
                        ClientSession session = sf.createSession(false, true, true);
                        session.close();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    failure = e;
                }
            }
        }
        CreateSessionThread[] threads = new CreateSessionThread[numberOfThreads];
        for (int i = 0; i < numberOfThreads; i++) {
            threads[i] = new CreateSessionThread();
            threads[i].start();
        }
        waitForLatch(alignLatch);
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                try {
                    connFailure.fail(new ActiveMQNotConnectedException());
                } catch (Exception e) {
                    ReattachTest.log.warn("Error on the timer " + e);
                }
            }
        }, 10, 10);
        startFlag.countDown();
        Throwable failure = null;
        for (CreateSessionThread thread : threads) {
            thread.join();
            if (thread.failure != null) {
                System.out.println("Thread " + thread.getName() + " failed - " + thread.failure);
                failure = thread.failure;
            }
        }
        if (failure != null) {
            throw failure;
        }
        sf.close();
    } finally {
        timer.cancel();
        if (session != null) {
            session.close();
        }
    }
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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