Search in sources :

Example 66 with HazelcastInstance

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 67 with HazelcastInstance

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());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 68 with HazelcastInstance

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) List(java.util.List) Arrays.asList(java.util.Arrays.asList) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 69 with HazelcastInstance

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 70 with HazelcastInstance

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapEvent(com.hazelcast.core.MapEvent) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2084 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)149 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)99 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83