Search in sources :

Example 1 with ServiceCallContextBuilder

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));
    }
}
Also used : ServiceCallContext(org.apache.ignite.services.ServiceCallContext) IgniteClient(org.apache.ignite.client.IgniteClient) ServiceCallContextBuilder(org.apache.ignite.services.ServiceCallContextBuilder) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)1 ServiceCallContext (org.apache.ignite.services.ServiceCallContext)1 ServiceCallContextBuilder (org.apache.ignite.services.ServiceCallContextBuilder)1 Test (org.junit.Test)1