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);
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations