use of org.apache.ignite.internal.client.GridClient in project ignite by apache.
the class ClientFailedInitSelfTest method doTestRouter.
/**
* @param p Protocol.
* @throws Exception If failed.
*/
@SuppressWarnings("BusyWait")
private void doTestRouter(GridClientProtocol p) throws Exception {
startRouters();
GridClient c = client(p, true);
for (int i = 0; i < RECONN_CNT; i++) {
try {
c.compute().nodes();
fail("Nodes list should fail while grid is stopped.");
} catch (GridClientDisconnectedException e) {
assertTrue(X.hasCause(e, GridClientException.class));
}
startGrid();
try {
Thread.sleep(TOP_REFRESH_PERIOD * 2);
c.compute().nodes();
assertEquals("arg", c.compute().execute(TestTask.class.getName(), "arg"));
} finally {
stopGrid();
}
Thread.sleep(TOP_REFRESH_PERIOD * 2);
}
}
use of org.apache.ignite.internal.client.GridClient in project ignite by apache.
the class ClientFailedInitSelfTest method doTestClient.
/**
* @param p Protocol.
* @throws Exception If failed.
*/
@SuppressWarnings("BusyWait")
private void doTestClient(GridClientProtocol p) throws Exception {
GridClient c = client(p, false);
for (int i = 0; i < RECONN_CNT; i++) {
try {
c.compute().nodes();
} catch (GridClientDisconnectedException e) {
assertTrue(X.hasCause(e, GridServerUnreachableException.class, GridClientConnectionResetException.class));
}
startGrid();
try {
Thread.sleep(TOP_REFRESH_PERIOD * 2);
c.compute().nodes();
assertEquals("arg", c.compute().execute(TestTask.class.getName(), "arg"));
} finally {
stopGrid();
}
Thread.sleep(TOP_REFRESH_PERIOD * 2);
}
}
use of org.apache.ignite.internal.client.GridClient in project ignite by apache.
the class TcpRouterAbstractSelfTest method testConnectable.
/**
* @throws Exception If failed.
*/
@Override
public void testConnectable() throws Exception {
GridClient client = client();
List<GridClientNode> nodes = client.compute().refreshTopology(false, false);
assertFalse(F.first(nodes).connectable());
}
use of org.apache.ignite.internal.client.GridClient in project ignite by apache.
the class ClientAbstractConnectivitySelfTest method testTwoNodesDefaultHostAndPort.
/**
* Tests correct behavior in case of 2 REST-enabled nodes with default
* settings.
*
* @throws Exception If error occurs.
*/
public void testTwoNodesDefaultHostAndPort() throws Exception {
startRestNode("grid1", null, null);
startRestNode("grid2", null, null);
GridClient cli = startClient(LOOPBACK_IP, defaultRestPort());
List<GridClientNode> nodes = cli.compute().refreshTopology(true, false);
assertEquals(2, nodes.size());
assertTrue(F.forAll(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
return node.tcpAddresses().contains(LOOPBACK_IP);
}
}));
GridTestUtils.assertOneToOne(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort()).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
}, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort() + 1).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
});
}
use of org.apache.ignite.internal.client.GridClient 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.
}
}
}
Aggregations