use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testExecute.
/**
* @throws Exception If failed.
*/
@Test
public void testExecute() throws Exception {
String taskName = getTaskName();
Object taskArg = getTaskArgument();
GridClientCompute compute = client.compute();
assertEquals(Integer.valueOf(17), compute.execute(taskName, taskArg));
assertEquals(Integer.valueOf(17), compute.executeAsync(taskName, taskArg).get());
}
use of org.apache.ignite.internal.client.GridClientCompute 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.GridClientCompute in project ignite by apache.
the class ClientAbstractSelfTest method testTopology.
/**
* @throws Exception If failed.
*/
@Test
public void testTopology() throws Exception {
GridClientCompute compute = client.compute();
List<GridClientNode> top = compute.refreshTopology(true, true);
assertNotNull(top);
assertEquals(1, top.size());
GridClientNode node = F.first(top);
assertNotNull(node);
assertFalse(node.attributes().isEmpty());
assertNotNull(node.tcpAddresses());
assertEquals(grid().localNode().id(), node.nodeId());
assertNotNull(node.metrics());
top = compute.refreshTopology(false, false);
node = F.first(top);
assertNotNull(top);
assertEquals(1, top.size());
assertNull(node.metrics());
assertTrue(node.attributes().isEmpty());
node = F.first(top);
assertNotNull(node);
assertTrue(node.attributes().isEmpty());
assertNull(node.metrics());
assertNotNull(node.tcpAddresses());
assertEquals(grid().localNode().id(), node.nodeId());
top = compute.refreshTopologyAsync(true, true).get();
assertNotNull(top);
assertEquals(1, top.size());
node = F.first(top);
assertNotNull(node);
assertFalse(node.attributes().isEmpty());
assertNotNull(node.metrics());
assertNotNull(node.tcpAddresses());
assertEquals(grid().localNode().id(), node.nodeId());
top = compute.refreshTopologyAsync(false, false).get();
assertNotNull(top);
assertEquals(1, top.size());
node = F.first(top);
assertNotNull(node);
assertTrue(node.attributes().isEmpty());
assertNull(node.metrics());
assertNotNull(node.tcpAddresses());
assertEquals(grid().localNode().id(), node.nodeId());
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class MetadataAbstractSubCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public final Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
try (GridClient client = Command.startClient(clientCfg)) {
GridClientCompute compute = client.compute();
// Try to find connectable server nodes.
Collection<GridClientNode> nodes = compute.nodes((n) -> n.connectable() && !n.isClient());
if (F.isEmpty(nodes)) {
nodes = compute.nodes(GridClientNode::connectable);
if (F.isEmpty(nodes))
throw new GridClientDisconnectedException("Connectable nodes not found", null);
}
GridClientNode node = nodes.stream().findAny().orElse(null);
if (node == null)
node = compute.balancer().balancedNode(nodes);
MetadataResultDto res = compute.projection(node).execute(taskName(), new VisorTaskArgument<>(node.nodeId(), arg(), false));
printResult(res, log);
} catch (Throwable e) {
log.severe("Failed to execute metadata command='" + name() + "'");
log.severe(CommandLogger.errorMessage(e));
throw e;
}
return null;
}
use of org.apache.ignite.internal.client.GridClientCompute in project ignite by apache.
the class ClientAbstractMultiNodeSelfTest method testEmptyProjections.
/**
* @throws Exception If failed.
*/
@Test
public void testEmptyProjections() throws Exception {
final GridClientCompute dflt = client.compute();
Collection<? extends GridClientNode> nodes = dflt.nodes();
assertEquals(NODES_CNT, nodes.size());
Iterator<? extends GridClientNode> iter = nodes.iterator();
final GridClientCompute singleNodePrj = dflt.projection(Collections.singletonList(iter.next()));
final GridClientNode second = iter.next();
final GridClientPredicate<GridClientNode> targetFilter = new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
return node.nodeId().equals(second.nodeId());
}
};
GridTestUtils.assertThrows(log(), new Callable<Object>() {
@Override
public Object call() throws Exception {
return singleNodePrj.projection(second);
}
}, GridClientException.class, null);
GridTestUtils.assertThrows(log(), new Callable<Object>() {
@Override
public Object call() throws Exception {
return singleNodePrj.projection(targetFilter);
}
}, GridClientException.class, null);
}
Aggregations