Search in sources :

Example 96 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ServicesTest method testWrongServiceName.

/**
 * Test that exception is thrown when trying to invoke non-existing service.
 */
@Test
public void testWrongServiceName() throws Exception {
    try (IgniteClient client = startClient(0)) {
        TestServiceInterface svc = client.services().serviceProxy("no_such_service", TestServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, () -> svc.testMethod(0), ClientException.class, "Service not found");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 97 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ServicesTest method testCollectionMethods.

/**
 * Test that methods which get and return collections work correctly.
 */
@Test
public void testCollectionMethods() throws Exception {
    try (IgniteClient client = startClient(0)) {
        // Test local service calls (service deployed to each node).
        TestServiceInterface svc = client.services().serviceProxy(NODE_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        checkCollectionMethods(svc);
        // Test remote service calls (client connected to grid(0) but service deployed to grid(1)).
        svc = client.services().serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        checkCollectionMethods(svc);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 98 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ServicesTest method testWrongMethodInvocation.

/**
 * Test that exception is thrown when invoking service with wrong interface.
 */
@Test
public void testWrongMethodInvocation() throws Exception {
    try (IgniteClient client = startClient(0)) {
        TestServiceInterface svc = client.services().serviceProxy(NODE_ID_SERVICE_NAME, TestServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, () -> svc.testMethod(0), ClientException.class, "Method not found");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 99 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class IgniteAwareApplicationService method main.

/**
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    log.info("Starting Application... [params=" + args[0] + "]");
    String[] params = args[0].split(",");
    IgniteServiceType svcType = IgniteServiceType.valueOf(params[0]);
    Class<?> clazz = Class.forName(params[1]);
    String cfgPath = params[2];
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = params.length > 3 ? mapper.readTree(Base64.getDecoder().decode(params[3])) : mapper.createObjectNode();
    IgniteAwareApplication app = (IgniteAwareApplication) clazz.getConstructor().newInstance();
    app.cfgPath = cfgPath;
    if (svcType == IgniteServiceType.NODE) {
        log.info("Starting Ignite node...");
        IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgs = IgnitionEx.loadConfiguration(cfgPath);
        IgniteConfiguration cfg = cfgs.get1();
        try (Ignite ignite = Ignition.start(cfg)) {
            app.ignite = ignite;
            app.start(jsonNode);
        } finally {
            log.info("Ignite instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.THIN_CLIENT) {
        log.info("Starting thin client...");
        ClientConfiguration cfg = IgnitionEx.loadSpringBean(cfgPath, "thin.client.cfg");
        try (IgniteClient client = Ignition.startClient(cfg)) {
            app.client = client;
            app.start(jsonNode);
        } finally {
            log.info("Thin client instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.NONE)
        app.start(jsonNode);
    else
        throw new IllegalArgumentException("Unknown service type " + svcType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext) Ignite(org.apache.ignite.Ignite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 100 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class SqlViewExporterSpiTest method testClientsConnections.

/**
 */
@Test
public void testClientsConnections() throws Exception {
    String host = ignite0.configuration().getClientConnectorConfiguration().getHost();
    if (host == null)
        host = ignite0.configuration().getLocalHost();
    int port = ignite0.configuration().getClientConnectorConfiguration().getPort();
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
        try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
            List<List<?>> conns = execute(ignite0, "SELECT * FROM SYS.CLIENT_CONNECTIONS");
            assertEquals(2, conns.size());
        }
    }
}
Also used : IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) Connection(java.sql.Connection) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) AbstractExporterSpiTest(org.apache.ignite.internal.metric.AbstractExporterSpiTest) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9