Search in sources :

Example 36 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ComputeTaskTest method testTaskCancellation.

/**
 */
@Test(expected = CancellationException.class)
public void testTaskCancellation() throws Exception {
    try (IgniteClient client = startClient(0)) {
        Future<T2<UUID, List<UUID>>> fut = client.compute().executeAsync(TestTask.class.getName(), TIMEOUT);
        assertFalse(fut.isCancelled());
        assertFalse(fut.isDone());
        assertTrue(fut.cancel(true));
        assertTrue(GridTestUtils.waitForCondition(() -> ((ClientComputeImpl) client.compute()).activeTasksCount() == 0, TIMEOUT));
        assertTrue(fut.isCancelled());
        assertTrue(fut.isDone());
        fut.get();
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) Test(org.junit.Test)

Example 37 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ComputeTaskTest method testExecuteTaskOnEmptyClusterGroup.

/**
 */
@Test(expected = ClientException.class)
public void testExecuteTaskOnEmptyClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeIds(Collections.emptyList());
        client.compute(grp).execute(TestTask.class.getName(), null);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) Test(org.junit.Test)

Example 38 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ClusterApiTest method testClusterState.

/**
 * Test change cluster state operation by thin client.
 */
@Test
public void testClusterState() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientCluster clientCluster = client.cluster();
        IgniteCluster igniteCluster = grid(0).cluster();
        changeAndCheckState(clientCluster, igniteCluster, ClusterState.INACTIVE);
        changeAndCheckState(clientCluster, igniteCluster, ClusterState.ACTIVE_READ_ONLY);
        changeAndCheckState(clientCluster, igniteCluster, ClusterState.ACTIVE);
        changeAndCheckState(clientCluster, igniteCluster, ClusterState.INACTIVE);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) IgniteCluster(org.apache.ignite.IgniteCluster) ClientCluster(org.apache.ignite.client.ClientCluster) Test(org.junit.Test)

Example 39 with IgniteClient

use of org.apache.ignite.client.IgniteClient in project ignite by apache.

the class ServicesTest method testOverloadedMethods.

/**
 * Test that overloaded methods resolved correctly.
 */
@Test
public void testOverloadedMethods() 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);
        checkOverloadedMethods(svc);
        // Test remote service calls (client connected to grid(0) but service deployed to grid(1)).
        svc = client.services().serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        checkOverloadedMethods(svc);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Test(org.junit.Test)

Example 40 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9