use of org.apache.ignite.internal.client.GridClientClosedException 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.GridClientClosedException 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.");
}
use of org.apache.ignite.internal.client.GridClientClosedException in project ignite by apache.
the class GridClientNioTcpConnection method makeRequest.
/**
* Makes request to server via tcp protocol and returns a future that will be completed when response is received.
*
* @param msg Message to request,
* @param fut Future that will handle response.
* @param routeMode If {@code true} then this method should overwrite session token by the cached one,
* otherwise keep original value.
* @return Response object.
* @throws GridClientConnectionResetException If request failed.
* @throws GridClientClosedException If client closed.
*/
private <R> GridClientFutureAdapter<R> makeRequest(GridClientMessage msg, final TcpClientFuture<R> fut, boolean routeMode) throws GridClientConnectionResetException, GridClientClosedException {
assert msg != null;
if (msg instanceof GridClientPingPacket) {
long now = U.currentTimeMillis();
if (Math.min(now, lastPingRcvTime) - lastPingSndTime >= pingTimeout)
close(FAILED, false, new IOException("Did not receive any packets within ping response interval (connection is " + "considered to be half-opened) [lastPingReceiveTime=" + lastPingRcvTime + ", lastPingSendTime=" + lastPingSndTime + ", now=" + now + ", timeout=" + pingTimeout + ", addr=" + serverAddress() + ']'));
else // or we've already waiting for ping response.
if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VALUE) {
lastPingRcvTime = Long.MAX_VALUE;
ses.send(GridClientPingPacket.PING_MESSAGE);
lastPingSndTime = now;
}
} else {
long reqId = reqIdCntr.getAndIncrement();
msg.requestId(reqId);
if (!routeMode) {
msg.clientId(clientId);
msg.sessionToken(sesTok);
}
fut.pendingMessage(msg);
checkClosed(closeReason);
GridClientFutureAdapter old = pendingReqs.putIfAbsent(reqId, fut);
assert old == null;
GridNioFuture<?> sndFut = ses.send(msg);
lastMsgSndTime = U.currentTimeMillis();
if (routeMode) {
sndFut.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> sndFut) {
try {
sndFut.get();
} catch (Exception e) {
close(FAILED, false, e);
fut.onDone(getCloseReasonAsException(FAILED, e));
}
}
});
} else {
try {
sndFut.get();
} catch (Exception e) {
throw new GridClientConnectionResetException("Failed to send message over connection " + "(will try to reconnect): " + serverAddress(), e);
}
}
}
return fut;
}
Aggregations