Search in sources :

Example 46 with Duration

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

the class IgniteCacheExpiryPolicyAbstractTest method testNearExpiresOnClient.

/**
 * Put entry to server node and check how its expires in client NearCache.
 *
 * @throws Exception If failed.
 */
@Test
public void testNearExpiresOnClient() throws Exception {
    if (cacheMode() != PARTITIONED)
        return;
    factory = CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 2));
    nearCache = true;
    startGrids();
    IgniteConfiguration clientCfg = getConfiguration("client");
    ((TcpDiscoverySpi) clientCfg.getDiscoverySpi()).setForceServerMode(false);
    Ignite client = startClientGrid("client", clientCfg);
    IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
    Integer key = 1;
    // Put on server node.
    jcache(0).put(key, 1);
    // Make entry cached in client NearCache.
    assertEquals(1, cache.get(key));
    assertEquals(1, cache.localPeek(key, CachePeekMode.NEAR));
    waitExpired(key);
    // Check client NearCache.
    assertNull(cache.localPeek(key, CachePeekMode.NEAR));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Duration(javax.cache.expiry.Duration) Ignite(org.apache.ignite.Ignite) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) IgniteCacheAbstractTest(org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest) Test(org.junit.Test)

Example 47 with Duration

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

the class IgniteCacheExpiryPolicyWithStoreAbstractTest method testLoadAll.

/**
 * @throws Exception If failed.
 */
@Test
public void testLoadAll() throws Exception {
    IgniteCache<Integer, Integer> cache = jcache(0);
    final Integer key = primaryKey(cache);
    storeMap.put(key, 100);
    try {
        CompletionListenerFuture fut = new CompletionListenerFuture();
        cache.loadAll(F.asSet(key), false, fut);
        fut.get();
        checkTtl(key, 500, false);
        assertEquals((Integer) 100, cache.localPeek(key, CachePeekMode.ONHEAP));
        U.sleep(600);
        checkExpired(key);
        cache = cache.withExpiryPolicy(new ExpiryPolicy() {

            @Override
            public Duration getExpiryForCreation() {
                return new Duration(TimeUnit.MILLISECONDS, 501);
            }

            @Override
            public Duration getExpiryForAccess() {
                return new Duration(TimeUnit.MILLISECONDS, 601);
            }

            @Override
            public Duration getExpiryForUpdate() {
                return new Duration(TimeUnit.MILLISECONDS, 701);
            }
        });
        fut = new CompletionListenerFuture();
        cache.loadAll(F.asSet(key), false, fut);
        fut.get();
        checkTtl(key, 501, false);
    } finally {
        cache.removeAll();
    }
}
Also used : ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration) CompletionListenerFuture(javax.cache.integration.CompletionListenerFuture) IgniteCacheAbstractTest(org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest) Test(org.junit.Test)

Example 48 with Duration

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

the class CacheQueryFilterExpiredTest method checkFilterExpired.

/**
 * @param ignite Node.
 * @param atomicityMode Cache atomicity mode.
 * @param eagerTtl Value for {@link CacheConfiguration#setEagerTtl(boolean)}.
 * @throws Exception If failed.
 */
private void checkFilterExpired(Ignite ignite, CacheAtomicityMode atomicityMode, boolean eagerTtl) throws Exception {
    CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setEagerTtl(eagerTtl);
    ccfg.setIndexedTypes(Integer.class, Integer.class);
    final IgniteCache<Integer, Integer> cache = ignite.createCache(ccfg);
    try {
        IgniteCache<Integer, Integer> expCache = cache.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(0, 2000)));
        for (int i = 0; i < 10; i++) {
            IgniteCache<Integer, Integer> cache0 = i % 2 == 0 ? cache : expCache;
            cache0.put(i, i);
        }
        assertEquals(10, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
        assertEquals(10, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size() == 5 && cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size() == 5;
            }
        }, 5000);
        assertEquals(5, cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size());
        assertEquals(5, cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size());
    } finally {
        ignite.destroyCache(ccfg.getName());
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 49 with Duration

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

the class Runner method main.

public static void main(String[] args) {
    ClientConnectorConfiguration connectorConfiguration = new ClientConnectorConfiguration().setPort(10890);
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder().setAddresses(Collections.singleton("127.0.0.1:47500"));
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi().setIpFinder(ipFinder).setSocketTimeout(300).setNetworkTimeout(300);
    CacheConfiguration expiryCacheCfg = new CacheConfiguration("twoSecondCache").setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 2))));
    IgniteConfiguration cfg = new IgniteConfiguration().setClientConnectorConfiguration(connectorConfiguration).setDiscoverySpi(discoSpi).setCacheConfiguration(expiryCacheCfg).setLocalHost("127.0.0.1");
    Ignition.start(cfg);
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 50 with Duration

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

the class CacheMvccTransactionsTest method testChangeExpireTime.

/**
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-7311")
@Test
public void testChangeExpireTime() throws Exception {
    final IgniteEx node = startGrid(0);
    IgniteCache cache = node.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, 64));
    cache.put(1, 1);
    final IgniteCache expiryCache = cache.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(TimeUnit.SECONDS, 1)));
    expiryCache.get(1);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) Ignore(org.junit.Ignore) Test(org.junit.Test)

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