Search in sources :

Example 41 with IgniteClient

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

the class ServicesTest method testServiceException.

/**
 * Test that service exception message is propagated to client.
 */
@Test
public void testServiceException() 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);
        GridTestUtils.assertThrowsAnyCause(log, svc::testException, ClientException.class, "testException()");
        // Test remote service calls (client connected to grid(0) but service deployed to grid(1)).
        client.services().serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, svc::testException, ClientException.class, "testException()");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 42 with IgniteClient

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

the class ServicesTest method testServicesOnClusterGroup.

/**
 * Test that services executed on cluster group.
 */
@Test
public void testServicesOnClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        // Local node.
        ClientClusterGroup grp = client.cluster().forNodeId(nodeId(0), nodeId(3));
        TestNodeIdServiceInterface nodeSvc0 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        assertEquals(nodeId(0), nodeSvc0.nodeId());
        // Remote node.
        grp = client.cluster().forNodeId(nodeId(1), nodeId(3));
        nodeSvc0 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        assertEquals(nodeId(1), nodeSvc0.nodeId());
        // Client node.
        grp = client.cluster().forNodeId(nodeId(3));
        TestNodeIdServiceInterface nodeSvc1 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, nodeSvc1::nodeId, ClientException.class, "Failed to find deployed service");
        // All nodes, except service node.
        grp = client.cluster().forNodeId(nodeId(0), nodeId(2), nodeId(3));
        TestServiceInterface nodeSvc2 = client.services(grp).serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, nodeSvc2::testMethod, ClientException.class, "Failed to find deployed service");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) Test(org.junit.Test)

Example 43 with IgniteClient

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

the class ServicesTest method testServiceDescriptors.

/**
 * Test service descriptors returned correctly.
 */
@Test
public void testServiceDescriptors() throws Exception {
    try (IgniteClient client = startClient(0)) {
        Collection<ClientServiceDescriptor> svcs = client.services().serviceDescriptors();
        assertNotNull(svcs);
        assertEquals(3, svcs.size());
        assertTrue(svcs.stream().filter(svc -> svc.name().equals(NODE_ID_SERVICE_NAME)).peek(svc -> {
            assertEquals(NODE_ID_SERVICE_NAME, svc.name());
            assertEquals(TestNodeIdService.class.getName(), svc.serviceClass());
            assertEquals(0, svc.totalCount());
            assertEquals(1, svc.maxPerNodeCount());
            assertNull(svc.cacheName());
            assertEquals(grid(0).localNode().id(), svc.originNodeId());
            assertEquals(PlatformType.JAVA, svc.platformType());
            assertDescriptorsEquals(svc, client.services().serviceDescriptor(NODE_ID_SERVICE_NAME));
        }).findFirst().isPresent());
        assertTrue(svcs.stream().filter(svc -> svc.name().equals(NODE_SINGLTON_SERVICE_NAME)).peek(svc -> {
            assertEquals(NODE_SINGLTON_SERVICE_NAME, svc.name());
            assertEquals(TestService.class.getName(), svc.serviceClass());
            assertEquals(0, svc.totalCount());
            assertEquals(1, svc.maxPerNodeCount());
            assertNull(svc.cacheName());
            assertEquals(grid(0).localNode().id(), svc.originNodeId());
            assertEquals(PlatformType.JAVA, svc.platformType());
            assertDescriptorsEquals(svc, client.services().serviceDescriptor(NODE_SINGLTON_SERVICE_NAME));
        }).findFirst().isPresent());
        assertTrue(svcs.stream().filter(svc -> svc.name().equals(CLUSTER_SINGLTON_SERVICE_NAME)).peek(svc -> {
            assertEquals(CLUSTER_SINGLTON_SERVICE_NAME, svc.name());
            assertEquals(TestService.class.getName(), svc.serviceClass());
            assertEquals(1, svc.totalCount());
            assertEquals(1, svc.maxPerNodeCount());
            assertEquals(DEFAULT_CACHE_NAME, svc.cacheName());
            assertEquals(grid(0).localNode().id(), svc.originNodeId());
            assertEquals(PlatformType.JAVA, svc.platformType());
            assertDescriptorsEquals(svc, client.services().serviceDescriptor(CLUSTER_SINGLTON_SERVICE_NAME));
        }).findFirst().isPresent());
        assertThrowsWithCause(() -> {
            client.services().serviceDescriptor("unknown");
        }, ClientException.class);
    }
}
Also used : ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) Arrays(java.util.Arrays) Person(org.apache.ignite.client.Person) PlatformType(org.apache.ignite.platform.PlatformType) HashSet(java.util.HashSet) ClientException(org.apache.ignite.client.ClientException) ServiceContext(org.apache.ignite.services.ServiceContext) IgniteClient(org.apache.ignite.client.IgniteClient) Map(java.util.Map) BinaryArray(org.apache.ignite.internal.binary.BinaryArray) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) F(org.apache.ignite.internal.util.typedef.F) ServiceCallContext(org.apache.ignite.services.ServiceCallContext) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) Collection(java.util.Collection) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ServiceCallContextBuilder(org.apache.ignite.services.ServiceCallContextBuilder) ClientServiceDescriptor(org.apache.ignite.client.ClientServiceDescriptor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceContextResource(org.apache.ignite.resources.ServiceContextResource) Service(org.apache.ignite.services.Service) IGNITE_USE_BINARY_ARRAYS(org.apache.ignite.IgniteSystemProperties.IGNITE_USE_BINARY_ARRAYS) IgniteClient(org.apache.ignite.client.IgniteClient) ClientServiceDescriptor(org.apache.ignite.client.ClientServiceDescriptor) Test(org.junit.Test)

Example 44 with IgniteClient

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

the class JavaThinCompatibilityTest method testExpiryPolicy.

/**
 */
private void testExpiryPolicy() throws Exception {
    X.println(">>>> Testing expiry policy");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache("testExpiryPolicy");
        cache = cache.withExpirePolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 1)));
        cache.put(1, 1);
        doSleep(10);
        assertFalse(cache.containsKey(1));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) BinaryObject(org.apache.ignite.binary.BinaryObject) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 45 with IgniteClient

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

the class JavaThinCompatibilityTest method testServicesWithCallerContextThrows.

/**
 */
private void testServicesWithCallerContextThrows() {
    X.println(">>>> Testing services with caller context throws");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ServiceCallContext callCtx = ServiceCallContext.builder().put("key", "value").build();
        EchoServiceInterface svc = client.services().serviceProxy("test_service", EchoServiceInterface.class, callCtx);
        Throwable err = assertThrowsWithCause(() -> svc.echo(1), ClientFeatureNotSupportedByServerException.class);
        assertEquals("Feature " + SERVICE_INVOKE_CALLCTX.name() + " is not supported by the server", err.getMessage());
    }
}
Also used : ServiceCallContext(org.apache.ignite.services.ServiceCallContext) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

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