Search in sources :

Example 56 with IgniteCache

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

the class IgniteVariousConnectionNumberTest method runOperations.

/**
 * @param time Execution time.
 * @throws Exception If failed.
 */
private void runOperations(final long time) throws Exception {
    final AtomicInteger idx = new AtomicInteger();
    GridTestUtils.runMultiThreaded(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Ignite node = ignite(idx.getAndIncrement() % NODES);
            IgniteCache cache = node.cache(DEFAULT_CACHE_NAME);
            long stopTime = U.currentTimeMillis() + time;
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (U.currentTimeMillis() < stopTime) {
                cache.put(rnd.nextInt(10_000), 0);
                node.compute().broadcast(new DummyJob());
            }
            return null;
        }
    }, NODES * 10, "test-thread");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCache(org.apache.ignite.IgniteCache) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite)

Example 57 with IgniteCache

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

the class GridCacheGetAndTransformStoreAbstractTest method testGetAndTransform.

/**
 * @throws Exception If failed.
 */
public void testGetAndTransform() throws Exception {
    final AtomicBoolean finish = new AtomicBoolean();
    try {
        startGrid(0);
        startGrid(1);
        startGrid(2);
        final Processor entryProcessor = new Processor();
        IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                IgniteCache<Integer, String> c = jcache(ThreadLocalRandom.current().nextInt(3));
                while (!finish.get() && !Thread.currentThread().isInterrupted()) {
                    c.get(ThreadLocalRandom.current().nextInt(100));
                    c.put(ThreadLocalRandom.current().nextInt(100), "s");
                    c.invoke(ThreadLocalRandom.current().nextInt(100), entryProcessor);
                }
                return null;
            }
        }, 20);
        Thread.sleep(15_000);
        finish.set(true);
        fut.get();
    } finally {
        stopGrid(0);
        stopGrid(1);
        stopGrid(2);
        while (jcache().localSize() != 0) jcache().clear();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EntryProcessor(javax.cache.processor.EntryProcessor) IgniteCache(org.apache.ignite.IgniteCache)

Example 58 with IgniteCache

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

the class CacheClientStoreSelfTest method testReplicatedLoadFromClient.

/**
 * Load cache created on client as REPLICATED and see if it only loaded on servers
 */
public void testReplicatedLoadFromClient() throws Exception {
    cacheMode = CacheMode.REPLICATED;
    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 59 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 60 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)

Aggregations

IgniteCache (org.apache.ignite.IgniteCache)402 Ignite (org.apache.ignite.Ignite)232 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