Search in sources :

Example 81 with IgniteClient

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

the class ComputeTaskTest method testTaskWithNoResultCache.

/**
 */
@Test
public void testTaskWithNoResultCache() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientCompute computeWithCache = client.compute();
        ClientCompute computeWithNoCache = client.compute().withNoResultCache();
        assertTrue(computeWithCache.execute(TestResultCacheTask.class.getName(), null));
        assertFalse(computeWithNoCache.execute(TestResultCacheTask.class.getName(), null));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 82 with IgniteClient

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

the class ComputeTaskTest method testComputeWithMixedModificators.

/**
 */
@Test
public void testComputeWithMixedModificators() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeId(nodeId(1), nodeId(2));
        ClientCompute compute = client.compute(grp).withNoFailover().withNoResultCache().withTimeout(TIMEOUT / 5);
        T2<UUID, List<UUID>> val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeIds(1, 2), val.get2());
        assertFalse(compute.execute(TestFailoverTask.class.getName(), null));
        assertFalse(compute.execute(TestResultCacheTask.class.getName(), null));
        GridTestUtils.assertThrowsAnyCause(null, () -> compute.execute(TestTask.class.getName(), TIMEOUT), ClientException.class, null);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 83 with IgniteClient

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

the class ComputeTaskTest method testExecuteTwoTasksMisorderedResults.

/**
 */
@Test
public void testExecuteTwoTasksMisorderedResults() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientCompute compute1 = client.compute(client.cluster().forNodeId(nodeId(1)));
        ClientCompute compute2 = client.compute(client.cluster().forNodeId(nodeId(2)));
        CountDownLatch latch1 = TestLatchTask.latch = new CountDownLatch(2);
        TestLatchTask.startLatch = new CountDownLatch(1);
        Future<T2<UUID, Set<UUID>>> fut1 = compute1.executeAsync(TestLatchTask.class.getName(), null);
        TestLatchTask.startLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
        CountDownLatch latch2 = TestLatchTask.latch = new CountDownLatch(1);
        TestLatchTask.startLatch = new CountDownLatch(1);
        Future<T2<UUID, Set<UUID>>> fut2 = compute2.executeAsync(TestLatchTask.class.getName(), null);
        TestLatchTask.startLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
        latch2.countDown();
        assertEquals(nodeIds(2), fut2.get().get2());
        assertFalse(fut1.isDone());
        latch1.countDown();
        assertEquals(nodeIds(1), fut1.get().get2());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 84 with IgniteClient

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

the class ComputeTaskTest method testExecuteTaskOnClusterGroup.

/**
 */
@Test
public void testExecuteTaskOnClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeIds(nodeIds(1, 2));
        T2<UUID, List<UUID>> val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(nodeIds(1, 2), val.get2());
        // Compute on client node defined explicitly.
        grp = client.cluster().forNodeIds(nodeIds(3));
        val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(nodeIds(3), val.get2());
        // Compute on all nodes (clients + servers).
        grp = client.cluster();
        val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(new HashSet<>(F.nodeIds(grid(0).cluster().nodes())), val.get2());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Example 85 with IgniteClient

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

the class ComputeTaskTest method testExecuteTaskByName.

/**
 */
@Test
public void testExecuteTaskByName() throws Exception {
    try (IgniteClient client = startClient(0)) {
        // We should deploy class manually to make it visible to server node by task name.
        grid(0).compute().localDeployTask(TestTask.class, TestTask.class.getClassLoader());
        T2<UUID, Set<UUID>> val = client.compute().execute(TEST_TASK_NAME, null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(new HashSet<>(F.nodeIds(grid(0).cluster().forServers().nodes())), val.get2());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IgniteClient(org.apache.ignite.client.IgniteClient) UUID(java.util.UUID) 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