use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method partitionAssignment_shouldFail_whenTriggered_inFrozenState.
@Test(expected = IllegalStateException.class)
public void partitionAssignment_shouldFail_whenTriggered_inFrozenState() {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(config);
HazelcastInstance hz1 = instances[0];
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
hz2.getCluster().changeClusterState(ClusterState.FROZEN);
InternalPartitionService partitionService = getPartitionService(hz1);
partitionService.getPartitionOwnerOrWait(1);
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class MigrationCommitTest method getOwnedPartition.
private InternalPartition getOwnedPartition(HazelcastInstance instance) {
InternalPartitionService partitionService = getPartitionService(instance);
Address address = getAddress(instance);
if (address.equals(partitionService.getPartitionOwner(0))) {
return partitionService.getPartition(0);
} else if (address.equals(partitionService.getPartitionOwner(1))) {
return partitionService.getPartition(1);
}
return null;
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method setup.
@Before
public void setup() throws Exception {
blockMigrationStartLatch = new CountDownLatch(1);
factory = createHazelcastInstanceFactory(NODE_COUNT);
instances = factory.newInstances(createConfig(), NODE_COUNT);
warmUpPartitions(instances);
waitAllForSafeState(instances);
InternalOperationService operationService = getOperationService(instances[0]);
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
InternalPartitionService partitionService = getPartitionService(instances[0]);
InternalPartition partition = partitionService.getPartition(partitionId);
for (int i = 0; i <= BACKUP_COUNT; i++) {
Address replicaAddress = partition.getReplicaAddress(i);
if (replicaAddress != null) {
TestMigrationAwareService service = getService(replicaAddress);
assertNotNull(service.get(partitionId));
}
}
}
}
});
for (HazelcastInstance instance : instances) {
TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
service.clearEvents();
}
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class LocalMapStatsTest method testHits_whenMultipleNodes.
@Test
public void testHits_whenMultipleNodes() throws InterruptedException {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance[] instances = factory.newInstances(getConfig());
MultiMap<Object, Object> multiMap0 = instances[0].getMultiMap("testHits_whenMultipleNodes");
MultiMap<Object, Object> multiMap1 = instances[1].getMultiMap("testHits_whenMultipleNodes");
// InternalPartitionService is used in order to determine owners of these keys that we will use.
InternalPartitionService partitionService = getNode(instances[0]).getPartitionService();
Address address = partitionService.getPartitionOwner(partitionService.getPartitionId("test1"));
boolean inFirstInstance = address.equals(getNode(instances[0]).getThisAddress());
multiMap0.get("test0");
multiMap0.put("test1", 1);
multiMap1.get("test1");
assertEquals(inFirstInstance ? 1 : 0, multiMap0.getLocalMultiMapStats().getHits());
assertEquals(inFirstInstance ? 0 : 1, multiMap1.getLocalMultiMapStats().getHits());
multiMap0.get("test1");
multiMap1.get("test1");
assertEquals(inFirstInstance ? 0 : 3, multiMap1.getLocalMultiMapStats().getHits());
}
use of com.hazelcast.internal.partition.InternalPartitionService in project hazelcast by hazelcast.
the class NearCacheTest method testGetAll.
@Test
public void testGetAll() {
int mapSize = 1000;
String mapName = "testGetAllWithNearCache";
Config config = getConfig();
NearCacheConfig nearCacheConfig = newNearCacheConfig();
nearCacheConfig.setInvalidateOnChange(false);
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = hazelcastInstanceFactory.newInstances(config);
warmUpPartitions(instances);
HazelcastInstance hazelcastInstance = instances[0];
InternalPartitionService partitionService = getPartitionService(hazelcastInstance);
// populate map
IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
populateMap(map, mapSize);
Set<Integer> keys = map.keySet();
// populate Near Cache
int expectedHits = 0;
for (int i = 0; i < mapSize; i++) {
map.get(i);
int partitionId = partitionService.getPartitionId(i);
if (!partitionService.isPartitionOwner(partitionId)) {
// map proxy stores non-owned entries (belong to partition which its not owner) inside its Near Cache
expectedHits++;
}
}
// generate Near Cache hits
Map<Integer, Integer> allEntries = map.getAll(keys);
for (int i = 0; i < mapSize; i++) {
assertEquals(i, (int) allEntries.get(i));
}
// check Near Cache hits
long hits = getNearCacheStats(map).getHits();
assertEquals(format("Near Cache hits should be %d but were %d", expectedHits, hits), expectedHits, hits);
}
Aggregations