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()");
}
}
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");
}
}
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);
}
}
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));
}
}
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());
}
}
Aggregations