Search in sources :

Example 6 with GridClientCompute

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);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridRestCommandHandler(org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler) IgniteKernal(org.apache.ignite.internal.IgniteKernal) P1(org.apache.ignite.internal.util.typedef.P1) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) GridTaskCommandHandler(org.apache.ignite.internal.processors.rest.handlers.task.GridTaskCommandHandler)

Example 7 with GridClientCompute

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;
    }
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientException(org.apache.ignite.internal.client.GridClientException) SQLException(java.sql.SQLException) List(java.util.List)

Example 8 with GridClientCompute

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());
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute)

Example 9 with GridClientCompute

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.
        }
    }
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) GridClient(org.apache.ignite.internal.client.GridClient) LinkedHashMap(java.util.LinkedHashMap) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientData(org.apache.ignite.internal.client.GridClientData) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with GridClientCompute

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.");
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException)

Aggregations

GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)10 GridClientNode (org.apache.ignite.internal.client.GridClientNode)4 GridClientException (org.apache.ignite.internal.client.GridClientException)3 GridClient (org.apache.ignite.internal.client.GridClient)2 GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 GridClientData (org.apache.ignite.internal.client.GridClientData)1 GridClientPredicate (org.apache.ignite.internal.client.GridClientPredicate)1 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)1