use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class InternalPartitionServiceLiteMemberTest method test_dataMemberCanShutdownSafely_whenOnlyLiteMemberExistsInCluster.
@Test(timeout = 120000)
public void test_dataMemberCanShutdownSafely_whenOnlyLiteMemberExistsInCluster() {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance master = factory.newHazelcastInstance();
final HazelcastInstance lite = factory.newHazelcastInstance(liteMemberConfig);
warmUpPartitions(master, lite);
master.getLifecycleService().shutdown();
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class InternalPartitionServiceLiteMemberTest method test_getPartition_afterLiteMemberLeavesTheCluster.
@Test
public void test_getPartition_afterLiteMemberLeavesTheCluster() {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance dataInstance = factory.newHazelcastInstance();
final HazelcastInstance lite = factory.newHazelcastInstance(liteMemberConfig);
warmUpPartitions(dataInstance, lite);
lite.getLifecycleService().shutdown();
assertClusterSizeEventually(1, dataInstance);
final InternalPartitionServiceImpl partitionService = getInternalPartitionServiceImpl(dataInstance);
for (int i = 0; i < partitionService.getPartitionCount(); i++) {
assertEquals(getNode(dataInstance).getThisAddress(), partitionService.getPartition(i).getOwnerOrNull());
}
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class InternalPartitionServiceLiteMemberTest method test_getMemberPartitionsMap_withLiteAndDataMembers.
@Test
public void test_getMemberPartitionsMap_withLiteAndDataMembers() {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance lite = factory.newHazelcastInstance(liteMemberConfig);
final HazelcastInstance dataInstance = factory.newHazelcastInstance();
warmUpPartitions(lite, dataInstance);
final InternalPartitionServiceImpl partitionService = getInternalPartitionServiceImpl(lite);
final Map<Address, List<Integer>> partitionsMap = partitionService.getMemberPartitionsMap();
assertEquals(1, partitionsMap.size());
final List<Integer> partitions = partitionsMap.get(getAddress(dataInstance));
assertNotNull(partitions);
assertFalse(partitions.isEmpty());
}
use of com.hazelcast.core.HazelcastInstance 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.core.HazelcastInstance in project hazelcast by hazelcast.
the class MapEvictAllTest method testEvictAll_preserveLockedKeys.
@Test
public void testEvictAll_preserveLockedKeys() throws Exception {
int numberOfEntries = 1000;
int numberOfLockedKeys = 123;
int expectedNumberOfEvictedKeys = numberOfEntries - numberOfLockedKeys;
final CountDownLatch countDownLatch = new CountDownLatch(expectedNumberOfEvictedKeys);
HazelcastInstance node = createHazelcastInstance(getConfig());
IMap<Integer, Integer> map = node.getMap(randomMapName());
map.addLocalEntryListener(new EntryAdapter<Integer, Integer>() {
@Override
public void mapEvicted(MapEvent event) {
int numberOfEntries = event.getNumberOfEntriesAffected();
for (int i = 0; i < numberOfEntries; i++) {
countDownLatch.countDown();
}
}
});
for (int i = 0; i < numberOfEntries; i++) {
map.put(i, i);
}
for (int i = 0; i < numberOfLockedKeys; i++) {
map.lock(i);
}
map.evictAll();
assertOpenEventually(countDownLatch);
assertEquals(0, countDownLatch.getCount());
assertEquals(numberOfLockedKeys, map.size());
}
Aggregations