use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class TaskCommandHandlerSelfTest method testManyTasksRun.
/**
* @throws Exception If failed.
*/
public void testManyTasksRun() throws Exception {
GridClientCompute compute = client.compute();
for (int i = 0; i < 1000; i++) assertEquals(new Integer("executing".length()), compute.execute(TestTask.class.getName(), "executing"));
GridClientFactory.stop(client.id(), true);
IgniteKernal g = (IgniteKernal) grid(0);
Map<GridRestCommand, GridRestCommandHandler> handlers = U.field(g.context().rest(), "handlers");
GridTaskCommandHandler taskHnd = (GridTaskCommandHandler) F.find(handlers.values(), null, new P1<GridRestCommandHandler>() {
@Override
public boolean apply(GridRestCommandHandler e) {
return e instanceof GridTaskCommandHandler;
}
});
assertNotNull("GridTaskCommandHandler was not found", taskHnd);
ConcurrentLinkedHashMap taskDesc = U.field(taskHnd, "taskDescs");
assertTrue("Task result map size exceeded max value [mapSize=" + taskDesc.sizex() + ", " + "maxSize=" + MAX_TASK_RESULTS + ']', taskDesc.sizex() <= MAX_TASK_RESULTS);
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class JdbcResultSet method next.
/** {@inheritDoc} */
@Override
public boolean next() throws SQLException {
ensureNotClosed();
if (fields == null && !finished) {
assert nodeId != null;
assert futId != null;
try {
GridClientCompute compute = stmt.connection().client().compute();
GridClientCompute prj = compute.projection(compute.node(nodeId));
byte[] packet = prj.execute(TASK_NAME, JdbcUtils.marshalArgument(JdbcUtils.taskArgument(nodeId, futId, fetchSize, stmt.getMaxRows())));
byte status = packet[0];
byte[] data = new byte[packet.length - 1];
U.arrayCopy(packet, 1, data, 0, data.length);
if (status == 1)
throw JdbcUtils.unmarshalError(data);
else {
List<?> msg = JdbcUtils.unmarshal(data);
assert msg.size() == 2;
fields = ((Collection<List<Object>>) msg.get(0)).iterator();
finished = (Boolean) msg.get(1);
}
} catch (GridClientException e) {
throw new SQLException("Failed to query Ignite.", e);
}
}
if (fields != null && fields.hasNext()) {
curr = fields.next();
if (!fields.hasNext())
fields = null;
pos++;
return true;
} else {
curr = null;
return false;
}
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testGracefulShutdown.
/**
* @throws Exception If failed.
*/
public void testGracefulShutdown() throws Exception {
GridClientCompute compute = client.compute();
Object taskArg = getTaskArgument();
String taskName = getSleepTaskName();
GridClientFuture<Object> fut = compute.executeAsync(taskName, taskArg);
GridClientFuture<Object> fut2 = compute.executeAsync(taskName, taskArg);
GridClientFactory.stop(client.id(), true);
Assert.assertEquals(17, fut.get());
Assert.assertEquals(17, fut2.get());
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testNoAsyncExceptions.
/**
* Check async API methods don't generate exceptions.
*
* @throws Exception If failed.
*/
public void testNoAsyncExceptions() throws Exception {
GridClient client = client();
GridClientData data = client.data(CACHE_NAME);
GridClientCompute compute = client.compute().projection(new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return false;
}
});
Map<String, GridClientFuture<?>> futs = new LinkedHashMap<>();
futs.put("exec", compute.executeAsync("taskName", "taskArg"));
futs.put("affExec", compute.affinityExecuteAsync("taskName", "cacheName", "affKey", "taskArg"));
futs.put("refreshById", compute.refreshNodeAsync(UUID.randomUUID(), true, true));
futs.put("refreshByIP", compute.refreshNodeAsync("nodeIP", true, true));
futs.put("refreshTop", compute.refreshTopologyAsync(true, true));
GridClientFactory.stop(client.id(), false);
futs.put("put", data.putAsync("key", "val"));
futs.put("putAll", data.putAllAsync(F.asMap("key", "val")));
futs.put("get", data.getAsync("key"));
futs.put("getAll", data.getAllAsync(Collections.singletonList("key")));
futs.put("remove", data.removeAsync("key"));
futs.put("removeAll", data.removeAllAsync(Collections.singletonList("key")));
futs.put("replace", data.replaceAsync("key", "val"));
futs.put("cas", data.casAsync("key", "val", "val2"));
futs.put("metrics", data.metricsAsync());
for (Map.Entry<String, GridClientFuture<?>> e : futs.entrySet()) {
try {
e.getValue().get();
info("Expects '" + e.getKey() + "' fails with grid client exception.");
} catch (GridServerUnreachableException | GridClientClosedException ignore) {
// No op: compute projection is empty.
}
}
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testForceShutdown.
/**
* @throws Exception If failed.
*/
public void testForceShutdown() throws Exception {
GridClientCompute compute = client.compute();
Object taskArg = getTaskArgument();
String taskName = getSleepTaskName();
GridClientFuture<Object> fut = compute.executeAsync(taskName, taskArg);
GridClientFactory.stop(client.id(), false);
try {
fut.get();
} catch (GridClientClosedException ignored) {
return;
}
Assert.fail("Expected GridClientClosedException.");
}
Aggregations