use of org.apache.ignite.IgniteCache in project ignite by apache.
the class MemoryPolicyInitializationTest method testCachesOnUserDefinedDefaultMemoryPolicy.
/**
* Test for verification that caches with not specified memory policy name,
* with specified default memory policy name and specified custom memory policy name
* all started with correct memory policy.
*/
public void testCachesOnUserDefinedDefaultMemoryPolicy() throws Exception {
prepareCustomConfigWithOverriddenDefaultName();
IgniteEx ignite = startGrid(0);
CacheConfiguration cache1Cfg = new CacheConfiguration().setName("cache1");
IgniteCache cache1 = ignite.createCache(cache1Cfg);
verifyCacheMemoryPolicy(cache1, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
CacheConfiguration cache2Cfg = new CacheConfiguration().setName("cache2").setMemoryPolicyName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
IgniteCache cache2 = ignite.createCache(cache2Cfg);
verifyCacheMemoryPolicy(cache2, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
CacheConfiguration cache3Cfg = new CacheConfiguration().setName("cache3").setMemoryPolicyName(DFLT_MEM_PLC_DEFAULT_NAME);
IgniteCache cache3 = ignite.createCache(cache3Cfg);
verifyCacheMemoryPolicy(cache3, DFLT_MEM_PLC_DEFAULT_NAME);
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class MemoryPolicyInitializationTest method testCachesOnOverriddenMemoryPolicy.
/**
* Test for verification that caches with not specified memory policy name,
* with specified default memory policy name and specified custom memory policy name
* all started with correct memory policy.
*/
public void testCachesOnOverriddenMemoryPolicy() throws Exception {
prepareCustomConfigWithOverridingDefaultAndCustom();
IgniteEx ignite = startGrid(0);
CacheConfiguration cache1Cfg = new CacheConfiguration().setName("cache1");
IgniteCache cache1 = ignite.createCache(cache1Cfg);
verifyCacheMemoryPolicy(cache1, DFLT_MEM_PLC_DEFAULT_NAME);
CacheConfiguration cache2Cfg = new CacheConfiguration().setName("cache2").setMemoryPolicyName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
IgniteCache cache2 = ignite.createCache(cache2Cfg);
verifyCacheMemoryPolicy(cache2, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
CacheConfiguration cache3Cfg = new CacheConfiguration().setName("cache3").setMemoryPolicyName(DFLT_MEM_PLC_DEFAULT_NAME);
IgniteCache cache3 = ignite.createCache(cache3Cfg);
verifyCacheMemoryPolicy(cache3, DFLT_MEM_PLC_DEFAULT_NAME);
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class IgniteCacheNearOnlyTxTest method testConcurrentTx.
/**
* @throws Exception If failed.
*/
public void testConcurrentTx() throws Exception {
final Ignite ignite1 = ignite(1);
assertTrue(ignite1.configuration().isClientMode());
ignite1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
final Integer key = 1;
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, Integer> cache = ignite1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) cache.put(key, 1);
return null;
}
}, 5, "put1-thread");
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, Integer> cache = ignite1.cache(DEFAULT_CACHE_NAME);
IgniteTransactions txs = ignite1.transactions();
for (int i = 0; i < 100; i++) {
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get(key);
cache.put(key, 1);
tx.commit();
}
}
return null;
}
}, 5, "put2-thread");
fut1.get();
fut2.get();
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class NearCachePutAllMultinodeTest method testMultithreadedPutAll.
/**
* @throws Exception If failed.
*/
public void testMultithreadedPutAll() throws Exception {
final AtomicInteger idx = new AtomicInteger();
runMultiThreaded(new Callable<Object>() {
private final Random rnd = new Random();
@Override
public Object call() throws Exception {
int threadIdx = idx.getAndIncrement();
int node = threadIdx % 2 + (GRID_CNT - 2);
IgniteCache<Object, Object> cache = jcache(node);
for (int i = 0; i < TX_CNT; i++) {
Map<Integer, String> map = new TreeMap<>();
for (int j = 0; j < 3; j++) map.put(rnd.nextInt(10), "value");
cache.putAll(map);
if (i % 100 == 0)
log.info("Iteration: " + i + " " + node);
}
return null;
}
}, 8, "putAll");
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class WalModeChangeAdvancedSelfTest method testCacheCleanup.
/**
* Test cache cleanup on restart.
*
* @throws Exception If failed.
*/
public void testCacheCleanup() throws Exception {
Ignite srv = startGrid(config(SRV_1, false, false));
srv.cluster().active(true);
IgniteCache cache1 = srv.getOrCreateCache(cacheConfig(CACHE_NAME, PARTITIONED, TRANSACTIONAL));
IgniteCache cache2 = srv.getOrCreateCache(cacheConfig(CACHE_NAME_2, PARTITIONED, TRANSACTIONAL));
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, true);
for (int i = 0; i < 10; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
srv.cluster().disableWal(CACHE_NAME);
assertForAllNodes(CACHE_NAME, false);
assertForAllNodes(CACHE_NAME_2, true);
for (int i = 10; i < 20; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
srv.cluster().disableWal(CACHE_NAME_2);
assertForAllNodes(CACHE_NAME, false);
assertForAllNodes(CACHE_NAME_2, false);
for (int i = 20; i < 30; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
assertEquals(cache1.size(), 30);
assertEquals(cache2.size(), 30);
srv.cluster().enableWal(CACHE_NAME);
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, false);
assertEquals(cache1.size(), 30);
assertEquals(cache2.size(), 30);
stopAllGrids(true);
srv = startGrid(config(SRV_1, false, false));
srv.cluster().active(true);
cache1 = srv.cache(CACHE_NAME);
cache2 = srv.cache(CACHE_NAME_2);
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, false);
assertEquals(30, cache1.size());
assertEquals(0, cache2.size());
}
Aggregations