Search in sources :

Example 76 with IgniteClient

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

the class ComputeTaskTest method testExecuteTaskByClassName.

/**
 */
@Test
public void testExecuteTaskByClassName() throws Exception {
    try (IgniteClient client = startClient(0)) {
        T2<UUID, Set<UUID>> val = client.compute().execute(TestTask.class.getName(), 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)

Example 77 with IgniteClient

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

the class ComputeTaskTest method testExecuteTaskConnectionLost.

/**
 */
@Test
public void testExecuteTaskConnectionLost() throws Exception {
    try (IgniteClient client = startClient(0, 1)) {
        ClientComputeImpl compute = (ClientComputeImpl) client.compute();
        TestLatchTask.latch = new CountDownLatch(1);
        TestLatchTask.startLatch = new CountDownLatch(1);
        Future<Object> fut1 = compute.executeAsync(TestLatchTask.class.getName(), null);
        // Wait for the task to start, then drop connections.
        TestLatchTask.startLatch.await();
        dropAllThinClientConnections();
        TestLatchTask.startLatch = new CountDownLatch(1);
        Future<Object> fut2 = compute.executeAsync(TestLatchTask.class.getName(), null);
        TestLatchTask.startLatch.await();
        dropAllThinClientConnections();
        TestLatchTask.latch = new CountDownLatch(1);
        Future<Object> fut3 = compute.executeAsync(TestLatchTask.class.getName(), null);
        compute.execute(TestTask.class.getName(), null);
        GridTestUtils.assertThrowsAnyCause(null, fut1::get, ClientConnectionException.class, "closed");
        GridTestUtils.assertThrowsAnyCause(null, fut2::get, ClientConnectionException.class, "closed");
        assertFalse(fut3.isDone());
        TestLatchTask.latch.countDown();
        fut3.get(TIMEOUT, TimeUnit.MILLISECONDS);
        assertTrue(GridTestUtils.waitForCondition(() -> compute.activeTasksCount() == 0, TIMEOUT));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 78 with IgniteClient

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

the class ComputeTaskTest method testActiveTasksLimit.

/**
 */
@Test
public void testActiveTasksLimit() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientCompute compute = client.compute(client.cluster().forNodeId(nodeId(1)));
        CountDownLatch latch = TestLatchTask.latch = new CountDownLatch(1);
        List<Future<T2<UUID, Set<UUID>>>> futs = new ArrayList<>(ACTIVE_TASKS_LIMIT);
        for (int i = 0; i < ACTIVE_TASKS_LIMIT; i++) futs.add(compute.executeAsync(TestLatchTask.class.getName(), null));
        assertTrue(GridTestUtils.waitForCondition(() -> ((ClientComputeImpl) client.compute()).activeTasksCount() == ACTIVE_TASKS_LIMIT, TIMEOUT));
        // Check that we can't start more tasks.
        GridTestUtils.assertThrowsAnyCause(null, () -> compute.executeAsync(TestLatchTask.class.getName(), null).get(), ClientException.class, "limit");
        // Check that cancelled tasks restore limit.
        for (int i = 0; i < ACTIVE_TASKS_LIMIT / 2; i++) futs.get(i).cancel(true);
        latch.countDown();
        // Check that successfully complited tasks restore limit.
        for (int i = ACTIVE_TASKS_LIMIT / 2; i < ACTIVE_TASKS_LIMIT; i++) assertEquals(nodeIds(1), futs.get(i).get(TIMEOUT, TimeUnit.MILLISECONDS).get2());
        // Check that complited with error tasks restore limit.
        GridTestUtils.assertThrowsAnyCause(null, () -> compute.execute("NoSuchTask", null), ClientException.class, null);
        // Check that we can start up to ACTIVE_TASKS_LIMIT new active tasks again.
        latch = TestLatchTask.latch = new CountDownLatch(1);
        futs = new ArrayList<>(ACTIVE_TASKS_LIMIT);
        for (int i = 0; i < ACTIVE_TASKS_LIMIT; i++) futs.add(compute.executeAsync(TestLatchTask.class.getName(), null));
        latch.countDown();
        for (Future<T2<UUID, Set<UUID>>> fut : futs) assertEquals(nodeIds(1), fut.get(TIMEOUT, TimeUnit.MILLISECONDS).get2());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClient(org.apache.ignite.client.IgniteClient) Future(java.util.concurrent.Future) IgniteClientFuture(org.apache.ignite.client.IgniteClientFuture) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 79 with IgniteClient

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

the class ComputeTaskTest method testTaskCancellation2.

/**
 */
@Test(expected = CancellationException.class)
public void testTaskCancellation2() throws Exception {
    try (IgniteClient client = startClient(0)) {
        IgniteClientFuture<T2<UUID, List<UUID>>> fut = client.compute().executeAsync2(TestTask.class.getName(), TIMEOUT);
        assertFalse(fut.isCancelled());
        assertFalse(fut.isDone());
        AtomicReference<Throwable> handledErr = new AtomicReference<>();
        CompletionStage<T2<UUID, List<UUID>>> handledFut = fut.handle((r, err) -> {
            handledErr.set(err);
            return r;
        });
        fut.cancel(true);
        assertTrue(GridTestUtils.waitForCondition(() -> ((ClientComputeImpl) client.compute()).activeTasksCount() == 0, TIMEOUT));
        assertTrue(fut.isCancelled());
        assertTrue(fut.isDone());
        assertNotNull(handledErr.get());
        assertTrue(handledErr.get() instanceof CancellationException);
        assertNull(handledFut.toCompletableFuture().get());
        fut.get();
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) CancellationException(java.util.concurrent.CancellationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) Test(org.junit.Test)

Example 80 with IgniteClient

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

the class ComputeTaskTest method testExecuteTaskTwoClientsToOneNode.

/**
 */
@Test
public void testExecuteTaskTwoClientsToOneNode() throws Exception {
    try (IgniteClient client1 = startClient(0);
        IgniteClient client2 = startClient(0)) {
        ClientCompute compute1 = client1.compute(client1.cluster().forNodeId(nodeId(1)));
        ClientCompute compute2 = client2.compute(client2.cluster().forNodeId(nodeId(2)));
        CountDownLatch latch1 = TestLatchTask.latch = new CountDownLatch(1);
        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)

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