use of org.apache.ignite.services.ServiceCallContext in project ignite by apache.
the class ServicesTest method testServiceCallContext.
/**
* Test custom caller context.
*/
@Test
public void testServiceCallContext() {
String attrName = "testAttr";
String attrVal = "test";
String binAttrName = "binTestAttr";
byte[] binAttrVal = attrVal.getBytes();
try (IgniteClient client = startClient(0)) {
// Check proxy creation with an invalid implementation.
ServiceCallContext customCls = new ServiceCallContext() {
@Override
public String attribute(String name) {
return null;
}
@Override
public byte[] binaryAttribute(String name) {
return null;
}
};
GridTestUtils.assertThrowsAnyCause(log, () -> client.services().serviceProxy(NODE_SINGLTON_SERVICE_NAME, TestServiceInterface.class, customCls), IllegalArgumentException.class, "\"callCtx\" has an invalid type.");
// Check proxy creation with a valid caller context.
ServiceCallContext callCtx = new ServiceCallContextBuilder().put(attrName, attrVal).put(binAttrName, binAttrVal).build();
TestServiceInterface svc = client.services().serviceProxy(NODE_SINGLTON_SERVICE_NAME, TestServiceInterface.class, callCtx);
assertEquals(attrVal, svc.testContextAttribute(attrName));
assertArrayEquals(binAttrVal, svc.testContextBinaryAttribute(binAttrName));
}
}
use of org.apache.ignite.services.ServiceCallContext 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());
}
}
use of org.apache.ignite.services.ServiceCallContext in project ignite by apache.
the class JavaThinCompatibilityTest method testServicesWithCallerContext.
/**
*/
private void testServicesWithCallerContext() {
X.println(">>>> Testing services with caller context");
ServiceCallContext callCtx = ServiceCallContext.builder().put("key", "value").build();
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
assertEquals("value", client.services().serviceProxy("ctx_service", CtxServiceInterface.class, callCtx).attribute("key"));
}
}
use of org.apache.ignite.services.ServiceCallContext in project ignite by apache.
the class IgniteServiceCallContextTest method testInvalidContextImplementation.
/**
* Check proxy creation with an invalid implementation.
*/
@Test
public void testInvalidContextImplementation() {
ServiceCallContext callCtx = new ServiceCallContext() {
@Override
public String attribute(String name) {
return null;
}
@Override
public byte[] binaryAttribute(String name) {
return null;
}
};
GridTestUtils.assertThrowsAnyCause(log, () -> grid(0).services().serviceProxy(SVC_NAME, TestService.class, sticky, callCtx), IllegalArgumentException.class, "\"callCtx\" has an invalid type.");
}
Aggregations