Search in sources :

Example 1 with ServiceCallContext

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

Example 2 with ServiceCallContext

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

Example 3 with ServiceCallContext

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

Example 4 with ServiceCallContext

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.");
}
Also used : ServiceCallContext(org.apache.ignite.services.ServiceCallContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ServiceCallContext (org.apache.ignite.services.ServiceCallContext)4 IgniteClient (org.apache.ignite.client.IgniteClient)3 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)2 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)2 Test (org.junit.Test)2 ServiceCallContextBuilder (org.apache.ignite.services.ServiceCallContextBuilder)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1