Search in sources :

Example 36 with ActiveMQNotConnectedException

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

the class CoreClientOverOneWaySSLTest method testOneWaySSLWithBadClientCipherSuite.

@Test
public void testOneWaySSLWithBadClientCipherSuite() throws Exception {
    createCustomSslServer();
    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD);
    tc.getParams().put(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME, "myBadCipherSuite");
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
    try {
        createSessionFactory(locator);
        Assert.fail();
    } catch (ActiveMQNotConnectedException e) {
        Assert.assertTrue(true);
    }
}
Also used : ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 37 with ActiveMQNotConnectedException

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

the class CoreClientOverOneWaySSLTest method testOneWaySSLWithBadServerProtocol.

@Test
public void testOneWaySSLWithBadServerProtocol() throws Exception {
    createCustomSslServer(null, "myBadProtocol");
    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD);
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
    try {
        createSessionFactory(locator);
        Assert.fail();
    } catch (ActiveMQNotConnectedException e) {
        Assert.assertTrue(true);
    }
}
Also used : ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 38 with ActiveMQNotConnectedException

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

the class CoreClientOverTwoWaySSLTest method testTwoWaySSLWithoutClientKeyStore.

@Test
public void testTwoWaySSLWithoutClientKeyStore() throws Exception {
    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME, storeType);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, CLIENT_SIDE_TRUSTSTORE);
    tc.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, PASSWORD);
    ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(tc));
    try {
        createSessionFactory(locator);
        Assert.fail();
    } catch (ActiveMQNotConnectedException se) {
    // ok
    } catch (ActiveMQException e) {
        Assert.fail("Invalid Exception type:" + e.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 39 with ActiveMQNotConnectedException

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

the class BridgeReconnectTest method testReconnectSameNode.

// Fail bridge and reconnect same node, no backup specified
@Test
public void testReconnectSameNode() throws Exception {
    server0 = createActiveMQServer(0, isNetty(), server0Params);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    server0.getConfiguration().setConnectorConfigurations(connectors);
    server1.getConfiguration().setConnectorConfigurations(connectors);
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
    ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
    session0 = csf0.createSession(false, true, true);
    ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
    session1 = csf1.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientConsumer cons1 = session1.createConsumer(queueName);
    session1.start();
    // Now we will simulate a failure of the bridge connection between server0 and server1
    Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
    assertNotNull(bridge);
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = reconnectAttempts - 1;
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    final ManagementService managementService = server0.getManagementService();
    QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queueName);
    assertEquals(0, coreQueueControl.getDeliveringCount());
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons1.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) Test(org.junit.Test)

Example 40 with ActiveMQNotConnectedException

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

the class BridgeReconnectTest method testFailoverThenFailAgainAndReconnect.

@Test
public void testFailoverThenFailAgainAndReconnect() throws Exception {
    server0 = createActiveMQServer(0, isNetty(), server0Params);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    server0.getConfiguration().setConnectorConfigurations(connectors);
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
    ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
    session0 = csf0.createSession(false, true, true);
    ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
    session1 = csf1.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientConsumer cons1 = session1.createConsumer(queueName);
    session1.start();
    Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = reconnectAttempts - 1;
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    int outOfOrder = -1;
    int supposed = -1;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons1.receive(1500);
        assertNotNull(r1);
        if (outOfOrder == -1 && i != r1.getIntProperty(propKey).intValue()) {
            outOfOrder = r1.getIntProperty(propKey).intValue();
            supposed = i;
        }
    }
    if (outOfOrder != -1) {
        fail("Message " + outOfOrder + " was received out of order, it was supposed to be " + supposed);
    }
    log.info("=========== second failure, sending message");
    // Fail again - should reconnect
    forwardingConnection = ((BridgeImpl) bridge).getForwardingConnection();
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = reconnectAttempts - 1;
    forwardingConnection.fail(new ActiveMQException(ActiveMQExceptionType.UNBLOCKED));
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons1.receive(1500);
        assertNotNull("Didn't receive message", r1);
        if (outOfOrder == -1 && i != r1.getIntProperty(propKey).intValue()) {
            outOfOrder = r1.getIntProperty(propKey).intValue();
            supposed = i;
        }
    }
    if (outOfOrder != -1) {
        fail("Message " + outOfOrder + " was received out of order, it was supposed to be " + supposed);
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) 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