use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.
the class MemberGroupFactoryTest method testConfigMemberGroupFactoryCreateMemberGroups.
/**
* When there is a matching {@link MemberGroupConfig} for a {@link Member}, it will be assigned to a {@link MemberGroup}.
* <p>
* In this test all members will have a matching configuration, so there will be 4 groups with 2 members each.
*/
@Test
public void testConfigMemberGroupFactoryCreateMemberGroups() {
Collection<Member> members = createMembers();
Collection<MemberGroupConfig> groupConfigs = createMemberGroupConfigs(true);
MemberGroupFactory groupFactory = new ConfigMemberGroupFactory(groupConfigs);
Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
assertEquals("Member Groups: " + String.valueOf(memberGroups), 4, memberGroups.size());
for (MemberGroup memberGroup : memberGroups) {
assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
}
}
use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.
the class ConfigMemberGroupFactory method createInternalMemberGroups.
@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> members) {
Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>();
for (Member member : members) {
String host = ((MemberImpl) member).getAddress().getHost();
for (Entry<Integer, MemberGroupConfig> entry : memberGroupConfigMap.entrySet()) {
Collection<String> interfaces = entry.getValue().getInterfaces();
boolean match;
if (AddressUtil.isIpAddress(host)) {
match = AddressUtil.matchAnyInterface(host, interfaces);
} else {
match = AddressUtil.matchAnyDomain(host, interfaces);
}
if (match) {
MemberGroup group = memberGroups.get(entry.getKey());
if (group == null) {
group = new DefaultMemberGroup();
memberGroups.put(entry.getKey(), group);
}
group.addMember(member);
break;
}
}
}
return new HashSet<MemberGroup>(memberGroups.values());
}
use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.
the class LocalMapStatsTest method createConfig.
private Config createConfig(String mapName, String[] firstGroup, String[] secondGroup) {
final MemberGroupConfig firstGroupConfig = createGroupConfig(firstGroup);
final MemberGroupConfig secondGroupConfig = createGroupConfig(secondGroup);
Config config = getConfig();
config.getPartitionGroupConfig().setEnabled(true).setGroupType(PartitionGroupConfig.MemberGroupType.CUSTOM);
config.getPartitionGroupConfig().addMemberGroupConfig(firstGroupConfig);
config.getPartitionGroupConfig().addMemberGroupConfig(secondGroupConfig);
config.getNetworkConfig().getInterfaces().addInterface("127.0.0.*");
config.getMapConfig(mapName).setBackupCount(2);
return config;
}
use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.
the class MemberDomConfigProcessor method handleMemberGroup.
protected void handleMemberGroup(Node node, Config config) {
MemberGroupConfig memberGroupConfig = new MemberGroupConfig();
for (Node child : childElements(node)) {
if (matches("interface", cleanNodeName(child))) {
memberGroupConfig.addInterface(getTextContent(child));
}
}
config.getPartitionGroupConfig().addMemberGroupConfig(memberGroupConfig);
}
use of com.hazelcast.config.MemberGroupConfig in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method testConfigCustomPartitionStateGenerator.
@Test
public void testConfigCustomPartitionStateGenerator() throws Exception {
PartitionGroupConfig config = new PartitionGroupConfig();
config.setEnabled(true);
config.setGroupType(PartitionGroupConfig.MemberGroupType.CUSTOM);
MemberGroupConfig mgCfg0 = new MemberGroupConfig();
MemberGroupConfig mgCfg1 = new MemberGroupConfig();
MemberGroupConfig mgCfg2 = new MemberGroupConfig();
MemberGroupConfig mgCfg3 = new MemberGroupConfig();
config.addMemberGroupConfig(mgCfg0);
config.addMemberGroupConfig(mgCfg1);
config.addMemberGroupConfig(mgCfg2);
config.addMemberGroupConfig(mgCfg3);
for (int k = 0; k < 3; k++) {
for (int i = 0; i < 255; i++) {
MemberGroupConfig mg;
switch(i % 4) {
case 0:
mg = mgCfg0;
break;
case 1:
mg = mgCfg1;
break;
case 2:
mg = mgCfg2;
break;
case 3:
mg = mgCfg3;
break;
default:
throw new IllegalArgumentException();
}
mg.addInterface("10.10." + k + "." + i);
}
}
test(new ConfigMemberGroupFactory(config.getMemberGroupConfigs()));
}
Aggregations