Search in sources :

Example 76 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class ListenerTest method updates_with_putTransient_triggers_entryUpdatedListener.

@Test
public void updates_with_putTransient_triggers_entryUpdatedListener() throws Exception {
    HazelcastInstance hz = createHazelcastInstance(getConfig());
    IMap<String, String> map = hz.getMap("updates_with_putTransient_triggers_entryUpdatedListener");
    final CountDownLatch updateEventCounterLatch = new CountDownLatch(1);
    map.addEntryListener(new EntryUpdatedListener<String, String>() {

        @Override
        public void entryUpdated(EntryEvent<String, String> event) {
            updateEventCounterLatch.countDown();
        }
    }, true);
    map.putTransient("hello", "world", 0, TimeUnit.SECONDS);
    map.putTransient("hello", "another world", 0, TimeUnit.SECONDS);
    assertOpenEventually(updateEventCounterLatch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 77 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class ListenerTest method testEntryListenerEvent_withMapReplaceFail.

@Test
public void testEntryListenerEvent_withMapReplaceFail() throws Exception {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    final IMap<Integer, Object> map = instance.getMap(randomString());
    final CounterEntryListener listener = new CounterEntryListener();
    map.addEntryListener(listener, true);
    final int putTotal = 1000;
    final int oldVal = 1;
    for (int i = 0; i < putTotal; i++) {
        map.put(i, oldVal);
    }
    final int replaceTotal = 1000;
    final int newVal = 2;
    for (int i = 0; i < replaceTotal; i++) {
        map.replace(i, "WrongValue", newVal);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            for (int i = 0; i < replaceTotal; i++) {
                assertEquals(oldVal, map.get(i));
            }
            assertEquals(putTotal, listener.addCount.get());
            assertEquals(0, listener.updateCount.get());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 78 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class ListenerTest method hazelcastAwareEntryListener_injectHazelcastInstance.

private void hazelcastAwareEntryListener_injectHazelcastInstance(EntryListenerConfig listenerConfig) {
    String pingMapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(pingMapName).getEntryListenerConfigs().add(listenerConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, String> pingMap = instance.getMap(pingMapName);
    String pongMapName = randomMapName();
    pingMap.put(0, pongMapName);
    IMap<Integer, String> outputMap = instance.getMap(pongMapName);
    assertSizeEventually(1, outputMap);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig)

Example 79 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class EvictionTest method testEvictionPerPartition.

@Test
public void testEvictionPerPartition() throws InterruptedException {
    final int k = 2;
    final int size = 10;
    final String mapName = "testEvictionPerPartition";
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    final MapConfig mc = cfg.getMapConfig(mapName);
    mc.setEvictionPolicy(EvictionPolicy.LRU);
    mc.setEvictionPercentage(50);
    mc.setMinEvictionCheckMillis(0);
    final MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(PER_PARTITION);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    final int pNum = instances[0].getPartitionService().getPartitions().size();
    int insertCount = size * pNum * 2;
    final Map<Integer, Integer> map = instances[0].getMap(mapName);
    for (int i = 0; i < insertCount; i++) {
        map.put(i, i);
    }
    int mapSize = map.size();
    String message = format("mapSize : %d should be <= max-size : %d ", mapSize, size);
    assertTrue(message, mapSize <= size);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class EvictionTest method testEvictionLRU_statisticsDisabled.

@Test
public void testEvictionLRU_statisticsDisabled() {
    final int nodeCount = 2;
    final int size = 100000;
    final String mapName = randomMapName("_testEvictionLRU_statisticsDisabled_");
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mc = cfg.getMapConfig(mapName);
    mc.setStatisticsEnabled(false);
    mc.setEvictionPolicy(EvictionPolicy.LRU);
    mc.setEvictionPercentage(10);
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    IMap<Object, Object> map = instances[0].getMap(mapName);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
        if (i < size / 2) {
            map.get(i);
        }
    }
    // give some time to eviction thread run.
    sleepSeconds(3);
    int recentlyUsedEvicted = 0;
    for (int i = 0; i < size / 2; i++) {
        if (map.get(i) == null) {
            recentlyUsedEvicted++;
        }
    }
    assertEquals(0, recentlyUsedEvicted);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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