Search in sources :

Example 1 with EvictionPolicyComparator

use of com.hazelcast.internal.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class ConfigValidator method checkEvictionConfig.

/**
     * Checks if a {@link EvictionConfig} is valid in its context.
     *
     * @param evictionConfig the {@link EvictionConfig}
     * @param isNearCache    {@code true} if the config is for a Near Cache, {@code false} otherwise
     */
@SuppressWarnings("ConstantConditions")
public static void checkEvictionConfig(EvictionConfig evictionConfig, boolean isNearCache) {
    if (evictionConfig == null) {
        throw new IllegalArgumentException("Eviction config cannot be null!");
    }
    EvictionPolicy evictionPolicy = evictionConfig.getEvictionPolicy();
    String comparatorClassName = evictionConfig.getComparatorClassName();
    EvictionPolicyComparator comparator = evictionConfig.getComparator();
    checkEvictionConfig(evictionPolicy, comparatorClassName, comparator, isNearCache);
}
Also used : EvictionPolicy(com.hazelcast.config.EvictionPolicy) EvictionPolicyComparator(com.hazelcast.internal.eviction.EvictionPolicyComparator)

Example 2 with EvictionPolicyComparator

use of com.hazelcast.internal.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class CacheEvictionConfigTest method test_cacheEvictionConfig_shouldInheritConstructors_from_evictionConfig_correctly.

@Test
public void test_cacheEvictionConfig_shouldInheritConstructors_from_evictionConfig_correctly() {
    CacheEvictionConfig cacheEvictionConfig1 = new CacheEvictionConfig(1000, MaxSizePolicy.ENTRY_COUNT, LFU);
    assertEquals(1000, cacheEvictionConfig1.getSize());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig1.getMaximumSizePolicy());
    assertEquals(LFU, cacheEvictionConfig1.getEvictionPolicy());
    assertNotNull(cacheEvictionConfig1.toString());
    CacheEvictionConfig cacheEvictionConfig2 = new CacheEvictionConfig(1000, CacheMaxSizePolicy.ENTRY_COUNT, LFU);
    assertEquals(1000, cacheEvictionConfig2.getSize());
    assertEquals(CacheMaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig2.getMaxSizePolicy());
    assertEquals(LFU, cacheEvictionConfig2.getEvictionPolicy());
    assertNotNull(cacheEvictionConfig2.toString());
    String comparatorName = "myComparator";
    CacheEvictionConfig cacheEvictionConfig3 = new CacheEvictionConfig(1000, MaxSizePolicy.ENTRY_COUNT, comparatorName);
    assertEquals(1000, cacheEvictionConfig3.getSize());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig3.getMaximumSizePolicy());
    assertEquals(comparatorName, cacheEvictionConfig3.getComparatorClassName());
    assertNotNull(cacheEvictionConfig3.toString());
    CacheEvictionConfig cacheEvictionConfig4 = new CacheEvictionConfig(1000, CacheMaxSizePolicy.ENTRY_COUNT, comparatorName);
    assertEquals(1000, cacheEvictionConfig4.getSize());
    assertEquals(CacheMaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig4.getMaxSizePolicy());
    assertEquals(comparatorName, cacheEvictionConfig4.getComparatorClassName());
    assertNotNull(cacheEvictionConfig4.toString());
    EvictionPolicyComparator comparator = new EvictionPolicyComparator() {

        @Override
        public int compare(EvictableEntryView e1, EvictableEntryView e2) {
            return 0;
        }
    };
    CacheEvictionConfig cacheEvictionConfig5 = new CacheEvictionConfig(1000, MaxSizePolicy.ENTRY_COUNT, comparator);
    assertEquals(1000, cacheEvictionConfig5.getSize());
    assertEquals(MaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig5.getMaximumSizePolicy());
    assertEquals(comparator, cacheEvictionConfig5.getComparator());
    assertNotNull(cacheEvictionConfig5.toString());
    CacheEvictionConfig cacheEvictionConfig6 = new CacheEvictionConfig(1000, CacheMaxSizePolicy.ENTRY_COUNT, comparator);
    assertEquals(1000, cacheEvictionConfig6.getSize());
    assertEquals(CacheMaxSizePolicy.ENTRY_COUNT, cacheEvictionConfig6.getMaxSizePolicy());
    assertEquals(comparator, cacheEvictionConfig6.getComparator());
    assertNotNull(cacheEvictionConfig6.toString());
}
Also used : EvictableEntryView(com.hazelcast.internal.eviction.EvictableEntryView) EvictionPolicyComparator(com.hazelcast.internal.eviction.EvictionPolicyComparator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with EvictionPolicyComparator

use of com.hazelcast.internal.eviction.EvictionPolicyComparator in project hazelcast by hazelcast.

the class ConfigValidatorTest method getEvictionConfig.

private EvictionConfig getEvictionConfig(boolean setComparatorClass, boolean setComparator, EvictionPolicy evictionPolicy) {
    EvictionConfig evictionConfig = new EvictionConfig();
    if (setComparatorClass) {
        evictionConfig.setComparatorClassName("myComparatorClass");
    }
    if (setComparator) {
        evictionConfig.setComparator(new EvictionPolicyComparator() {

            @Override
            @SuppressWarnings("ComparatorMethodParameterNotUsed")
            public int compare(EvictableEntryView e1, EvictableEntryView e2) {
                return 0;
            }

            @Override
            @SuppressWarnings("ComparatorMethodParameterNotUsed")
            public int compare(Object o1, Object o2) {
                return 0;
            }
        });
    }
    evictionConfig.setEvictionPolicy(evictionPolicy);
    return evictionConfig;
}
Also used : EvictableEntryView(com.hazelcast.internal.eviction.EvictableEntryView) ConfigValidator.checkEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) EvictionPolicyComparator(com.hazelcast.internal.eviction.EvictionPolicyComparator)

Aggregations

EvictionPolicyComparator (com.hazelcast.internal.eviction.EvictionPolicyComparator)3 EvictableEntryView (com.hazelcast.internal.eviction.EvictableEntryView)2 EvictionConfig (com.hazelcast.config.EvictionConfig)1 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 ConfigValidator.checkEvictionConfig (com.hazelcast.internal.config.ConfigValidator.checkEvictionConfig)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1