Search in sources :

Example 1 with GridClient

use of org.apache.ignite.internal.client.GridClient in project ignite by apache.

the class ClientAbstractConnectivitySelfTest method checkConnectivityByIp.

/**
     * @param connectIp IP to test.
     * @param nodeIp Expected IP reported to client.
     * @throws GridClientException If failed.
     */
private void checkConnectivityByIp(String connectIp, IgniteBiTuple<Collection<String>, Collection<String>> nodeIp) throws GridClientException {
    GridClient cli = startClient(connectIp, defaultRestPort());
    List<GridClientNode> nodes = cli.compute().refreshTopology(true, false);
    assertEquals(1, nodes.size());
    GridClientNode node = F.first(nodes);
    assertNotNull(node);
    assertTrue(eqAddresses(nodeIp, node));
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient)

Example 2 with GridClient

use of org.apache.ignite.internal.client.GridClient in project ignite by apache.

the class ClientAbstractConnectivitySelfTest method testOneNodeZeroIpv4Address.

/**
     * Tests correct behavior in case of 1 REST-enabled node
     * with explicitly specified 0.0.0.0 address.
     *
     * @throws Exception If error occurs.
     */
public void testOneNodeZeroIpv4Address() throws Exception {
    startRestNode("grid1", WILDCARD_IP, defaultRestPort());
    Collection<String> addrs = new LinkedList<>();
    addrs.add(LOOPBACK_IP);
    Collection<String> nonLoopbackAddrs = U.allLocalIps();
    assertNotNull(nonLoopbackAddrs);
    addrs.addAll(F.view(nonLoopbackAddrs, new IpV4AddressPredicate()));
    // The client should be able to connect through all IPv4 addresses.
    for (String addr : addrs) {
        log.info("Trying address: " + addr);
        GridClient cli = startClient(addr, defaultRestPort());
        List<GridClientNode> nodes = cli.compute().refreshTopology(true, false);
        assertEquals(1, nodes.size());
        GridClientNode node = F.first(nodes);
        assertNotNull(node);
        assertEquals(getAllIps().get1(), node.attribute(restAddressAttributeName()));
        assertEquals(getAllIps().get2(), node.attribute(restHostNameAttributeName()));
        List<String> nodeAddrs = node.tcpAddresses();
        assertTrue(nodeAddrs.contains(LOOPBACK_IP));
        assertTrue(F.containsAll(nodeAddrs, addrs));
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient) LinkedList(java.util.LinkedList)

Example 3 with GridClient

use of org.apache.ignite.internal.client.GridClient in project ignite by apache.

the class ClientAbstractConnectivitySelfTest method testRefreshTopologyOnNodeLeft.

/**
     * Tests correct behavior in case of shutdown node used to refresh topology state.
     *
     * @throws Exception If error occurs.
     */
public void testRefreshTopologyOnNodeLeft() 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());
    stopGrid("grid1");
    nodes = cli.compute().refreshTopology(true, false);
    assertEquals(1, nodes.size());
    startRestNode("grid3", null, null);
    nodes = cli.compute().refreshTopology(true, false);
    assertEquals(2, nodes.size());
    stopGrid("grid2");
    nodes = cli.compute().refreshTopology(true, false);
    assertEquals(1, nodes.size());
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient)

Example 4 with GridClient

use of org.apache.ignite.internal.client.GridClient in project ignite by apache.

the class ClientAbstractSelfTest method testShutdown.

/**
     * @throws Exception If failed.
     */
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);
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) ArrayList(java.util.ArrayList) GridClient(org.apache.ignite.internal.client.GridClient)

Example 5 with GridClient

use of org.apache.ignite.internal.client.GridClient in project ignite by apache.

the class ClientAbstractSelfTest method testConnectable.

/**
     * @throws Exception If failed.
     */
public void testConnectable() throws Exception {
    GridClient client = client();
    List<GridClientNode> nodes = client.compute().refreshTopology(false, false);
    assertTrue(F.first(nodes).connectable());
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient)

Aggregations

GridClient (org.apache.ignite.internal.client.GridClient)14 GridClientNode (org.apache.ignite.internal.client.GridClientNode)7 GridClientException (org.apache.ignite.internal.client.GridClientException)4 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)3 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