use of com.hazelcast.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method testRandomPartitionGenerator.
@Test
public void testRandomPartitionGenerator() throws Exception {
final MemberGroupFactory memberGroupFactory = new SingleMemberGroupFactory();
test(memberGroupFactory);
}
use of com.hazelcast.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.
the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryCreateMemberGroups.
@Test
public void testSPIAwareMemberGroupFactoryCreateMemberGroups() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
Config config = getDiscoverySPIConfig(xmlFileName);
// we create this instance in order to fully create Node
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
Node node = TestUtil.getNode(hazelcastInstance);
assertNotNull(node);
MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(node.getDiscoveryService());
Collection<Member> members = createMembers();
Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
assertEquals("Member Groups: " + String.valueOf(memberGroups), 2, memberGroups.size());
for (MemberGroup memberGroup : memberGroups) {
assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
}
hazelcastInstance.shutdown();
}
use of com.hazelcast.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.
the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryInvalidConfig.
@Test(expected = RuntimeException.class)
public void testSPIAwareMemberGroupFactoryInvalidConfig() throws Exception {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
try {
MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(TestUtil.getNode(hazelcastInstance).getDiscoveryService());
Collection<Member> members = createMembers();
groupFactory.createMemberGroups(members);
} finally {
hazelcastInstance.shutdown();
}
}
use of com.hazelcast.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method testCustomPartitionStateGenerator.
@Test
public void testCustomPartitionStateGenerator() throws Exception {
final MemberGroupFactory memberGroupFactory = new MemberGroupFactory() {
public Collection<MemberGroup> createMemberGroups(Collection<? extends Member> members) {
MemberGroup[] g = new MemberGroup[4];
for (int i = 0; i < g.length; i++) {
g[i] = new DefaultMemberGroup();
}
for (Member member : members) {
Address address = member.getAddress();
if (even(address.getHost().hashCode()) && even(address.getPort())) {
g[0].addMember(member);
} else if (even(address.getHost().hashCode()) && !even(address.getPort())) {
g[1].addMember(member);
} else if (!even(address.getHost().hashCode()) && even(address.getPort())) {
g[2].addMember(member);
} else if (!even(address.getHost().hashCode()) && !even(address.getPort())) {
g[3].addMember(member);
}
}
List<MemberGroup> list = new LinkedList<MemberGroup>();
for (MemberGroup memberGroup : g) {
if (memberGroup.size() > 0) {
list.add(memberGroup);
}
}
return list;
}
boolean even(int k) {
return k % 2 == 0;
}
};
test(memberGroupFactory);
}
Aggregations