use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.
the class ClusterWithBackupFailoverTestBase method failNode.
/**
* @param node The node which we should fail
* @param originalLiveNode The number of the original node, to locate session to fail
* @throws Exception
*/
protected void failNode(final int node, final int originalLiveNode) throws Exception {
ClusterWithBackupFailoverTestBase.log.info("*** failing node " + node);
ActiveMQServer server = getServer(node);
TestableServer tstServer = new SameProcessActiveMQServer(server);
ClientSession[] sessionsArray = exploreSessions(originalLiveNode);
tstServer.crash(sessionsArray);
}
use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.
the class MultipleBackupsFailoverTestBase method waitForNewLive.
protected int waitForNewLive(long seconds, boolean waitForNewBackup, Map<Integer, TestableServer> servers, int... nodes) {
long time = System.currentTimeMillis();
long toWait = seconds * 1000;
int newLive = -1;
while (true) {
for (int node : nodes) {
TestableServer backupServer = servers.get(node);
if (newLive == -1 && backupServer.isActive()) {
newLive = node;
} else if (newLive != -1) {
if (waitForNewBackup) {
if (node != newLive && servers.get(node).isStarted()) {
return newLive;
}
} else {
return newLive;
}
}
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
if (System.currentTimeMillis() > (time + toWait)) {
Assert.fail("backup server never started");
}
}
}
use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.
the class ReplicatedMultipleServerFailoverExtraBackupsTest method sendCrashBackupReceive.
protected void sendCrashBackupReceive() throws Exception {
ServerLocator locator0 = getBackupServerLocator(0);
ServerLocator locator1 = getBackupServerLocator(1);
ClientSessionFactory factory0 = createSessionFactory(locator0);
ClientSessionFactory factory1 = createSessionFactory(locator1);
ClientSession session0 = factory0.createSession(false, true, true);
ClientSession session1 = factory1.createSession(false, true, true);
ClientProducer producer = session0.createProducer(ADDRESS);
for (int i = 0; i < 200; i++) {
ClientMessage message = session0.createMessage(true);
setBody(i, message);
message.putIntProperty("counter", i);
producer.send(message);
}
producer.close();
waitForDistribution(ADDRESS, backupServers.get(0).getServer(), 100);
waitForDistribution(ADDRESS, backupServers.get(1).getServer(), 100);
List<TestableServer> toCrash = new ArrayList<>();
for (TestableServer backupServer : backupServers) {
if (!backupServer.getServer().getHAPolicy().isBackup()) {
toCrash.add(backupServer);
}
}
for (TestableServer testableServer : toCrash) {
testableServer.crash();
}
ClientConsumer consumer0 = session0.createConsumer(ADDRESS);
ClientConsumer consumer1 = session1.createConsumer(ADDRESS);
session0.start();
session1.start();
for (int i = 0; i < 100; i++) {
ClientMessage message = consumer0.receive(1000);
assertNotNull("expecting durable msg " + i, message);
message.acknowledge();
consumer1.receive(1000);
assertNotNull("expecting durable msg " + i, message);
message.acknowledge();
}
}
use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.
the class MultipleServerFailoverTestBase method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
liveServers = new ArrayList<>();
backupServers = new ArrayList<>();
backupConfigs = new ArrayList<>();
liveConfigs = new ArrayList<>();
for (int i = 0; i < getLiveServerCount(); i++) {
HAPolicyConfiguration haPolicyConfiguration = null;
if (isSharedStore()) {
haPolicyConfiguration = new SharedStoreMasterPolicyConfiguration();
} else {
haPolicyConfiguration = new ReplicatedPolicyConfiguration();
if (getNodeGroupName() != null) {
((ReplicatedPolicyConfiguration) haPolicyConfiguration).setGroupName(getNodeGroupName() + "-" + i);
}
}
Configuration configuration = createDefaultConfig(isNetty()).clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(true, i)).setHAPolicyConfiguration(haPolicyConfiguration);
if (!isSharedStore()) {
configuration.setBindingsDirectory(getBindingsDir(i, false));
configuration.setJournalDirectory(getJournalDir(i, false));
configuration.setPagingDirectory(getPageDir(i, false));
configuration.setLargeMessagesDirectory(getLargeMessagesDir(i, false));
} else {
// todo
}
TransportConfiguration livetc = getConnectorTransportConfiguration(true, i);
configuration.addConnectorConfiguration(livetc.getName(), livetc);
List<String> connectors = new ArrayList<>();
for (int j = 0; j < getLiveServerCount(); j++) {
if (j != i) {
TransportConfiguration staticTc = getConnectorTransportConfiguration(true, j);
configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
connectors.add(staticTc.getName());
}
}
String[] input = new String[connectors.size()];
connectors.toArray(input);
configuration.addClusterConfiguration(basicClusterConnectionConfig(livetc.getName(), input));
liveConfigs.add(configuration);
ActiveMQServer server = createServer(true, configuration);
TestableServer activeMQServer = new SameProcessActiveMQServer(server);
activeMQServer.setIdentity("Live-" + i);
liveServers.add(activeMQServer);
}
for (int i = 0; i < getBackupServerCount(); i++) {
HAPolicyConfiguration haPolicyConfiguration = null;
if (isSharedStore()) {
haPolicyConfiguration = new SharedStoreSlavePolicyConfiguration();
} else {
haPolicyConfiguration = new ReplicaPolicyConfiguration();
if (getNodeGroupName() != null) {
((ReplicaPolicyConfiguration) haPolicyConfiguration).setGroupName(getNodeGroupName() + "-" + i);
}
}
Configuration configuration = createDefaultConfig(isNetty()).clearAcceptorConfigurations().addAcceptorConfiguration(getAcceptorTransportConfiguration(false, i)).setHAPolicyConfiguration(haPolicyConfiguration);
if (!isSharedStore()) {
configuration.setBindingsDirectory(getBindingsDir(i, true));
configuration.setJournalDirectory(getJournalDir(i, true));
configuration.setPagingDirectory(getPageDir(i, true));
configuration.setLargeMessagesDirectory(getLargeMessagesDir(i, true));
} else {
// todo
}
TransportConfiguration backuptc = getConnectorTransportConfiguration(false, i);
configuration.addConnectorConfiguration(backuptc.getName(), backuptc);
List<String> connectors = new ArrayList<>();
for (int j = 0; j < getBackupServerCount(); j++) {
TransportConfiguration staticTc = getConnectorTransportConfiguration(true, j);
configuration.addConnectorConfiguration(staticTc.getName(), staticTc);
connectors.add(staticTc.getName());
}
for (int j = 0; j < getBackupServerCount(); j++) {
if (j != i) {
TransportConfiguration staticTc = getConnectorTransportConfiguration(false, j);
configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
connectors.add(staticTc.getName());
}
}
String[] input = new String[connectors.size()];
connectors.toArray(input);
configuration.addClusterConfiguration(basicClusterConnectionConfig(backuptc.getName(), input));
backupConfigs.add(configuration);
ActiveMQServer server = createServer(true, configuration);
TestableServer testableServer = new SameProcessActiveMQServer(server);
testableServer.setIdentity("Backup-" + i);
backupServers.add(testableServer);
}
}
use of org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer in project activemq-artemis by apache.
the class ReplicatedMultipleServerFailoverTest method testStartBackupFirst.
@Test
public void testStartBackupFirst() throws Exception {
for (TestableServer backupServer : backupServers) {
backupServer.start();
}
for (TestableServer liveServer : liveServers) {
liveServer.start();
}
waitForTopology(liveServers.get(0).getServer(), liveServers.size(), liveServers.size());
sendCrashReceive();
}
Aggregations