use of org.apache.activemq.artemis.core.server.NodeManager in project activemq-artemis by apache.
the class MultiServerTestBase method setupLiveServer.
protected Pair<ActiveMQServer, NodeManager> setupLiveServer(final int node, final boolean realFiles, final boolean sharedStorage) throws Exception {
NodeManager nodeManager = null;
TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
if (sharedStorage) {
nodeManager = new InVMNodeManager(false);
}
Configuration configuration = createBasicConfig(node).setJournalMaxIO_AIO(1000).setThreadPoolMaxSize(10).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(sharedStorage ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration());
List<String> targetServersOnConnection = new ArrayList<>();
for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
if (targetNode == node) {
continue;
}
String targetConnectorName = "target-" + targetNode;
TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
configuration.getConnectorConfigurations().put(targetConnectorName, targetServer);
targetServersOnConnection.add(targetConnectorName);
// The connector towards a backup.. just to have a reference so bridges can connect to backups on their configs
String backupConnectorName = "backup-" + targetNode;
TransportConfiguration backupConnector = createTransportConfiguration(useNetty(), false, generateParams(targetNode + getNumberOfServers(), useNetty()));
configuration.getConnectorConfigurations().put(backupConnectorName, backupConnector);
}
ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
configuration.getClusterConfigurations().add(clusterConf);
ActiveMQServer server;
if (sharedStorage) {
server = createInVMFailoverServer(realFiles, configuration, nodeManager, node);
} else {
server = createServer(realFiles, configuration);
}
server.setIdentity(this.getClass().getSimpleName() + "/Live(" + node + ")");
addServer(server);
return new Pair<>(server, nodeManager);
}
use of org.apache.activemq.artemis.core.server.NodeManager in project activemq-artemis by apache.
the class MultipleLivesMultipleBackupsFailoverTest method testMultipleFailovers2LiveServers.
@Test
public void testMultipleFailovers2LiveServers() throws Exception {
NodeManager nodeManager1 = new InVMNodeManager(!sharedStore);
NodeManager nodeManager2 = new InVMNodeManager(!sharedStore);
createLiveConfig(nodeManager1, 0, 3, 4, 5);
createBackupConfig(nodeManager1, 0, 1, true, new int[] { 0, 2 }, 3, 4, 5);
createBackupConfig(nodeManager1, 0, 2, true, new int[] { 0, 1 }, 3, 4, 5);
createLiveConfig(nodeManager2, 3, 0);
createBackupConfig(nodeManager2, 3, 4, true, new int[] { 3, 5 }, 0, 1, 2);
createBackupConfig(nodeManager2, 3, 5, true, new int[] { 3, 4 }, 0, 1, 2);
servers.get(0).start();
waitForServerToStart(servers.get(0).getServer());
servers.get(3).start();
waitForServerToStart(servers.get(3).getServer());
servers.get(1).start();
waitForServerToStart(servers.get(1).getServer());
servers.get(2).start();
servers.get(4).start();
waitForServerToStart(servers.get(4).getServer());
servers.get(5).start();
waitForServerToStart(servers.get(4).getServer());
locator = getServerLocator(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
ClientSessionFactoryInternal sf = createSessionFactoryAndWaitForTopology(locator, 4, servers.get(0).getServer());
ClientSession session = sendAndConsume(sf, true);
System.out.println(((ServerLocatorInternal) locator).getTopology().describe());
Thread.sleep(500);
servers.get(0).crash(session);
int liveAfter0 = waitForNewLive(10000, true, servers, 1, 2);
locator2 = getServerLocator(3).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setReconnectAttempts(15);
ClientSessionFactoryInternal sf2 = createSessionFactoryAndWaitForTopology(locator2, 4);
ClientSession session2 = sendAndConsume(sf2, true);
System.setProperty("foo", "bar");
servers.get(3).crash(session2);
int liveAfter3 = waitForNewLive(10000, true, servers, 4, 5);
locator.close();
locator2.close();
if (liveAfter0 == 2) {
Thread.sleep(500);
servers.get(1).stop();
Thread.sleep(500);
servers.get(2).stop();
} else {
Thread.sleep(500);
servers.get(2).stop();
Thread.sleep(500);
servers.get(1).stop();
}
if (liveAfter3 == 4) {
Thread.sleep(500);
servers.get(5).stop();
Thread.sleep(500);
servers.get(4).stop();
} else {
Thread.sleep(500);
servers.get(4).stop();
Thread.sleep(500);
servers.get(5).stop();
}
}
use of org.apache.activemq.artemis.core.server.NodeManager in project activemq-artemis by apache.
the class NettyFailoverTest method createNodeManager.
@Override
protected NodeManager createNodeManager() throws Exception {
switch(nodeManagerType) {
case InVM:
return new InVMNodeManager(false);
case Jdbc:
final ThreadFactory daemonThreadFactory = t -> {
final Thread th = new Thread(t);
th.setDaemon(true);
return th;
};
final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(daemonThreadFactory);
scheduledExecutorServices.add(scheduledExecutorService);
final ExecutorService executor = Executors.newFixedThreadPool(2, daemonThreadFactory);
executors.add(executor);
final DatabaseStorageConfiguration dbConf = createDefaultDatabaseStorageConfiguration();
final ExecutorFactory executorFactory = new OrderedExecutorFactory(executor);
return JdbcNodeManager.with(dbConf, scheduledExecutorService, executorFactory, (code, message, file) -> {
code.printStackTrace();
Assert.fail(message);
});
default:
throw new AssertionError("enum type not supported!");
}
}
use of org.apache.activemq.artemis.core.server.NodeManager in project activemq-artemis by apache.
the class RealNodeManagerTest method testId.
@Test
public void testId() throws Exception {
NodeManager nodeManager = new FileLockNodeManager(new File(getTemporaryDir()), false);
nodeManager.start();
UUID id1 = nodeManager.getUUID();
nodeManager.stop();
nodeManager.start();
ActiveMQTestBase.assertEqualsByteArrays(id1.asBytes(), nodeManager.getUUID().asBytes());
nodeManager.stop();
}
use of org.apache.activemq.artemis.core.server.NodeManager 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();
}
Aggregations