use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class SqlErrorAbstractTest method newHazelcastInstance.
/**
* Start the new Hazelcast instance.
*
* @param awaitAssignment whether to wait for a partition assignment to a new member
* @return created instance
*/
protected HazelcastInstance newHazelcastInstance(boolean awaitAssignment) {
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
if (awaitAssignment) {
assertTrueEventually(() -> {
Set<UUID> memberIds = new HashSet<>();
for (Member member : instance.getCluster().getMembers()) {
memberIds.add(member.getUuid());
}
PartitionService partitionService = instance.getPartitionService();
Set<UUID> assignedMemberIds = new HashSet<>();
for (Partition partition : partitionService.getPartitions()) {
Member owner = partition.getOwner();
assertNotNull(owner);
assignedMemberIds.add(owner.getUuid());
}
assertEquals(memberIds, assignedMemberIds);
});
}
return instance;
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class PartitionServiceProxy method getPartitions.
@Override
public Set<Partition> getPartitions() {
final int partitionCount = partitionService.getPartitionCount();
Set<Partition> partitions = new LinkedHashSet<>(partitionCount);
for (int i = 0; i < partitionCount; i++) {
final Partition partition = partitionService.getPartition(i);
partitions.add(partition);
}
return partitions;
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class ClientConsoleApp method handlePartitions.
protected void handlePartitions(String[] args) {
Set<Partition> partitions = client.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<Entry<Member, Integer>> entries = partitionCounts.entrySet();
for (Entry<Member, Integer> entry : entries) {
println(entry.getKey() + ":" + entry.getValue());
}
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class WriteBehindOnBackupsTest method getOwnerNode.
private HazelcastInstance getOwnerNode(String key, HazelcastInstance[] nodes) {
PartitionService partitionService = nodes[0].getPartitionService();
Partition partition = partitionService.getPartition(key);
Member owner = partition.getOwner();
for (HazelcastInstance node : nodes) {
Member localMember = node.getCluster().getLocalMember();
if (localMember.equals(owner)) {
return node;
}
}
throw new IllegalStateException("This should not be happen...");
}
use of com.hazelcast.partition.Partition in project hazelcast by hazelcast.
the class SimpleReplicatedMapTest method load.
private void load(ExecutorService es) throws Exception {
if (!load) {
return;
}
final ReplicatedMap<String, Object> map = instance.getReplicatedMap(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();
}
Aggregations