Search in sources :

Example 1 with CacheStoreAdapter

use of org.apache.ignite.cache.store.CacheStoreAdapter in project ignite by apache.

the class IgniteCacheStoreValueAbstractTest method cacheConfiguration.

/** {@inheritDoc} */
@Override
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
    CacheConfiguration ccfg = super.cacheConfiguration(igniteInstanceName);
    if (ccfg.getCacheMode() != CacheMode.LOCAL)
        assertEquals(1, ccfg.getBackups());
    assertTrue(ccfg.isCopyOnRead());
    ccfg.setCopyOnRead(cpyOnRead);
    assertEquals(FULL_SYNC, ccfg.getWriteSynchronizationMode());
    ccfg.setCacheStoreFactory(singletonFactory(new CacheStoreAdapter() {

        @Override
        public void loadCache(IgniteBiInClosure clo, Object... args) {
            clo.apply(new TestKey(100_000), new TestValue(30_000));
        }

        @Override
        public Object load(Object key) throws CacheLoaderException {
            return null;
        }

        @Override
        public void write(Cache.Entry entry) throws CacheWriterException {
        // No-op.
        }

        @Override
        public void delete(Object key) throws CacheWriterException {
        // No-op.
        }
    }));
    ccfg.setInterceptor(new TestInterceptor());
    return ccfg;
}
Also used : MutableEntry(javax.cache.processor.MutableEntry) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with CacheStoreAdapter

use of org.apache.ignite.cache.store.CacheStoreAdapter in project ignite by apache.

the class GridCacheReloadSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setLocalHost("127.0.0.1");
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500"));
    discoSpi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(discoSpi);
    CacheConfiguration cacheCfg = defaultCacheConfiguration();
    cacheCfg.setName(CACHE_NAME);
    cacheCfg.setCacheMode(cacheMode);
    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(MAX_CACHE_ENTRIES);
    cacheCfg.setEvictionPolicy(plc);
    cacheCfg.setOnheapCacheEnabled(true);
    cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null);
    final CacheStore store = new CacheStoreAdapter<Integer, Integer>() {

        @Override
        public Integer load(Integer key) {
            return key;
        }

        @Override
        public void write(javax.cache.Cache.Entry<? extends Integer, ? extends Integer> e) {
        //No-op.
        }

        @Override
        public void delete(Object key) {
        //No-op.
        }
    };
    cacheCfg.setCacheStoreFactory(singletonFactory(store));
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    if (cacheMode == PARTITIONED)
        cacheCfg.setBackups(1);
    cfg.setCacheConfiguration(cacheCfg);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) CacheStore(org.apache.ignite.cache.store.CacheStore) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 3 with CacheStoreAdapter

use of org.apache.ignite.cache.store.CacheStoreAdapter in project ignite by apache.

the class CacheTtlAbstractSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(cacheMode());
    ccfg.setAtomicityMode(atomicityMode());
    LruEvictionPolicy plc = new LruEvictionPolicy();
    plc.setMaxSize(MAX_CACHE_SIZE);
    ccfg.setEvictionPolicy(plc);
    ccfg.setOnheapCacheEnabled(true);
    ccfg.setIndexedTypes(Integer.class, Integer.class);
    ccfg.setBackups(2);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setRebalanceMode(SYNC);
    ccfg.setCacheStoreFactory(singletonFactory(new CacheStoreAdapter() {

        @Override
        public void loadCache(IgniteBiInClosure clo, Object... args) {
            for (int i = 0; i < SIZE; i++) clo.apply(i, i);
        }

        @Override
        public Object load(Object key) throws CacheLoaderException {
            return key;
        }

        @Override
        public void write(Cache.Entry entry) throws CacheWriterException {
        // No-op.
        }

        @Override
        public void delete(Object key) throws CacheWriterException {
        // No-op.
        }
    }));
    ccfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new TouchedExpiryPolicy(new Duration(MILLISECONDS, DEFAULT_TIME_TO_LIVE))));
    cfg.setCacheConfiguration(ccfg);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Duration(javax.cache.expiry.Duration) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

CacheStoreAdapter (org.apache.ignite.cache.store.CacheStoreAdapter)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteBiInClosure (org.apache.ignite.lang.IgniteBiInClosure)2 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)2 Duration (javax.cache.expiry.Duration)1 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)1 MutableEntry (javax.cache.processor.MutableEntry)1 CacheStore (org.apache.ignite.cache.store.CacheStore)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)1