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;
}
}
}
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));
}
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;
}
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;
}
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());
}
}
Aggregations