Search in sources :

Example 81 with Duration

use of javax.cache.expiry.Duration in project ignite by apache.

the class IgnitePdsContinuousRestartTestWithExpiryPolicy method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setName(CACHE_NAME);
    ccfg.setGroupName("Group1");
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 128));
    ccfg.setBackups(2);
    ccfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 1)));
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Duration(javax.cache.expiry.Duration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 82 with Duration

use of javax.cache.expiry.Duration in project ignite by apache.

the class IgnitePdsCacheEntriesExpirationTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    DataStorageConfiguration dsCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(1024L * 1024 * 1024).setPersistenceEnabled(true)).setWalMode(WALMode.LOG_ONLY).setCheckpointFrequency(60_000);
    cfg.setDataStorageConfiguration(dsCfg);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 2)).setBackups(1).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 350)));
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Duration(javax.cache.expiry.Duration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 83 with Duration

use of javax.cache.expiry.Duration in project ignite by apache.

the class IgniteCacheExpiryStoreLoadSelfTest method checkLocalLoad.

/**
 * @param async If {@code true} uses asynchronous method.
 * @throws Exception If failed.
 */
private void checkLocalLoad(boolean async) throws Exception {
    final IgniteCache<String, Integer> cache = jcache(0).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
    List<Integer> keys = primaryKeys(cache, 3);
    if (async)
        cache.localLoadCacheAsync(null, keys.toArray(new Integer[3])).get();
    else
        cache.localLoadCache(null, keys.toArray(new Integer[3]));
    assertEquals(3, cache.localSize());
    boolean res = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return cache.localSize() == 0;
        }
    }, TIME_TO_LIVE + WAIT_TIME);
    assertTrue(res);
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy)

Example 84 with Duration

use of javax.cache.expiry.Duration in project ignite by apache.

the class IgniteCacheExpiryStoreLoadSelfTest method checkLoad.

/**
 * @param async If {@code true} uses asynchronous method.
 * @throws Exception If failed.
 */
private void checkLoad(boolean async) throws Exception {
    IgniteCache<String, Integer> cache = jcache(0).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
    List<Integer> keys = new ArrayList<>();
    keys.add(primaryKey(jcache(0)));
    keys.add(primaryKey(jcache(1)));
    keys.add(primaryKey(jcache(2)));
    if (async)
        cache.loadCacheAsync(null, keys.toArray(new Integer[3])).get();
    else
        cache.loadCache(null, keys.toArray(new Integer[3]));
    assertEquals(3, cache.size(CachePeekMode.PRIMARY));
    Thread.sleep(TIME_TO_LIVE + WAIT_TIME);
    assertEquals(0, cache.size());
}
Also used : ArrayList(java.util.ArrayList) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy)

Example 85 with Duration

use of javax.cache.expiry.Duration in project ignite by apache.

the class IgniteCacheExpiryStoreLoadSelfTest method testLoadAllWithExpiry.

/**
 * @throws Exception If failed.
 */
@Test
public void testLoadAllWithExpiry() throws Exception {
    IgniteCache<Integer, Integer> cache = ignite(0).<Integer, Integer>cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
    Set<Integer> keys = new HashSet<>();
    keys.add(primaryKey(jcache(0)));
    keys.add(primaryKey(jcache(1)));
    keys.add(primaryKey(jcache(2)));
    CompletionListenerFuture fut = new CompletionListenerFuture();
    cache.loadAll(keys, false, fut);
    fut.get();
    assertEquals(3, cache.size(CachePeekMode.PRIMARY));
    Thread.sleep(TIME_TO_LIVE + WAIT_TIME);
    assertEquals(0, cache.size());
}
Also used : Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CompletionListenerFuture(javax.cache.integration.CompletionListenerFuture) HashSet(java.util.HashSet) Test(org.junit.Test) GridCacheAbstractSelfTest(org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest)

Aggregations

Duration (javax.cache.expiry.Duration)119 Test (org.junit.Test)49 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)36 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)31 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)31 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)29 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 ModifiedExpiryPolicy (javax.cache.expiry.ModifiedExpiryPolicy)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)12 Ignite (org.apache.ignite.Ignite)11 Transaction (org.apache.ignite.transactions.Transaction)11 CacheLoaderException (javax.cache.integration.CacheLoaderException)10 ArrayList (java.util.ArrayList)9 IgniteCache (org.apache.ignite.IgniteCache)9 MutableConfiguration (javax.cache.configuration.MutableConfiguration)8 CacheWriterException (javax.cache.integration.CacheWriterException)8 CacheNotExistsException (com.hazelcast.cache.CacheNotExistsException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7