Search in sources :

Example 36 with Ignite

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

the class IgniteCacheObjectKeyIndexingSelfTest method testObjectKeyHandling.

/**
 */
public void testObjectKeyHandling() throws Exception {
    Ignite ignite = grid();
    IgniteCache<Object, TestObject> cache = ignite.getOrCreateCache(cacheCfg());
    UUID uid = UUID.randomUUID();
    cache.put(uid, new TestObject("A"));
    assertItemsNumber(1);
    cache.put(1, new TestObject("B"));
    assertItemsNumber(2);
    cache.put(uid, new TestObject("C"));
    // Key should have been replaced
    assertItemsNumber(2);
    List<List<?>> res = cache.query(new SqlFieldsQuery("select _key, name from TestObject order by name")).getAll();
    assertEquals(res, Arrays.asList(Arrays.asList(1, "B"), Arrays.asList(uid, "C")));
    cache.remove(1);
    assertItemsNumber(1);
    res = cache.query(new SqlFieldsQuery("select _key, name from TestObject")).getAll();
    assertEquals(res, Collections.singletonList(Arrays.asList(uid, "C")));
    cache.remove(uid);
    // Removal has worked for both keys although the table was the same and keys were of different type
    assertItemsNumber(0);
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) UUID(java.util.UUID) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 37 with Ignite

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

the class IgfsStartCacheTest method testCacheStart.

/**
 * @throws Exception If failed.
 */
public void testCacheStart() throws Exception {
    Ignite g0 = G.start(config(true, 0));
    String dataCacheName = ((IgniteEx) g0).igfsx("igfs").configuration().getDataCacheConfiguration().getName();
    String metaCacheName = ((IgniteEx) g0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName();
    checkIgfsCaches(g0, dataCacheName, metaCacheName);
    Ignite g1 = G.start(config(false, 1));
    checkIgfsCaches(g1, dataCacheName, metaCacheName);
    IgniteFileSystem igfs = g0.fileSystem("igfs");
    igfs.mkdirs(new IgfsPath("/test"));
    try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create(new IgfsPath("/test/test.file"), true)))) {
        for (int i = 0; i < 1000; i++) bw.write("test-" + i);
    }
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) Ignite(org.apache.ignite.Ignite) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 38 with Ignite

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

the class IgniteCacheQueryMultiThreadedSelfTest method _testMultiThreadedSwapUnswapLongString.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
public void _testMultiThreadedSwapUnswapLongString() throws Exception {
    fail("http://atlassian.gridgain.com/jira/browse/GG-11216");
    int threadCnt = 50;
    final int keyCnt = 2000;
    final int valCnt = 10000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Object> c = cache(Integer.class, Object.class);
    assertEquals(0, g.cache(DEFAULT_CACHE_NAME).size());
    assertEquals(0, c.query(new SqlQuery(Object.class, "1 = 1")).getAll().size());
    Random rnd = new Random();
    for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
        c.put(i, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
        if (evictsEnabled() && rnd.nextBoolean())
            c.localEvict(Arrays.asList(i));
    }
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            Random rnd = new Random();
            while (!done.get()) {
                int key = rnd.nextInt(keyCnt);
                switch(rnd.nextInt(5)) {
                    case 0:
                        c.put(key, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
                        break;
                    case 1:
                        if (evictsEnabled())
                            c.localEvict(Arrays.asList(key));
                        break;
                    case 2:
                        c.remove(key);
                        break;
                    case 3:
                        c.get(key);
                        break;
                    case 4:
                        int from = rnd.nextInt(valCnt);
                        c.query(new SqlQuery(Object.class, "_val between ? and ?").setArgs(from, from + 250)).getAll();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX)

Example 39 with Ignite

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

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedNewQueries.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedNewQueries() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 10;
    final int logMod = 5000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
    for (int i = 0; i < keyCnt; i++) {
        c.put(i, i);
        c.localEvict(Arrays.asList(i));
    }
    final AtomicInteger cnt = new AtomicInteger();
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            int iter = 0;
            while (!done.get() && !Thread.currentThread().isInterrupted()) {
                iter++;
                Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
                assert entries != null;
                assertEquals("Entries count is not as expected on iteration: " + iter, keyCnt, entries.size());
                if (cnt.incrementAndGet() % logMod == 0) {
                    GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
                    assert qryMgr != null;
                    qryMgr.printMemoryStats();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    done.set(true);
    fut.get();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryManager(org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 40 with Ignite

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

the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSameQuery.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSameQuery() throws Exception {
    int threadCnt = 50;
    final int keyCnt = 10;
    final int logMod = 5000;
    final Ignite g = grid(0);
    // Put test values into cache.
    final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
    for (int i = 0; i < keyCnt; i++) {
        c.put(i, i);
        c.localEvict(Arrays.asList(i));
    }
    final AtomicInteger cnt = new AtomicInteger();
    final AtomicBoolean done = new AtomicBoolean();
    IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            int iter = 0;
            while (!done.get() && !Thread.currentThread().isInterrupted()) {
                iter++;
                Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
                assert entries != null;
                assertEquals("Query results [entries=" + entries + ", aff=" + affinityNodes(entries, g) + ", iteration=" + iter + ']', keyCnt, entries.size());
                if (cnt.incrementAndGet() % logMod == 0) {
                    GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
                    assert qryMgr != null;
                    qryMgr.printMemoryStats();
                }
            }
        }
    }, threadCnt);
    Thread.sleep(DURATION);
    info("Finishing test...");
    done.set(true);
    fut.get();
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheQueryManager(org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

Ignite (org.apache.ignite.Ignite)2007 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)358 CountDownLatch (java.util.concurrent.CountDownLatch)238 IgniteCache (org.apache.ignite.IgniteCache)234 IgniteException (org.apache.ignite.IgniteException)216 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)215 Transaction (org.apache.ignite.transactions.Transaction)194 ArrayList (java.util.ArrayList)177 ClusterNode (org.apache.ignite.cluster.ClusterNode)152 UUID (java.util.UUID)137 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)135 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)128 CacheException (javax.cache.CacheException)112 Event (org.apache.ignite.events.Event)112 HashMap (java.util.HashMap)105 List (java.util.List)89 IgniteEx (org.apache.ignite.internal.IgniteEx)85 Map (java.util.Map)84 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)81 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)78