use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteCacheDistributedQueryCancelSelfTest method testQueryResponseFailCode.
/**
*/
public void testQueryResponseFailCode() throws Exception {
try (Ignite client = startGrid("client")) {
CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
cfg.setSqlFunctionClasses(Functions.class);
cfg.setIndexedTypes(Integer.class, Integer.class);
cfg.setName("test");
IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
cache.put(1, 1);
QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("select fail() from Integer"));
try {
qry.getAll();
fail();
} catch (Exception e) {
assertTrue(e.getCause() instanceof CacheException);
}
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest method testQueryCancel.
/**
*/
private void testQueryCancel(int keyCnt, int valSize, String sql, int timeoutUnits, TimeUnit timeUnit, boolean timeout) throws Exception {
try (Ignite client = startGrid("client")) {
IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
assertEquals(0, cache.localSize());
int p = 1;
for (int i = 1; i <= keyCnt; i++) {
char[] tmp = new char[valSize];
Arrays.fill(tmp, ' ');
cache.put(i, new String(tmp));
if (i / (float) keyCnt >= p / 10f) {
log().info("Loaded " + i + " of " + keyCnt);
p++;
}
}
assertEquals(0, cache.localSize());
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
final QueryCursor<List<?>> cursor;
if (timeout) {
qry.setTimeout(timeoutUnits, timeUnit);
cursor = cache.query(qry);
} else {
cursor = cache.query(qry);
client.scheduler().runLocal(new Runnable() {
@Override
public void run() {
cursor.close();
}
}, timeoutUnits, timeUnit);
}
try (QueryCursor<List<?>> ignored = cursor) {
cursor.iterator();
} catch (CacheException ex) {
log().error("Got expected exception", ex);
assertTrue("Must throw correct exception", ex.getCause() instanceof QueryCancelledException);
}
// Give some time to clean up.
Thread.sleep(TimeUnit.MILLISECONDS.convert(timeoutUnits, timeUnit) + 3_000);
checkCleanState();
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ClosureServiceClientsNodesTest method testDefaultService.
/**
* @throws Exception If failed.
*/
public void testDefaultService() throws Exception {
UUID clientNodeId = grid(0).cluster().localNode().id();
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
final Ignite ignite = grid(i);
ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService());
final ClusterGroup grp = ignite.cluster();
assertEquals(NODES_CNT, grp.nodes().size());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite.services(grp).serviceDescriptors().size() == 1;
}
}, 5000);
Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
assertEquals(1, srvDscs.size());
Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
assertEquals(NODES_CNT - 1, nodesMap.size());
for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
assertFalse(clientNodeId.equals(nodeInfo.getKey()));
assertEquals(1, nodeInfo.getValue().intValue());
}
ignite.services().cancelAll();
}
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteCacheReplicatedFieldsQueryJoinNoPrimaryPartitionsSelfTest method beforeTest.
/**
*{@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
startGridsMultiThreaded(3);
Ignite cli = startGrid(NODE_CLI);
for (int i = 0; i < REP_CNT; i++) cli.cache(CACHE_REPLICATED).put(i, new RepValue(i));
for (int i = 0; i < PART_CNT; i++) cli.cache(CACHE_PARTITIONED).put(i, new PartValue(i, ((i + 1) % REP_CNT)));
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class ClosureServiceClientsNodesTest method testClientService.
/**
* @throws Exception If failed.
*/
public void testClientService() throws Exception {
UUID clientNodeId = grid(0).cluster().localNode().id();
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
final Ignite ignite = grid(i);
ignite.services(ignite.cluster().forClients()).deployNodeSingleton(SINGLETON_NAME, new TestService());
final ClusterGroup grp = ignite.cluster();
assertEquals(NODES_CNT, grp.nodes().size());
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite.services(grp).serviceDescriptors().size() == 1;
}
}, 5000);
Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
assertEquals(1, srvDscs.size());
Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
assertEquals(1, nodesMap.size());
for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
assertEquals(clientNodeId, nodeInfo.getKey());
assertEquals(1, nodeInfo.getValue().intValue());
}
ignite.services().cancelAll();
}
}
Aggregations