Search in sources :

Example 6 with NettyConnector

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.

the class NettyConnectorTest method testStartStop.

@Test
public void testStartStop() throws Exception {
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
    connector.start();
    Assert.assertTrue(connector.isStarted());
    connector.close();
    Assert.assertFalse(connector.isStarted());
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 7 with NettyConnector

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.

the class AmqpOutboundConnectionTest method runOutboundConnectionTest.

private void runOutboundConnectionTest(boolean withSecurity, boolean closeFromClient) throws Exception {
    final ActiveMQServer remote;
    try {
        securityEnabled = withSecurity;
        remote = createServer(AMQP_PORT + 1);
    } finally {
        securityEnabled = false;
    }
    Wait.assertTrue(remote::isActive);
    final Map<String, Object> config = new LinkedHashMap<>();
    config.put(TransportConstants.HOST_PROP_NAME, "localhost");
    config.put(TransportConstants.PORT_PROP_NAME, String.valueOf(AMQP_PORT + 1));
    final ClientSASLFactory clientSASLFactory;
    if (withSecurity) {
        clientSASLFactory = availableMechanims -> {
            if (availableMechanims != null && Arrays.asList(availableMechanims).contains("PLAIN")) {
                return new PlainSASLMechanism(fullUser, fullPass);
            } else {
                return null;
            }
        };
    } else {
        clientSASLFactory = null;
    }
    final AtomicBoolean connectionOpened = new AtomicBoolean();
    EventHandler eventHandler = new EventHandler() {

        @Override
        public void onRemoteOpen(Connection connection) throws Exception {
            connectionOpened.set(true);
        }
    };
    ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, "myid", Collections.singletonMap(Symbol.getSymbol("myprop"), "propvalue"), 5000), Optional.of(eventHandler), clientSASLFactory);
    ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server);
    NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager);
    connector.start();
    Object connectionId = connector.createConnection().getID();
    assertNotNull(connectionId);
    RemotingConnection remotingConnection = lifeCycleListener.getConnection(connectionId);
    AtomicReference<ActiveMQException> ex = new AtomicReference<>();
    AtomicBoolean closed = new AtomicBoolean(false);
    remotingConnection.addCloseListener(() -> closed.set(true));
    remotingConnection.addFailureListener(new FailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
            ex.set(exception);
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            ex.set(exception);
        }
    });
    try {
        Wait.assertEquals(1, remote::getConnectionCount);
        Wait.assertTrue(connectionOpened::get);
        if (closeFromClient) {
            lifeCycleListener.stop();
        } else {
            remote.stop();
        }
        Wait.assertEquals(0, remote::getConnectionCount);
        assertTrue(remotingConnection.isDestroyed());
        if (!closeFromClient) {
            assertTrue(ex.get() instanceof ActiveMQRemoteDisconnectException);
        } else {
            assertNull(ex.get());
        }
    } finally {
        if (closeFromClient) {
            remote.stop();
        } else {
            lifeCycleListener.stop();
        }
    }
}
Also used : ProtonProtocolManagerFactory(org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) EventHandler(org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler) ProtonClientProtocolManager(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager) LinkedHashMap(java.util.LinkedHashMap) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSASLFactory(org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASLFactory) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) Connection(org.apache.qpid.proton.engine.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProtonClientConnectionManager(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientConnectionManager) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AMQPClientConnectionFactory(org.apache.activemq.artemis.protocol.amqp.client.AMQPClientConnectionFactory) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener)

Example 8 with NettyConnector

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.

the class NettyConnectorTest method testConnectionTimeoutConfig.

// make sure the 'connect-timeout' passed to netty.
@Test
public void testConnectionTimeoutConfig() throws Exception {
    final int timeout = 23456;
    TransportConfiguration transport = new TransportConfiguration(NETTY_CONNECTOR_FACTORY);
    transport.getParams().put(TransportConstants.NETTY_CONNECT_TIMEOUT, timeout);
    ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(transport);
    ClientSessionFactoryImpl factory = (ClientSessionFactoryImpl) locator.createSessionFactory();
    NettyConnector connector = (NettyConnector) factory.getConnector();
    Bootstrap bootstrap = connector.getBootStrap();
    assertEquals(timeout, bootstrap.register().channel().config().getConnectTimeoutMillis());
    factory.close();
    locator.close();
}
Also used : ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) Bootstrap(io.netty.bootstrap.Bootstrap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 9 with NettyConnector

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.

the class NettyConnectorTest method testActiveMQSystemPropertyOverrides.

@Test
public void testActiveMQSystemPropertyOverrides() throws Exception {
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    params.put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "bad path");
    params.put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "bad password");
    params.put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "bad path");
    params.put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "bad password");
    NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
    System.setProperty(NettyConnector.JAVAX_KEYSTORE_PATH_PROP_NAME, "bad path");
    System.setProperty(NettyConnector.JAVAX_KEYSTORE_PASSWORD_PROP_NAME, "bad password");
    System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PATH_PROP_NAME, "bad path");
    System.setProperty(NettyConnector.JAVAX_TRUSTSTORE_PASSWORD_PROP_NAME, "bad password");
    System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PATH_PROP_NAME, "client-side-keystore.jks");
    System.setProperty(NettyConnector.ACTIVEMQ_KEYSTORE_PASSWORD_PROP_NAME, "secureexample");
    System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PATH_PROP_NAME, "client-side-truststore.jks");
    System.setProperty(NettyConnector.ACTIVEMQ_TRUSTSTORE_PASSWORD_PROP_NAME, "secureexample");
    connector.start();
    Assert.assertTrue(connector.isStarted());
    connector.close();
    Assert.assertFalse(connector.isStarted());
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 10 with NettyConnector

use of org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector in project activemq-artemis by apache.

the class NettyConnectorTest method testNullParams.

@Test
public void testNullParams() throws Exception {
    BufferHandler handler = new BufferHandler() {

        @Override
        public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
        }
    };
    Map<String, Object> params = new HashMap<>();
    try {
        new NettyConnector(params, null, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
        Assert.fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // Ok
    }
    try {
        new NettyConnector(params, handler, null, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
        Assert.fail("Should throw Exception");
    } catch (IllegalArgumentException e) {
    // Ok
    }
}
Also used : HashMap(java.util.HashMap) NettyConnector(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

NettyConnector (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector)10 Test (org.junit.Test)9 HashMap (java.util.HashMap)6 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)6 BufferHandler (org.apache.activemq.artemis.spi.core.remoting.BufferHandler)6 LinkedHashMap (java.util.LinkedHashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ProtonProtocolManagerFactory (org.apache.activemq.artemis.protocol.amqp.broker.ProtonProtocolManagerFactory)3 AMQPClientConnectionFactory (org.apache.activemq.artemis.protocol.amqp.client.AMQPClientConnectionFactory)3 ProtonClientConnectionManager (org.apache.activemq.artemis.protocol.amqp.client.ProtonClientConnectionManager)3 ProtonClientProtocolManager (org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager)3 EventHandler (org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler)3 ClientSASLFactory (org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASLFactory)3 Connection (javax.jms.Connection)2 ProtonHandler (org.apache.activemq.artemis.protocol.amqp.proton.handler.ProtonHandler)2 ClientSASL (org.apache.activemq.artemis.protocol.amqp.sasl.ClientSASL)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JMSSecurityException (javax.jms.JMSSecurityException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1