Search in sources :

Example 26 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class SimpleMapTest method load.

private void load(ExecutorService es) throws InterruptedException {
    if (!load) {
        return;
    }
    final IMap<String, Object> map = instance.getMap(NAMESPACE);
    final Member thisMember = instance.getCluster().getLocalMember();
    List<String> lsOwnedEntries = new LinkedList<String>();
    for (int i = 0; i < entryCount; i++) {
        final String key = String.valueOf(i);
        Partition partition = instance.getPartitionService().getPartition(key);
        if (thisMember.equals(partition.getOwner())) {
            lsOwnedEntries.add(key);
        }
    }
    final CountDownLatch latch = new CountDownLatch(lsOwnedEntries.size());
    for (final String ownedKey : lsOwnedEntries) {
        es.execute(new Runnable() {

            public void run() {
                map.put(ownedKey, createValue());
                latch.countDown();
            }
        });
    }
    latch.await();
}
Also used : Partition(com.hazelcast.core.Partition) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 27 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembersWithHostAwareMetadata.

private Collection<Member> createMembersWithHostAwareMetadata() throws UnknownHostException {
    Collection<Member> members = new HashSet<Member>();
    InetAddress fakeAddress = InetAddress.getLocalHost();
    MemberImpl member1 = new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, true);
    member1.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-1");
    MemberImpl member2 = new MemberImpl(new Address("192.192.0.2", fakeAddress, 5701), VERSION, true);
    member2.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-2");
    MemberImpl member3 = new MemberImpl(new Address("192.192.0.3", fakeAddress, 5701), VERSION, true);
    member3.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-3");
    members.add(member1);
    members.add(member2);
    members.add(member3);
    return members;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 28 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembers.

private Collection<Member> createMembers() throws UnknownHostException {
    Collection<Member> members = new HashSet<Member>();
    InetAddress fakeAddress = InetAddress.getLocalHost();
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("192.168.3.101", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("192.168.3.101", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("172.16.5.11", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("172.16.5.11", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("172.123.0.13", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("172.123.0.13", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.com.tr", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.com.tr", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("jobs.hazelcast.com", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("jobs.hazelcast.com", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.org", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.org", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("download.hazelcast.org", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("download.hazelcast.org", fakeAddress, 5702), VERSION, false));
    return members;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 29 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class SafeClusterTest method isMemberSafe_localMember.

@Test
public void isMemberSafe_localMember() throws Exception {
    final HazelcastInstance node = createHazelcastInstance();
    final Member localMember = node.getCluster().getLocalMember();
    final boolean safe = node.getPartitionService().isMemberSafe(localMember);
    assertTrue(safe);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with Member

use of com.hazelcast.core.Member 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();
}
Also used : DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Node(com.hazelcast.instance.Node) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.core.Member) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.core.Member)330 Test (org.junit.Test)134 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)113 HazelcastInstance (com.hazelcast.core.HazelcastInstance)99 Address (com.hazelcast.nio.Address)60 IExecutorService (com.hazelcast.core.IExecutorService)57 Future (java.util.concurrent.Future)47 ArrayList (java.util.ArrayList)45 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 CountDownLatch (java.util.concurrent.CountDownLatch)37 Config (com.hazelcast.config.Config)35 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)26 HashMap (java.util.HashMap)26 IMap (com.hazelcast.core.IMap)24 HashSet (java.util.HashSet)21 LinkedList (java.util.LinkedList)20 OperationService (com.hazelcast.spi.OperationService)19 AssertTask (com.hazelcast.test.AssertTask)19 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18