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