Search in sources :

Example 21 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class ClusterTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    forceGC();
    ActiveMQTestBase.checkFreePort(ClusterTestBase.PORTS);
    consumers = new ConsumerHolder[ClusterTestBase.MAX_CONSUMERS];
    servers = new ActiveMQServer[ClusterTestBase.MAX_SERVERS];
    timeStarts = new long[ClusterTestBase.MAX_SERVERS];
    sfs = new ClientSessionFactory[ClusterTestBase.MAX_SERVERS];
    nodeManagers = new NodeManager[ClusterTestBase.MAX_SERVERS];
    for (int i = 0, nodeManagersLength = nodeManagers.length; i < nodeManagersLength; i++) {
        nodeManagers[i] = new InVMNodeManager(isSharedStore(), new File(getJournalDir(i, true)));
    }
    locators = new ServerLocator[ClusterTestBase.MAX_SERVERS];
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) File(java.io.File) Before(org.junit.Before)

Example 22 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class BridgeReconnectTest method testFailoverAndReconnectImmediately.

// Fail bridge and reconnecting immediately
@Test
public void testFailoverAndReconnectImmediately() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    server0 = createActiveMQServer(0, server0Params, isNetty(), nodeManager);
    server2 = createBackupActiveMQServer(2, server2Params, isNetty(), 0, nodeManager);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");
    connectors.put(server2tc.getName(), server2tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    server1.getConfiguration().setConnectorConfigurations(connectors);
    reconnectAttempts = 1;
    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);
    server2.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    BridgeReconnectTest.log.info("** failing connection");
    // Now we will simulate a failure of the bridge connection between server0 and server1
    server0.fail(true);
    waitForServerStart(server2);
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server2tc));
    ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
    session0 = csf0.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc));
    session2 = csf2.createSession(false, true, true);
    ClientConsumer cons2 = session2.createConsumer(queueName);
    session2.start();
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons2.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) 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) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) 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) Test(org.junit.Test)

Example 23 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class BridgeReconnectTest method testFailoverAndReconnectAfterAFewTries.

// Fail bridge and attempt failover a few times before succeeding
@Test
public void testFailoverAndReconnectAfterAFewTries() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    server0 = createActiveMQServer(0, server0Params, isNetty(), nodeManager);
    server2 = createBackupActiveMQServer(2, server2Params, isNetty(), 0, nodeManager);
    TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");
    connectors.put(server2tc.getName(), server2tc);
    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);
    server2.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    // Now we will simulate a failure of the bridge connection between server0 and server1
    server0.fail(true);
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server2tc)).setReconnectAttempts(100);
    ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
    session0 = csf0.createSession(false, true, true);
    ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc));
    session2 = csf2.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientConsumer cons2 = session2.createConsumer(queueName);
    session2.start();
    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 = cons2.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) 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) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) 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) Test(org.junit.Test)

Example 24 with InVMNodeManager

use of org.apache.activemq.artemis.core.server.impl.InVMNodeManager in project activemq-artemis by apache.

the class JMSFailoverListenerTest method startServers.

/**
 * @throws Exception
 */
protected void startServers() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    backuptc = new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams);
    livetc = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
    liveAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);
    backupAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams);
    backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    backupConf = createBasicConfig().addAcceptorConfiguration(backupAcceptortc).addConnectorConfiguration(livetc.getName(), livetc).addConnectorConfiguration(backuptc.getName(), backuptc).setJournalType(getDefaultJournalType()).addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams)).setBindingsDirectory(getBindingsDir()).setJournalMinFiles(2).setJournalDirectory(getJournalDir()).setPagingDirectory(getPageDir()).setLargeMessagesDirectory(getLargeMessagesDir()).setPersistenceEnabled(true).setHAPolicyConfiguration(new SharedStoreSlavePolicyConfiguration()).addClusterConfiguration(basicClusterConnectionConfig(backuptc.getName(), livetc.getName()));
    backupServer = addServer(new InVMNodeManagerServer(backupConf, nodeManager));
    backupJMSServer = new JMSServerManagerImpl(backupServer);
    backupJMSServer.setRegistry(new JndiBindingRegistry(ctx2));
    backupJMSServer.getActiveMQServer().setIdentity("JMSBackup");
    log.info("Starting backup");
    backupJMSServer.start();
    liveConf = createBasicConfig().setJournalDirectory(getJournalDir()).setBindingsDirectory(getBindingsDir()).addAcceptorConfiguration(liveAcceptortc).setJournalType(getDefaultJournalType()).setBindingsDirectory(getBindingsDir()).setJournalMinFiles(2).setJournalDirectory(getJournalDir()).setPagingDirectory(getPageDir()).setLargeMessagesDirectory(getLargeMessagesDir()).addConnectorConfiguration(livetc.getName(), livetc).setPersistenceEnabled(true).setHAPolicyConfiguration(new SharedStoreMasterPolicyConfiguration()).addClusterConfiguration(basicClusterConnectionConfig(livetc.getName()));
    liveServer = addServer(new InVMNodeManagerServer(liveConf, nodeManager));
    liveJMSServer = new JMSServerManagerImpl(liveServer);
    liveJMSServer.setRegistry(new JndiBindingRegistry(ctx1));
    liveJMSServer.getActiveMQServer().setIdentity("JMSLive");
    log.info("Starting life");
    liveJMSServer.start();
    JMSUtil.waitForServer(backupServer);
}
Also used : InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) InVMNodeManagerServer(org.apache.activemq.artemis.tests.util.InVMNodeManagerServer) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry)

Aggregations

InVMNodeManager (org.apache.activemq.artemis.core.server.impl.InVMNodeManager)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)14 Test (org.junit.Test)13 SharedStoreSlavePolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration)10 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)9 SharedStoreMasterPolicyConfiguration (org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration)9 NodeManager (org.apache.activemq.artemis.core.server.NodeManager)9 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)8 ArrayList (java.util.ArrayList)6 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 XAException (javax.transaction.xa.XAException)5 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)4 ActiveMQObjectClosedException (org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException)4 ActiveMQTransactionOutcomeUnknownException (org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException)4 ActiveMQTransactionRolledBackException (org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException)4