Search in sources :

Example 11 with Partition

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

the class HazelcastTestSupport method generateKeyForPartition.

public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
    Cluster cluster = instance.getCluster();
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    Member localMember = cluster.getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = randomString();
        Partition partition = partitionService.getPartition(id);
        if (partition.getPartitionId() == partitionId) {
            return id;
        }
    }
}
Also used : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) Cluster(com.hazelcast.core.Cluster) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.core.Member)

Example 12 with Partition

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

the class PartitionControlledIdTest method testLock.

@Test
public void testLock() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    ILock lock = hz.getLock("lock@" + partitionKey);
    lock.lock();
    assertEquals("lock@" + partitionKey, lock.getName());
    assertEquals(partitionKey, lock.getPartitionKey());
    Node node = getNode(hz);
    LockServiceImpl lockService = node.nodeEngine.getService(LockServiceImpl.SERVICE_NAME);
    Partition partition = instances[0].getPartitionService().getPartition(partitionKey);
    LockStore lockStore = lockService.getLockStore(partition.getPartitionId(), new InternalLockNamespace(lock.getName()));
    Data key = node.getSerializationService().toData(lock.getName(), StringPartitioningStrategy.INSTANCE);
    assertTrue(lockStore.isLocked(key));
}
Also used : Partition(com.hazelcast.core.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) Node(com.hazelcast.instance.Node) LockServiceImpl(com.hazelcast.concurrent.lock.LockServiceImpl) Data(com.hazelcast.nio.serialization.Data) ILock(com.hazelcast.core.ILock) LockStore(com.hazelcast.concurrent.lock.LockStore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with Partition

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

the class PartitionControlledIdTest method getHazelcastInstance.

private HazelcastInstance getHazelcastInstance(String partitionKey) {
    Partition partition = instances[0].getPartitionService().getPartition(partitionKey);
    Member owner = partition.getOwner();
    assertNotNull(owner);
    HazelcastInstance hz = null;
    for (HazelcastInstance instance : instances) {
        if (instance.getCluster().getLocalMember().equals(owner)) {
            hz = instance;
            break;
        }
    }
    assertNotNull(hz);
    return hz;
}
Also used : Partition(com.hazelcast.core.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Member(com.hazelcast.core.Member)

Example 14 with Partition

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

the class PartitionDistributionTest method getLocalPartitionsCount.

private static int getLocalPartitionsCount(HazelcastInstance instance) {
    warmUpPartitions(instance);
    Member localMember = instance.getCluster().getLocalMember();
    Set<Partition> partitions = instance.getPartitionService().getPartitions();
    int count = 0;
    for (Partition partition : partitions) {
        if (localMember.equals(partition.getOwner())) {
            count++;
        }
    }
    return count;
}
Also used : Partition(com.hazelcast.core.Partition) Member(com.hazelcast.core.Member)

Example 15 with Partition

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

the class ConsoleApp method handlePartitions.

protected void handlePartitions(String[] args) {
    Set<Partition> partitions = hazelcast.getPartitionService().getPartitions();
    Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>();
    for (Partition partition : partitions) {
        Member owner = partition.getOwner();
        if (owner != null) {
            Integer count = partitionCounts.get(owner);
            int newCount = 1;
            if (count != null) {
                newCount = count + 1;
            }
            partitionCounts.put(owner, newCount);
        }
        println(partition);
    }
    Set<Map.Entry<Member, Integer>> entries = partitionCounts.entrySet();
    for (Map.Entry<Member, Integer> entry : entries) {
        println(entry.getKey() + ": " + entry.getValue());
    }
}
Also used : Partition(com.hazelcast.core.Partition) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member) MultiMap(com.hazelcast.core.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) IMap(com.hazelcast.core.IMap)

Aggregations

Partition (com.hazelcast.core.Partition)18 Member (com.hazelcast.core.Member)13 PartitionService (com.hazelcast.core.PartitionService)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 IPartition (com.hazelcast.spi.partition.IPartition)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Cluster (com.hazelcast.core.Cluster)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Entry (java.util.Map.Entry)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)1 LockServiceImpl (com.hazelcast.concurrent.lock.LockServiceImpl)1 LockStore (com.hazelcast.concurrent.lock.LockStore)1 ILock (com.hazelcast.core.ILock)1 IMap (com.hazelcast.core.IMap)1 MultiMap (com.hazelcast.core.MultiMap)1