use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class OptimizedMarshallerClassesCachedTest method testLocalDateTimeMetaCached.
/**
* Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client.
*/
@Test
public void testLocalDateTimeMetaCached() throws Exception {
try (Ignite srv = startGrid(0)) {
srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());
IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {
@Override
public <T> T service(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.service(op, payloadWriter, payloadReader);
}
@Override
public <T> CompletableFuture<T> serviceAsync(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.serviceAsync(op, payloadWriter, payloadReader);
}
}, new ClientConfiguration().setAddresses(Config.SERVER));
try {
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
} finally {
cli.close();
}
assertEquals(1, cnt.get());
}
}
use of org.apache.ignite.client.IgniteClient 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.IgniteClient in project ignite by apache.
the class ComputeTaskTest method testExecuteTaskAsync.
/**
*/
@Test
public void testExecuteTaskAsync() throws Exception {
try (IgniteClient client = startClient(0)) {
TestLatchTask.latch = new CountDownLatch(1);
Future<T2<UUID, Set<UUID>>> fut = client.compute().executeAsync(TestLatchTask.class.getName(), null);
GridTestUtils.assertThrowsAnyCause(null, () -> fut.get(10L, TimeUnit.MILLISECONDS), TimeoutException.class, null);
assertFalse(fut.isDone());
TestLatchTask.latch.countDown();
T2<UUID, Set<UUID>> val = fut.get();
assertTrue(fut.isDone());
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 testExecuteTaskAsync2.
/**
* Tests asynchronous task execution.
*/
@Test
public void testExecuteTaskAsync2() throws Exception {
try (IgniteClient client = startClient(0)) {
TestLatchTask.latch = new CountDownLatch(1);
IgniteClientFuture<T2<UUID, Set<UUID>>> fut = client.compute().executeAsync2(TestLatchTask.class.getName(), null);
GridTestUtils.assertThrowsAnyCause(null, () -> fut.get(10L, TimeUnit.MILLISECONDS), TimeoutException.class, null);
assertFalse(fut.isDone());
TestLatchTask.latch.countDown();
T2<UUID, Set<UUID>> val = fut.get();
assertTrue(fut.isDone());
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 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));
}
}
Aggregations