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());
}
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;
}
Aggregations