Search in sources :

Example 41 with IgniteCache

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);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 42 with IgniteCache

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);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 43 with IgniteCache

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) IgniteTransactions(org.apache.ignite.IgniteTransactions)

Example 44 with IgniteCache

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");
}
Also used : Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCache(org.apache.ignite.IgniteCache) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 45 with IgniteCache

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());
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Aggregations

IgniteCache (org.apache.ignite.IgniteCache)403 Ignite (org.apache.ignite.Ignite)233 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)137 Cache (javax.cache.Cache)98 Transaction (org.apache.ignite.transactions.Transaction)87 ArrayList (java.util.ArrayList)69 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)65 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)60 Map (java.util.Map)55 IgniteException (org.apache.ignite.IgniteException)55 List (java.util.List)51 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)48 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)46 HashMap (java.util.HashMap)45 CacheException (javax.cache.CacheException)43 Random (java.util.Random)37 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)32 CountDownLatch (java.util.concurrent.CountDownLatch)30 ClusterNode (org.apache.ignite.cluster.ClusterNode)30 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)28