use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteCacheReplicatedQuerySelfTest method testClientOnlyNode.
/**
* @throws Exception If failed.
*/
public void testClientOnlyNode() throws Exception {
try {
Ignite g = startGrid("client");
IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);
for (int i = 0; i < 10; i++) c.put(i, i);
// Client cache should be empty.
assertEquals(0, c.localSize());
Collection<Cache.Entry<Integer, Integer>> res = c.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 5 order by _key")).getAll();
assertEquals(5, res.size());
int i = 5;
for (Cache.Entry<Integer, Integer> e : res) {
assertEquals(i, e.getKey().intValue());
assertEquals(i, e.getValue().intValue());
i++;
}
} finally {
stopGrid("client");
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ClosureServiceClientsNodesTest method testDefaultClosure.
/**
* @throws Exception If failed.
*/
public void testDefaultClosure() throws Exception {
Set<String> srvNames = new HashSet<>(NODES_CNT - 1);
for (int i = 1; i < NODES_CNT; ++i) srvNames.add(getTestIgniteInstanceName(i));
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
Ignite ignite = grid(i);
Collection<String> res = ignite.compute().broadcast(new IgniteCallable<String>() {
@IgniteInstanceResource
Ignite ignite;
@Override
public String call() throws Exception {
assertFalse(ignite.configuration().isClientMode());
return ignite.name();
}
});
assertEquals(res.size(), NODES_CNT - 1);
for (String name : res) assertTrue(srvNames.contains(name));
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ClosureServiceClientsNodesTest method testCustomClosure.
/**
* @throws Exception If failed.
*/
public void testCustomClosure() throws Exception {
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
Ignite ignite = grid(i);
Collection<String> res = ignite.compute(ignite.cluster().forPredicate(F.<ClusterNode>alwaysTrue())).broadcast(new IgniteCallable<String>() {
@IgniteInstanceResource
Ignite ignite;
@Override
public String call() throws Exception {
return ignite.name();
}
});
assertEquals(NODES_CNT, res.size());
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class DynamicColumnsAbstractConcurrentSelfTest method testConcurrentPutRemove.
/**
* PUT/REMOVE data from cache and add/drop column concurrently.
*
* @throws Exception If failed,
*/
public void testConcurrentPutRemove() throws Exception {
CountDownLatch finishLatch = new CountDownLatch(4);
// Start several nodes.
IgniteEx srv1 = ignitionStart(serverConfiguration(1), finishLatch);
ignitionStart(serverConfiguration(2), finishLatch);
ignitionStart(serverConfiguration(3), finishLatch);
ignitionStart(serverConfiguration(4), finishLatch);
awaitPartitionMapExchange();
createSqlCache(srv1);
run(srv1, createSql4Cols);
// Start data change operations from several threads.
final AtomicBoolean stopped = new AtomicBoolean();
IgniteInternalFuture updateFut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stopped.get()) {
Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
int key = ThreadLocalRandom.current().nextInt(0, LARGE_CACHE_SIZE);
int val = ThreadLocalRandom.current().nextInt();
IgniteCache<Object, BinaryObject> cache = node.cache(CACHE_NAME);
if (ThreadLocalRandom.current().nextBoolean())
cache.put(key(node, key), val(node, val));
else
cache.remove(key(node, key));
}
return null;
}
}, 4);
// Let some to arrive.
Thread.sleep(500L);
addCols(srv1, QueryUtils.DFLT_SCHEMA, c("v", Integer.class.getName())).get();
dropCols(srv1, QueryUtils.DFLT_SCHEMA, "CITY").get();
// Stop updates once index is ready.
stopped.set(true);
updateFut.get();
finishLatch.await();
// Make sure new column is there.
checkTableState(srv1, QueryUtils.DFLT_SCHEMA, TBL_NAME, c("AGE", Integer.class.getName()), c("v", Integer.class.getName()));
run(srv1, "update person set \"v\" = case when mod(id, 2) <> 0 then substring(name, 7, length(name) - 6) " + "else null end");
// Get expected values.
Set<Integer> expKeys = new HashSet<>();
IgniteCache<Object, BinaryObject> cache = srv1.cache(CACHE_NAME).withKeepBinary();
for (int i = 0; i < LARGE_CACHE_SIZE; i++) {
Object key = key(srv1, i);
BinaryObject val = cache.get(key);
if (val != null) {
int id = (Integer) key;
assertEquals(i, id);
if (id % 2 != 0)
expKeys.add(i);
}
}
String valTypeName = ((IgniteEx) srv1).context().query().types(CACHE_NAME).iterator().next().valueTypeName();
// Validate query result.
for (Ignite node : Ignition.allGrids()) {
IgniteCache<Object, BinaryObject> nodeCache = node.cache(CACHE_NAME).withKeepBinary();
SqlQuery qry = new SqlQuery(valTypeName, "from " + TBL_NAME + " where mod(id, 2) <> 0");
List<Cache.Entry<Object, BinaryObject>> res = nodeCache.query(qry).getAll();
assertEquals("Cache size mismatch [exp=" + expKeys.size() + ", actual=" + res.size() + ']', expKeys.size(), res.size());
for (Cache.Entry<Object, BinaryObject> entry : res) {
int key = (Integer) entry.getKey();
int v = entry.getValue().field("v");
String name = entry.getValue().field("NAME");
assertTrue("Expected key is not in result set: " + key, expKeys.contains(key));
assertEquals(Integer.parseInt(name.substring(6)), v);
}
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class DynamicColumnsAbstractConcurrentSelfTest method testQueryConsistencyMultithreaded.
/**
* Make sure that contended operations on the same table from different nodes do not hang when we issue both
* ADD/DROP COLUMN and SELECT statements.
*
* @throws Exception If failed.
*/
public void testQueryConsistencyMultithreaded() throws Exception {
// Start complex topology.
ignitionStart(serverConfiguration(1));
ignitionStart(serverConfiguration(2));
ignitionStart(serverConfiguration(3, true));
Ignite cli = ignitionStart(clientConfiguration(4));
createSqlCache(cli);
run(cli, createSql);
put(cli, 0, 5000);
final AtomicBoolean stopped = new AtomicBoolean();
final AtomicInteger dynColCnt = new AtomicInteger();
final GridConcurrentHashSet<Integer> fields = new GridConcurrentHashSet<>();
IgniteInternalFuture fut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stopped.get()) {
Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
IgniteInternalFuture fut;
int fieldNum = ThreadLocalRandom.current().nextInt(0, dynColCnt.get() + 1);
boolean removed = fields.remove(fieldNum);
if (removed)
fut = dropCols(node, QueryUtils.DFLT_SCHEMA, "newCol" + fieldNum);
else {
fieldNum = dynColCnt.getAndIncrement();
fut = addCols(node, QueryUtils.DFLT_SCHEMA, c("newCol" + fieldNum, Integer.class.getName()));
}
try {
fut.get();
if (!removed)
fields.add(fieldNum);
} catch (SchemaOperationException e) {
// No-op.
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
}
return null;
}
}, 1);
IgniteInternalFuture qryFut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stopped.get()) {
Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5));
IgniteCache<BinaryObject, BinaryObject> cache = node.cache(CACHE_NAME).withKeepBinary();
String valTypeName = ((IgniteEx) node).context().query().types(CACHE_NAME).iterator().next().valueTypeName();
List<Cache.Entry<BinaryObject, BinaryObject>> res = cache.query(new SqlQuery<BinaryObject, BinaryObject>(valTypeName, "from " + TBL_NAME)).getAll();
assertEquals(5000, res.size());
}
return null;
}
}, 8);
Thread.sleep(TEST_DUR);
stopped.set(true);
// Make sure nothing hanged.
fut.get();
qryFut.get();
}
Aggregations