use of org.apache.ignite.internal.client.GridClientFuture in project ignite by apache.
the class ClientAbstractSelfTest method testShutdown.
/**
* @throws Exception If failed.
*/
@Test
public void testShutdown() throws Exception {
GridClient c = client();
GridClientCompute compute = c.compute();
String taskName = getTaskName();
Object taskArg = getTaskArgument();
Collection<GridClientFuture<Object>> futs = new ArrayList<>();
// Validate connection works.
compute.execute(taskName, taskArg);
info(">>> First task executed successfully, running batch.");
for (int i = 0; i < 10; i++) futs.add(compute.executeAsync(taskName, taskArg));
// Stop client.
GridClientFactory.stop(c.id(), true);
info(">>> Completed stop request.");
int failed = 0;
for (GridClientFuture<Object> fut : futs) {
try {
assertEquals(17, fut.get());
} catch (GridClientException e) {
failed++;
log.warning("Task execution failed.", e);
}
}
assertEquals(0, failed);
}
use of org.apache.ignite.internal.client.GridClientFuture in project ignite by apache.
the class ClientAbstractSelfTest method testNoAsyncExceptions.
/**
* Check async API methods don't generate exceptions.
*
* @throws Exception If failed.
*/
@Test
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.GridClientFuture in project ignite by apache.
the class GridTcpRouterNioListenerAdapter method onMessage.
/**
* {@inheritDoc}
*/
@SuppressWarnings("TypeMayBeWeakened")
@Override
public void onMessage(final GridNioSession ses, final GridClientMessage msg) {
if (msg instanceof GridRouterRequest) {
GridRouterRequest routerMsg = (GridRouterRequest) msg;
final UUID clientId = routerMsg.clientId();
final long reqId = routerMsg.requestId();
try {
client.forwardMessage(routerMsg, routerMsg.destinationId(), ses.<Byte>meta(MARSHALLER_ID.ordinal())).listen(new GridClientFutureListener() {
@Override
public void onDone(GridClientFuture fut) {
try {
GridRouterResponse res = (GridRouterResponse) fut.get();
// Restoring original request id, because it was overwritten by the client.
res.requestId(reqId);
ses.send(res);
} catch (GridClientException e) {
ses.send(makeFailureResponse(e, clientId, reqId));
}
}
});
} catch (GridClientException e) {
ses.send(makeFailureResponse(e, clientId, reqId));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
U.warn(log, "Message forwarding was interrupted (will ignore last message): " + e.getMessage());
}
} else if (msg instanceof GridClientHandshakeRequest) {
GridClientHandshakeRequest hs = (GridClientHandshakeRequest) msg;
short ver = hs.version();
if (!SUPP_VERS.contains(ver)) {
U.error(log, "Client protocol version is not supported [ses=" + ses + ", ver=" + ver + ", supported=" + SUPP_VERS + ']');
ses.close();
} else {
byte marshId = hs.marshallerId();
GridClientMarshaller marsh = marshMap.get(marshId);
if (marsh == null) {
U.error(log, "Client marshaller ID is invalid. Note that .NET and C++ clients " + "are supported only in enterprise edition [ses=" + ses + ", marshId=" + marshId + ']');
ses.close();
} else {
ses.addMeta(MARSHALLER_ID.ordinal(), marshId);
ses.addMeta(MARSHALLER.ordinal(), marsh);
ses.send(GridClientHandshakeResponse.OK);
}
}
} else if (msg instanceof GridClientPingPacket)
ses.send(GridClientPingPacket.PING_MESSAGE);
else
throw new IllegalArgumentException("Unsupported input message: " + msg);
}
Aggregations