use of com.hazelcast.partition.PartitionService 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.PartitionService 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.PartitionService in project hazelcast by hazelcast.
the class HazelcastOSGiInstanceTest method getPartitionServiceCalledSuccessfullyOverOSGiInstance.
@Test
public void getPartitionServiceCalledSuccessfullyOverOSGiInstance() {
PartitionService mockPartitionService = mock(PartitionService.class);
HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
HazelcastOSGiInstance hazelcastOSGiInstance = createHazelcastOSGiInstance(mockHazelcastInstance);
when(mockHazelcastInstance.getPartitionService()).thenReturn(mockPartitionService);
assertEquals(mockPartitionService, hazelcastOSGiInstance.getPartitionService());
verify(mockHazelcastInstance).getPartitionService();
}
use of com.hazelcast.partition.PartitionService in project hazelcast by hazelcast.
the class InMemoryFormatTest method countDeserializationsOnContainsValue.
@Test
public void countDeserializationsOnContainsValue() {
final Config config = new Config().addMapConfig(new MapConfig("default").setInMemoryFormat(InMemoryFormat.OBJECT));
final HazelcastInstance hz = createHazelcastInstance(config);
final PartitionService partitionService = hz.getPartitionService();
final IMap<Integer, Object> m = hz.getMap("mappy");
final HashSet<Integer> nonEmptyPartitions = new HashSet<Integer>();
for (int i = 0; i < MemberPartitionStateImpl.DEFAULT_PARTITION_COUNT * 5; i++) {
m.put(i, i);
nonEmptyPartitions.add(partitionService.getPartition(i).getPartitionId());
}
final SerializationCounting value = new SerializationCounting();
m.containsValue(value);
assertEquals(nonEmptyPartitions.size(), SerializationCounting.deserializationCount.get());
}
use of com.hazelcast.partition.PartitionService in project hazelcast by hazelcast.
the class HazelcastTestSupport method generateKeyForPartition.
public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
Cluster cluster = instance.getCluster();
checkPartitionCountGreaterOrEqualMemberCount(instance);
PartitionService partitionService = instance.getPartitionService();
while (true) {
String id = randomString();
Partition partition = partitionService.getPartition(id);
if (partition.getPartitionId() == partitionId) {
return id;
}
}
}
Aggregations