Search in sources :

Example 1 with TimedExpiryPolicyFactoryConfig

use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.

the class CacheConfigTest method cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory.

@Test
public void cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory() throws IOException {
    Config config1 = new XmlConfigBuilder(configUrl1).build();
    CacheSimpleConfig cacheWithTimedAccessedExpiryPolicyFactoryConfig = config1.getCacheConfig("cacheWithTimedAccessedExpiryPolicyFactory");
    ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedAccessedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
    TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
    DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
    assertNotNull(expiryPolicyFactoryConfig);
    assertNotNull(timedExpiryPolicyFactoryConfig);
    assertNotNull(durationConfig);
    assertNull(expiryPolicyFactoryConfig.getClassName());
    assertEquals(ExpiryPolicyType.ACCESSED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
    assertEquals(2, durationConfig.getDurationAmount());
    assertEquals(TimeUnit.HOURS, durationConfig.getTimeUnit());
}
Also used : TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with TimedExpiryPolicyFactoryConfig

use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.

the class CacheConfigTest method cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory.

@Test
public void cacheConfigXmlTest_TimedModifiedTouchedPolicyFactory() throws IOException {
    Config config1 = new XmlConfigBuilder(configUrl1).build();
    CacheSimpleConfig cacheWithTimedTouchedExpiryPolicyFactoryConfig = config1.getCacheConfig("cacheWithTimedTouchedExpiryPolicyFactory");
    ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedTouchedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
    TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
    DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
    assertNotNull(expiryPolicyFactoryConfig);
    assertNotNull(timedExpiryPolicyFactoryConfig);
    assertNotNull(durationConfig);
    assertNull(expiryPolicyFactoryConfig.getClassName());
    assertEquals(ExpiryPolicyType.TOUCHED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
    assertEquals(4, durationConfig.getDurationAmount());
    assertEquals(TimeUnit.SECONDS, durationConfig.getTimeUnit());
}
Also used : TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with TimedExpiryPolicyFactoryConfig

use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.

the class CacheConfig method initExpiryPolicyFactoryConfig.

private void initExpiryPolicyFactoryConfig(CacheSimpleConfig simpleConfig) throws Exception {
    CacheSimpleConfig.ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = simpleConfig.getExpiryPolicyFactoryConfig();
    if (expiryPolicyFactoryConfig != null) {
        if (expiryPolicyFactoryConfig.getClassName() != null) {
            setExpiryPolicyFactory(ClassLoaderUtil.newInstance(null, expiryPolicyFactoryConfig.getClassName()));
        } else {
            TimedExpiryPolicyFactoryConfig timedExpiryPolicyConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
            if (timedExpiryPolicyConfig != null) {
                DurationConfig durationConfig = timedExpiryPolicyConfig.getDurationConfig();
                ExpiryPolicyType expiryPolicyType = timedExpiryPolicyConfig.getExpiryPolicyType();
                switch(expiryPolicyType) {
                    case CREATED:
                        setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
                        break;
                    case MODIFIED:
                        setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
                        break;
                    case ACCESSED:
                        setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
                        break;
                    case TOUCHED:
                        setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(durationConfig.getTimeUnit(), durationConfig.getDurationAmount())));
                        break;
                    case ETERNAL:
                        setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
                        break;
                    default:
                        throw new IllegalArgumentException("Unsupported expiry policy type: " + expiryPolicyType);
                }
            }
        }
    }
}
Also used : TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) Duration(javax.cache.expiry.Duration) ExpiryPolicyType(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType)

Example 4 with TimedExpiryPolicyFactoryConfig

use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.

the class TestJCache method cacheConfigXmlTest_TimedEternalTouchedPolicyFactory.

@Test
public void cacheConfigXmlTest_TimedEternalTouchedPolicyFactory() {
    Config config = instance1.getConfig();
    CacheSimpleConfig cacheWithTimedEternalExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedEternalExpiryPolicyFactory");
    ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedEternalExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
    TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
    DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
    assertNotNull(expiryPolicyFactoryConfig);
    assertNotNull(timedExpiryPolicyFactoryConfig);
    assertNull(durationConfig);
    assertNull(expiryPolicyFactoryConfig.getClassName());
    assertEquals(ExpiryPolicyType.ETERNAL, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
}
Also used : ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with TimedExpiryPolicyFactoryConfig

use of com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig in project hazelcast by hazelcast.

the class TestJCache method cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory.

@Test
public void cacheConfigXmlTest_TimedAccessedExpiryPolicyFactory() {
    Config config = instance1.getConfig();
    CacheSimpleConfig cacheWithTimedAccessedExpiryPolicyFactoryConfig = config.getCacheConfig("cacheWithTimedAccessedExpiryPolicyFactory");
    ExpiryPolicyFactoryConfig expiryPolicyFactoryConfig = cacheWithTimedAccessedExpiryPolicyFactoryConfig.getExpiryPolicyFactoryConfig();
    TimedExpiryPolicyFactoryConfig timedExpiryPolicyFactoryConfig = expiryPolicyFactoryConfig.getTimedExpiryPolicyFactoryConfig();
    DurationConfig durationConfig = timedExpiryPolicyFactoryConfig.getDurationConfig();
    assertNotNull(expiryPolicyFactoryConfig);
    assertNotNull(timedExpiryPolicyFactoryConfig);
    assertNotNull(durationConfig);
    assertNull(expiryPolicyFactoryConfig.getClassName());
    assertEquals(ExpiryPolicyType.ACCESSED, timedExpiryPolicyFactoryConfig.getExpiryPolicyType());
    assertEquals(2, durationConfig.getDurationAmount());
    assertEquals(TimeUnit.HOURS, durationConfig.getTimeUnit());
}
Also used : ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) MergePolicyConfig(com.hazelcast.config.MergePolicyConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TimedExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig)14 DurationConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig)13 ExpiryPolicyFactoryConfig (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig)11 Test (org.junit.Test)11 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)5 Config (com.hazelcast.config.Config)5 EvictionConfig (com.hazelcast.config.EvictionConfig)5 MergePolicyConfig (com.hazelcast.config.MergePolicyConfig)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 ExpiryPolicyType (com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig.ExpiryPolicyType)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 TimeUnit (java.util.concurrent.TimeUnit)1 Duration (javax.cache.expiry.Duration)1