Search in sources :

Example 66 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection 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 67 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class AsynchronousFailoverTest method runTest.

private void runTest(final TestRunner runnable) throws Throwable {
    final int numIts = 1;
    try {
        for (int i = 0; i < numIts; i++) {
            AsynchronousFailoverTest.log.info("Iteration " + i);
            ServerLocator locator = getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(15).setConfirmationWindowSize(10 * 1024 * 1024);
            sf = createSessionFactoryAndWaitForTopology(locator, 2);
            try {
                ClientSession createSession = sf.createSession(true, true);
                createSession.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, (SimpleString) null, true);
                RemotingConnection conn = ((ClientSessionInternal) createSession).getConnection();
                Thread t = new Thread(runnable);
                t.setName("MainTEST");
                t.start();
                long randomDelay = (long) (2000 * Math.random());
                AsynchronousFailoverTest.log.info("Sleeping " + randomDelay);
                Thread.sleep(randomDelay);
                AsynchronousFailoverTest.log.info("Failing asynchronously");
                // Simulate failure on connection
                synchronized (lockFail) {
                    if (log.isDebugEnabled()) {
                        log.debug("#test crashing test");
                    }
                    crash(createSession);
                }
                /*if (listener != null)
               {
                  boolean ok = listener.latch.await(10000, TimeUnit.MILLISECONDS);

                  Assert.assertTrue(ok);
               }*/
                runnable.setFailed();
                AsynchronousFailoverTest.log.info("Fail complete");
                t.join(TimeUnit.SECONDS.toMillis(60));
                if (t.isAlive()) {
                    System.out.println(threadDump("Thread still running from the test"));
                    t.interrupt();
                    fail("Test didn't complete successful, thread still running");
                }
                runnable.checkForExceptions();
                createSession.close();
                Assert.assertEquals(0, sf.numSessions());
                locator.close();
            } finally {
                locator.close();
                Assert.assertEquals(0, sf.numConnections());
            }
            if (i != numIts - 1) {
                tearDown();
                runnable.checkForExceptions();
                runnable.reset();
                setUp();
            }
        }
    } finally {
    }
}
Also used : 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 68 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class PingTest method testNoFailureNoPinging.

/*
    * Test that no failure listeners are triggered in a non failure case with no pinging going on
    */
@Test
public void testNoFailureNoPinging() throws Exception {
    TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
    locator.setClientFailureCheckPeriod(-1);
    locator.setConnectionTTL(-1);
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession(false, true, true);
    Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
    Listener clientListener = new Listener();
    session.addFailureListener(clientListener);
    RemotingConnection serverConn = null;
    while (serverConn == null) {
        Set<RemotingConnection> conns = server.getRemotingService().getConnections();
        if (!conns.isEmpty()) {
            serverConn = server.getRemotingService().getConnections().iterator().next();
        } else {
            // It's async so need to wait a while
            Thread.sleep(10);
        }
    }
    Listener serverListener = new Listener();
    serverConn.addFailureListener(serverListener);
    Thread.sleep(ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD);
    Assert.assertNull(clientListener.getException());
    Assert.assertNull(serverListener.getException());
    RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
    PingTest.log.info("Serverconn2 is " + serverConn2);
    Assert.assertTrue(serverConn == serverConn2);
    session.close();
    csf.close();
    locator.close();
}
Also used : SessionFailureListener(org.apache.activemq.artemis.api.core.client.SessionFailureListener) CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 69 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class OpenwirePluginTest method createServer.

@Override
protected ActiveMQServer createServer(boolean realFiles, Configuration configuration, long pageSize, long maxAddressSize, Map<String, AddressSettings> settings) {
    ActiveMQServer server = super.createServer(realFiles, configuration, pageSize, maxAddressSize, settings);
    server.registerBrokerPlugin(verifier);
    server.registerBrokerPlugin(new ActiveMQServerPlugin() {

        @Override
        public void afterCreateConnection(RemotingConnection connection) throws ActiveMQException {
            try {
                // Verify that calling getClientID() before initialized doesn't cause an error
                // Test for ARTEMIS-1713
                connection.getClientID();
            } catch (Exception e) {
                throw new ActiveMQException(e.getMessage());
            }
        }
    });
    configuration.getAddressesSettings().put("autoCreated", new AddressSettings().setAutoDeleteAddresses(true).setAutoDeleteQueues(true).setAutoCreateQueues(true).setAutoCreateAddresses(true));
    return server;
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) JMSException(javax.jms.JMSException)

Example 70 with RemotingConnection

use of org.apache.activemq.artemis.spi.core.protocol.RemotingConnection in project activemq-artemis by apache.

the class SessionTest method testCloseSessionOnDestroyedConnection.

// Closing a session if the underlying remoting connection is dead should cleanly
// release all resources
@Test
public void testCloseSessionOnDestroyedConnection() throws Exception {
    // Make sure we have a short connection TTL so sessions will be quickly closed on the server
    server.stop();
    long ttl = 500;
    server.getConfiguration().setConnectionTTLOverride(ttl);
    server.start();
    cf = createSessionFactory(locator);
    ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
    clientSession.createQueue(queueName, queueName, false);
    /**
     * keep unused variables in order to maintain references to both objects
     */
    @SuppressWarnings("unused") ClientProducer producer = clientSession.createProducer();
    @SuppressWarnings("unused") ClientConsumer consumer = clientSession.createConsumer(queueName);
    Assert.assertEquals(1, server.getRemotingService().getConnections().size());
    RemotingConnection rc = clientSession.getConnection();
    rc.fail(new ActiveMQInternalErrorException());
    clientSession.close();
    long start = System.currentTimeMillis();
    while (true) {
        int cons = server.getRemotingService().getConnections().size();
        if (cons == 0) {
            break;
        }
        long now = System.currentTimeMillis();
        if (now - start > 10000) {
            throw new Exception("Timed out waiting for connections to close");
        }
        Thread.sleep(50);
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) Test(org.junit.Test)

Aggregations

RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)84 Test (org.junit.Test)44 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)36 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)30 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)22 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)21 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)17 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)15 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)14 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)13 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)12 Connection (javax.jms.Connection)11 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)11 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)11 Session (javax.jms.Session)10