use of org.apache.qpid.test.utils.PortHelper in project qpid-broker-j by apache.
the class MultiNodeTest method testClusterCannotStartWithIntruder.
@Test
public void testClusterCannotStartWithIntruder() throws Exception {
int intruderPort = new PortHelper().getNextAvailable(Arrays.stream(getBrokerAdmin().getBdbPorts()).max().getAsInt() + 1);
String nodeName = "intruder";
String nodeHostPort = getBrokerAdmin().getHost() + ":" + intruderPort;
File environmentPathFile = Files.createTempDirectory("qpid-work-intruder").toFile();
try {
environmentPathFile.mkdirs();
ReplicationConfig replicationConfig = new ReplicationConfig("test", nodeName, nodeHostPort);
replicationConfig.setHelperHosts(getBrokerAdmin().getHelperHostPort());
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setDurability(new Durability(Durability.SyncPolicy.SYNC, Durability.SyncPolicy.WRITE_NO_SYNC, Durability.ReplicaAckPolicy.SIMPLE_MAJORITY));
final String currentThreadName = Thread.currentThread().getName();
try (ReplicatedEnvironment intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig)) {
LOGGER.debug("Intruder started");
} finally {
Thread.currentThread().setName(currentThreadName);
}
Set<Integer> ports = Arrays.stream(getBrokerAdmin().getGroupAmqpPorts()).boxed().collect(Collectors.toSet());
for (int port : ports) {
getBrokerAdmin().awaitNodeToAttainAttributeValue(port, BDBHAVirtualHostNode.STATE, State.ERRORED.name());
}
getBrokerAdmin().stop();
try {
getBrokerAdmin().start();
fail("Cluster cannot start with an intruder node");
} catch (Exception e) {
// pass
}
} finally {
FileUtils.delete(environmentPathFile, true);
}
}
use of org.apache.qpid.test.utils.PortHelper in project qpid-broker-j by apache.
the class GroupBrokerAdmin method initializeGroupData.
private GroupMember[] initializeGroupData(final String groupName, final SpawnBrokerAdmin[] admins) {
PortHelper helper = new PortHelper();
int[] ports = new int[admins.length];
String[] addresses = new String[admins.length];
int port = -1;
for (int i = 0; i < admins.length; i++) {
port = i == 0 ? helper.getNextAvailable() : helper.getNextAvailable(port + 1);
addresses[i] = HOST + ":" + port;
ports[i] = port;
}
Map<String, String> context = new HashMap<>();
context.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s");
context.put(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES, "0");
context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, "{\"type\":\"BDB_HA\"}");
String permitted = objectToJson(addresses);
String contextAsString = objectToJson(context);
GroupMember[] members = new GroupMember[admins.length];
for (int i = 0; i < admins.length; i++) {
String nodeName = "node-" + ports[i];
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
nodeAttributes.put(BDBHAVirtualHostNode.NAME, nodeName);
nodeAttributes.put(BDBHAVirtualHostNode.ADDRESS, addresses[i]);
nodeAttributes.put(BDBHAVirtualHostNode.TYPE, BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
nodeAttributes.put(BDBHAVirtualHostNode.DEFAULT_VIRTUAL_HOST_NODE, true);
nodeAttributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, addresses[0]);
if (i > 0) {
nodeAttributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node-" + ports[0]);
}
nodeAttributes.put(BDBHAVirtualHostNode.PERMITTED_NODES, permitted);
nodeAttributes.put(BDBHAVirtualHostNode.CONTEXT, contextAsString);
members[i] = new GroupMember(nodeName, admins[i].getBrokerAddress(BrokerAdmin.PortType.AMQP).getPort(), port, admins[i], nodeAttributes);
}
return members;
}
Aggregations