Search in sources :

Example 11 with GridClient

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

Example 12 with GridClient

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

Example 13 with GridClient

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

Example 14 with GridClient

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;
            }
        }
    });
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) P1(org.apache.ignite.internal.util.typedef.P1) GridClient(org.apache.ignite.internal.client.GridClient) GridClientException(org.apache.ignite.internal.client.GridClientException)

Example 15 with GridClient

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.
        }
    }
}
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)

Aggregations

GridClient (org.apache.ignite.internal.client.GridClient)15 GridClientNode (org.apache.ignite.internal.client.GridClientNode)7 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)4 GridClientException (org.apache.ignite.internal.client.GridClientException)4 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)1 GridClientClusterState (org.apache.ignite.internal.client.GridClientClusterState)1 GridClientData (org.apache.ignite.internal.client.GridClientData)1