Search in sources :

Example 1 with PlatformExpiryPolicyFactory

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory in project ignite by apache.

the class IgniteCacheGroupsTest method entriesTtl.

/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Cache atomicity mode.
 * @throws Exception If failed.
 */
private void entriesTtl(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
    int keys = 10000;
    final int ttl = 10000;
    Integer[] data1 = generateData(keys);
    Integer[] data2 = generateData(keys);
    boolean loc = cacheMode == LOCAL;
    if (loc)
        startGrid(0);
    else
        startGridsMultiThreaded(4);
    Ignite srv0 = ignite(0);
    srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false).setExpiryPolicyFactory(new PlatformExpiryPolicyFactory(-1, -2, ttl)).setEagerTtl(true));
    srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false));
    if (!loc)
        awaitPartitionMapExchange();
    if (atomicityMode == TRANSACTIONAL) {
        Ignite ignite = ignite(loc ? 0 : 1);
        IgniteCache cache1 = ignite.cache(CACHE1);
        IgniteCache cache2 = ignite.cache(CACHE2);
        try (Transaction tx = ignite.transactions().txStart()) {
            for (int i = 0; i < keys; i++) {
                cache1.put(i, data1[i]);
                cache2.put(i, data2[i]);
            }
            tx.commit();
        }
    } else {
        // async put ops
        int ldrs = 4;
        List<Callable<?>> cls = new ArrayList<>(ldrs * 2);
        for (int i = 0; i < ldrs; i++) {
            cls.add(putOperation(loc ? 0 : 1, ldrs, i, CACHE1, data1));
            cls.add(putOperation(loc ? 0 : 2, ldrs, i, CACHE2, data2));
        }
        GridTestUtils.runMultiThreaded(cls, "loaders");
    }
    checkData(loc ? 0 : 3, CACHE1, data1);
    checkData(loc ? 0 : 3, CACHE2, data2);
    srv0.destroyCache(CACHE2);
    checkData(loc ? 0 : 3, CACHE1, data1);
    // Wait for expiration
    Thread.sleep((long) (ttl * 1.2));
    assertEquals(0, ignite(loc ? 0 : 3).cache(CACHE1).size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) PlatformExpiryPolicyFactory(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory) IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) Callable(java.util.concurrent.Callable) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable)

Example 2 with PlatformExpiryPolicyFactory

use of org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory in project ignite by apache.

the class PlatformConfigurationUtils method writeExpiryPolicyFactory.

/**
 * Writes the policy factory.
 *
 * @param out Writer.
 */
public static void writeExpiryPolicyFactory(BinaryRawWriter out, Factory<? extends ExpiryPolicy> factory) {
    if (!(factory instanceof PlatformExpiryPolicyFactory)) {
        out.writeBoolean(false);
        return;
    }
    out.writeBoolean(true);
    PlatformExpiryPolicyFactory f = (PlatformExpiryPolicyFactory) factory;
    out.writeLong(f.getCreate());
    out.writeLong(f.getUpdate());
    out.writeLong(f.getAccess());
}
Also used : PlatformExpiryPolicyFactory(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory)

Aggregations

PlatformExpiryPolicyFactory (org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory)2 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 GridPlainCallable (org.apache.ignite.internal.util.lang.GridPlainCallable)1 Transaction (org.apache.ignite.transactions.Transaction)1