use of org.apache.ignite.services.ServiceCallContextBuilder 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));
}
}
Aggregations