Search in sources :

Example 51 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.

the class IgniteCacheAtomicConcurrentUnorderedUpdateAllTest method testConcurrentUpdateAll.

/**
 * @throws Exception If failed.
 */
@Test
public void testConcurrentUpdateAll() throws Exception {
    Ignite ignite = startGridsMultiThreaded(NODES_CNT);
    Factory<CacheStore<Object, Object>> cacheStoreFactory = writeThrough ? new MapCacheStoreStrategy.MapStoreFactory() : null;
    IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>(CACHE_NAME).setWriteThrough(writeThrough).setCacheStoreFactory(cacheStoreFactory).setCacheMode(cacheMode).setAtomicityMode(ATOMIC).setBackups(1));
    CyclicBarrier barrier = new CyclicBarrier(THREADS_CNT);
    AtomicInteger threadCnt = new AtomicInteger();
    GridTestUtils.runMultiThreaded(() -> {
        int threadIdx = threadCnt.incrementAndGet();
        IgniteCache<Object, Object> cache0 = grid(ThreadLocalRandom.current().nextInt(NODES_CNT)).cache(CACHE_NAME);
        Map<Object, Object> map = new LinkedHashMap<>();
        if (threadIdx % 2 == 0) {
            for (int i = 0; i < CACHE_SIZE; i++) map.put(i, i);
        } else {
            for (int i = CACHE_SIZE - 1; i >= 0; i--) map.put(i, i);
        }
        for (int i = 0; i < 20; i++) {
            try {
                barrier.await();
            } catch (Exception e) {
                fail(e.getMessage());
            }
            cache0.putAll(map);
            cache0.removeAll(map.keySet());
            log.info("Thread " + threadIdx + " iteration " + i + " finished");
        }
    }, THREADS_CNT, "update-all-runner");
    assertEquals(0, cache.size());
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) CacheStore(org.apache.ignite.cache.store.CacheStore) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 52 with CacheStore

use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.

the class GridCachePartitionedReloadAllAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cc = defaultCacheConfiguration();
    if (!nearEnabled())
        cc.setNearConfiguration(null);
    cc.setCacheMode(cacheMode());
    cc.setAtomicityMode(atomicityMode());
    cc.setBackups(BACKUP_CNT);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    CacheStore store = cacheStore();
    if (store != null) {
        cc.setCacheStoreFactory(singletonFactory(store));
        cc.setReadThrough(true);
        cc.setWriteThrough(true);
        cc.setLoadPreviousValue(true);
    } else
        cc.setCacheStoreFactory(null);
    c.setCacheConfiguration(cc);
    return c;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheStore(org.apache.ignite.cache.store.CacheStore) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheStore (org.apache.ignite.cache.store.CacheStore)52 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)23 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 Test (org.junit.Test)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 Map (java.util.Map)12 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)12 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)11 SimplePerson (org.apache.ignite.tests.pojos.SimplePerson)8 Ignite (org.apache.ignite.Ignite)6 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)6 Person (org.apache.ignite.tests.pojos.Person)6 Product (org.apache.ignite.tests.pojos.Product)6 ProductOrder (org.apache.ignite.tests.pojos.ProductOrder)6 CacheStoreManager (org.apache.ignite.internal.processors.cache.store.CacheStoreManager)5 ArrayList (java.util.ArrayList)4 GridCacheTestStore (org.apache.ignite.internal.processors.cache.GridCacheTestStore)4 CacheDataStructuresManager (org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager)4 GridDhtCache (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache)4 GridDhtCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter)4