Search in sources :

Example 1 with EvictionConfig

use of com.hazelcast.config.EvictionConfig in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache.

@Test
public void testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache() {
    String mapName = randomMapName();
    EvictionConfig evictionConfig = new EvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(1);
    NearCacheConfig nearCacheConfig = new NearCacheConfig().setName(mapName).setEvictionConfig(evictionConfig);
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(nearCacheConfig).setExecutorPoolSize(1);
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    hazelcastFactory.newHazelcastInstance();
    final CountDownLatch latch = new CountDownLatch(1);
    final IMap<Object, Object> map = client.getMap(mapName);
    client.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
                map.get(1);
                map.get(2);
                latch.countDown();
            }
        }
    });
    instance.shutdown();
    assertOpenEventually(latch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EvictionConfig(com.hazelcast.config.EvictionConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) LifecycleEvent(com.hazelcast.core.LifecycleEvent) DistributedObject(com.hazelcast.core.DistributedObject) LifecycleListener(com.hazelcast.core.LifecycleListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with EvictionConfig

use of com.hazelcast.config.EvictionConfig in project hazelcast by hazelcast.

the class TestJCache method cacheConfigXmlTest_ComparatorBean.

@Test
public void cacheConfigXmlTest_ComparatorBean() {
    assertNotNull(instance1);
    CacheSimpleConfig cacheConfigWithComparatorClassName = instance1.getConfig().getCacheConfig("cacheWithComparatorBean");
    assertNotNull(cacheConfigWithComparatorClassName);
    EvictionConfig evictionConfig = cacheConfigWithComparatorClassName.getEvictionConfig();
    assertNotNull(evictionConfig);
    assertEquals(MyEvictionPolicyComparator.class, evictionConfig.getComparator().getClass());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with EvictionConfig

use of com.hazelcast.config.EvictionConfig in project hazelcast by hazelcast.

the class TestJCache method cacheConfigXmlTest_ComparatorClassName.

@Test
public void cacheConfigXmlTest_ComparatorClassName() {
    assertNotNull(instance1);
    CacheSimpleConfig cacheConfigWithComparatorClassName = instance1.getConfig().getCacheConfig("cacheWithComparatorClassName");
    assertNotNull(cacheConfigWithComparatorClassName);
    EvictionConfig evictionConfig = cacheConfigWithComparatorClassName.getEvictionConfig();
    assertNotNull(evictionConfig);
    assertEquals("com.mycompany.MyEvictionPolicyComparator", evictionConfig.getComparatorClassName());
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with EvictionConfig

use of com.hazelcast.config.EvictionConfig in project hazelcast by hazelcast.

the class QueryCacheConfigBuilderHelper method getEvictionConfig.

private EvictionConfig getEvictionConfig(final Node node) {
    final EvictionConfig evictionConfig = new EvictionConfig();
    final Node size = node.getAttributes().getNamedItem("size");
    final Node maxSizePolicy = node.getAttributes().getNamedItem("max-size-policy");
    final Node evictionPolicy = node.getAttributes().getNamedItem("eviction-policy");
    if (size != null) {
        evictionConfig.setSize(Integer.parseInt(getTextContent(size)));
    }
    if (maxSizePolicy != null) {
        evictionConfig.setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.valueOf(upperCaseInternal(getTextContent(maxSizePolicy))));
    }
    if (evictionPolicy != null) {
        evictionConfig.setEvictionPolicy(EvictionPolicy.valueOf(upperCaseInternal(getTextContent(evictionPolicy))));
    }
    return evictionConfig;
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) Node(org.w3c.dom.Node)

Example 5 with EvictionConfig

use of com.hazelcast.config.EvictionConfig in project hazelcast by hazelcast.

the class CacheEvictionPolicyComparatorTest method test_evictionPolicyComparator_with_comparatorInstance_when_maxSizePolicy_is_entryCount.

@Test
public void test_evictionPolicyComparator_with_comparatorInstance_when_maxSizePolicy_is_entryCount() {
    int partitionCount = Integer.parseInt(GroupProperty.PARTITION_COUNT.getDefaultValue());
    int iterationCount = (EntryCountCacheEvictionChecker.calculateMaxPartitionSize(EvictionConfig.DEFAULT_MAX_ENTRY_COUNT, partitionCount) * partitionCount) * 2;
    EvictionConfig evictionConfig = new EvictionConfig().setComparator(new MyEvictionPolicyComparator());
    do_test_evictionPolicyComparator(evictionConfig, iterationCount);
}
Also used : EvictionConfig(com.hazelcast.config.EvictionConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

EvictionConfig (com.hazelcast.config.EvictionConfig)13 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)2 Node (org.w3c.dom.Node)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)1 DistributedObject (com.hazelcast.core.DistributedObject)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LifecycleEvent (com.hazelcast.core.LifecycleEvent)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 ConfigValidator.checkEvictionConfig (com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig)1 EvictableEntryView (com.hazelcast.internal.eviction.EvictableEntryView)1 EvictionPolicyComparator (com.hazelcast.internal.eviction.EvictionPolicyComparator)1 NearCacheTestUtils.createNearCacheConfig (com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1