use of org.apache.ignite.client.ClientCompute in project ignite by apache.
the class ComputeTaskRemoteSecurityContextTest method testIgniteClient.
/**
* Tests task execution security context in case task was initiated from the {@link IgniteClient}.
*/
@Test
public void testIgniteClient() throws Exception {
String login = "thin_client";
ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(login).setUserPassword("");
try (IgniteClient cli = Ignition.startClient(cfg)) {
ClientCompute comp = cli.compute(cli.cluster().forNodes(cli.cluster().nodes()));
if (failWithTimeout)
comp = comp.withTimeout(TEST_TASK_TIMEOUT);
String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
Throwable timeoutE = null;
try {
if (async)
comp.executeAsync2(taskName, login).get();
else
comp.execute(taskName, login);
checkTaskEvents("crd", login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
} catch (Throwable e) {
if (!failWithTimeout)
throw e;
timeoutE = e;
}
if (failWithTimeout) {
assertNotNull(timeoutE);
assertTrue(X.hasCause(timeoutE, "Task timed out", ClientServerError.class));
checkTaskEvents("crd", login, REDUCER_FAILED_TASK_EVENTS, MAP_NODE_FAILED_TASK_EVENTS);
}
}
}
use of org.apache.ignite.client.ClientCompute in project ignite by apache.
the class ComputeTaskTest method testTaskWithNoFailover.
/**
*/
@Test
public void testTaskWithNoFailover() throws Exception {
try (IgniteClient client = startClient(0)) {
ClientCompute computeWithFailover = client.compute();
ClientCompute computeWithNoFailover = client.compute().withNoFailover();
assertTrue(computeWithFailover.execute(TestFailoverTask.class.getName(), null));
assertFalse(computeWithNoFailover.execute(TestFailoverTask.class.getName(), null));
}
}
use of org.apache.ignite.client.ClientCompute in project ignite by apache.
the class ComputeTaskTest method testExecuteTaskConcurrentLoad.
/**
*/
@Test
public void testExecuteTaskConcurrentLoad() throws Exception {
try (IgniteClient client = startClient(0)) {
int threadsCnt = 20;
int iterations = 100;
ClientCache<Integer, Integer> cache = client.getOrCreateCache(DEFAULT_CACHE_NAME);
AtomicInteger threadIdxs = new AtomicInteger();
CyclicBarrier barrier = new CyclicBarrier(threadsCnt);
GridTestUtils.runMultiThreaded(() -> {
int threadIdx = threadIdxs.incrementAndGet();
Random rnd = new Random();
try {
barrier.await();
for (int i = 0; i < iterations; i++) {
int nodeIdx = rnd.nextInt(GRIDS_CNT);
cache.put(threadIdx, i);
ClientCompute compute = client.compute(client.cluster().forNodeId(nodeId(nodeIdx)));
Future<T2<UUID, Set<UUID>>> fut = compute.executeAsync(TestTask.class.getName(), null);
boolean cancelled = (i % 3 == 0) && fut.cancel(true);
assertEquals((Integer) i, cache.get(threadIdx));
if (cancelled)
assertTrue(fut.isCancelled());
else
assertEquals(nodeIds(nodeIdx), fut.get().get2());
}
} catch (ExecutionException e) {
log.error("Task failed: ", e);
fail("Task failed");
} catch (InterruptedException | BrokenBarrierException ignore) {
// No-op.
}
}, threadsCnt, "run-task-async");
assertTrue(GridTestUtils.waitForCondition(() -> ((ClientComputeImpl) client.compute()).activeTasksCount() == 0, TIMEOUT));
}
}
use of org.apache.ignite.client.ClientCompute 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.ClientCompute 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