Search in sources :

Example 16 with IgniteCache

use of org.apache.ignite.IgniteCache in project ignite by apache.

the class CacheClientStoreSelfTest method testPartitionedLoadFromClient.

/**
 * Load cache created on client as REPLICATED and see if it only loaded on servers
 */
public void testPartitionedLoadFromClient() throws Exception {
    cacheMode = CacheMode.PARTITIONED;
    factory = new Factory3();
    startGrids(2);
    Ignite client = startGrid("client-1");
    IgniteCache cache = client.cache(CACHE_NAME);
    cache.loadCache(null);
    assertEquals(0, cache.localSize(CachePeekMode.ALL));
    assertEquals(10, grid(0).cache(CACHE_NAME).localSize(CachePeekMode.ALL));
    assertEquals(10, grid(1).cache(CACHE_NAME).localSize(CachePeekMode.ALL));
    assert !loadedFromClient : "Loaded data from client!";
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Example 17 with IgniteCache

use of org.apache.ignite.IgniteCache in project ignite by apache.

the class CacheConfigurationLeakTest method testCacheCreateLeak.

/**
 * @throws Exception If failed.
 */
public void testCacheCreateLeak() throws Exception {
    final Ignite ignite = grid();
    GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {

        @Override
        public void apply(Integer idx) {
            for (int i = 0; i < 100; i++) {
                CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
                ccfg.setName("cache-" + idx + "-" + i);
                ccfg.setEvictionPolicy(new LruEvictionPolicy(1000));
                ccfg.setOnheapCacheEnabled(true);
                IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
                for (int k = 0; k < 5000; k++) cache.put(k, new byte[1024]);
                ignite.destroyCache(cache.getName());
            }
        }
    }, 5, "cache-thread");
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) LruEvictionPolicy(org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)

Example 18 with IgniteCache

use of org.apache.ignite.IgniteCache in project ignite by apache.

the class CacheInterceptorPartitionCounterRandomOperationsTest method waitAndCheckEvent.

/**
 * @param cache Ignite cache.
 * @param partCntrs Partition counters.
 * @param aff Affinity function.
 * @param key Key.
 * @param val Value.
 * @param oldVal Old value.
 * @param rmv Remove operation.
 * @throws Exception If failed.
 */
private void waitAndCheckEvent(IgniteCache<Object, Object> cache, Map<Integer, Long> partCntrs, Affinity<Object> aff, Object key, Object val, Object oldVal, boolean rmv) throws Exception {
    Collection<BlockingQueue<Cache.Entry<TestKey, TestValue>>> entries = getInterceptorQueues(cache, key, rmv);
    assert !entries.isEmpty();
    if (val == null && oldVal == null) {
        checkNoEvent(entries);
        return;
    }
    for (BlockingQueue<Cache.Entry<TestKey, TestValue>> evtsQueue : entries) {
        Cache.Entry<TestKey, TestValue> entry = evtsQueue.poll(5, SECONDS);
        assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', entry);
        assertEquals(key, entry.getKey());
        assertEquals(rmv ? oldVal : val, entry.getValue());
        long cntr = partCntrs.get(aff.partition(key));
        CacheInterceptorEntry interceptorEntry = entry.unwrap(CacheInterceptorEntry.class);
        assertNotNull(cntr);
        assertNotNull(interceptorEntry);
        assertEquals(cntr, interceptorEntry.getPartitionUpdateCounter());
        assertNull(evtsQueue.peek());
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) CacheInterceptorEntry(org.apache.ignite.cache.CacheInterceptorEntry) MutableEntry(javax.cache.processor.MutableEntry) CacheInterceptorEntry(org.apache.ignite.cache.CacheInterceptorEntry) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 19 with IgniteCache

use of org.apache.ignite.IgniteCache in project ignite by apache.

the class CacheMetricsEntitiesCountTest method fillCache.

/**
 * @param igniteIdx Ignite index.
 * @param cacheIdx Cache index.
 */
private void fillCache(int igniteIdx, int cacheIdx) {
    log.info("Filling cache, igniteIdx=" + igniteIdx + ", cacheIdx=" + cacheIdx);
    IgniteCache cache = grid(igniteIdx).cache(CACHE_PREFIX + cacheIdx);
    for (int i = 0; i < ENTITIES_CNT; i++) cache.put("key" + igniteIdx + "-" + i, i);
}
Also used : IgniteCache(org.apache.ignite.IgniteCache)

Example 20 with IgniteCache

use of org.apache.ignite.IgniteCache in project ignite by apache.

the class CacheSerializableTransactionsTest method testNoReadLockConflictMultiNode.

/**
 * @throws Exception If failed.
 */
public void testNoReadLockConflictMultiNode() throws Exception {
    Ignite ignite0 = ignite(0);
    for (final CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
        logCacheInfo(ccfg);
        final AtomicInteger putKey = new AtomicInteger(1_000_000);
        ignite0.createCache(ccfg);
        try {
            final int THREADS = 64;
            IgniteCache<Integer, Integer> cache0 = ignite0.cache(ccfg.getName());
            List<Integer> readKeys = testKeys(cache0);
            for (final Integer readKey : readKeys) {
                final CyclicBarrier barrier = new CyclicBarrier(THREADS);
                cache0.put(readKey, Integer.MIN_VALUE);
                final AtomicInteger idx = new AtomicInteger();
                GridTestUtils.runMultiThreaded(new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        Ignite ignite = ignite(idx.incrementAndGet() % (CLIENTS + SRVS));
                        IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
                        try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
                            cache.get(readKey);
                            barrier.await();
                            cache.put(putKey.incrementAndGet(), 0);
                            tx.commit();
                        }
                        return null;
                    }
                }, THREADS, "test-thread");
                assertEquals((Integer) Integer.MIN_VALUE, cache0.get(readKey));
                cache0.put(readKey, readKey);
                assertEquals(readKey, cache0.get(readKey));
            }
        } finally {
            destroyCache(ccfg.getName());
        }
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteException(org.apache.ignite.IgniteException) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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