use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClosureProcessorSelfTest method testCallAsyncErrorNoFailover.
/**
* @throws Exception If failed.
*/
@Test
public void testCallAsyncErrorNoFailover() throws Exception {
IgniteCompute comp = compute(grid(0).cluster().forPredicate(F.notEqualTo(grid(0).localNode())));
IgniteFuture<Integer> fut = comp.withNoFailover().callAsync(new ClosureTestCallableError());
try {
fut.get();
assert false : "Exception should have been thrown.";
} catch (IgniteException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.
/**
* @throws Exception If fails.
*/
@Test
public void testAllComputeApiByCustomExecutor() throws Exception {
IgniteCompute comp = grid(0).compute().withExecutor(EXEC_NAME0);
comp.affinityRun(CACHE_NAME, primaryKey(grid(1).cache(CACHE_NAME)), new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
comp.affinityCall(CACHE_NAME, 0, new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
comp.broadcast(new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
comp.broadcast(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
comp.broadcast(new IgniteClosure<Object, Object>() {
@Override
public Object apply(Object o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, 0);
comp.apply(new IgniteClosure<Object, Object>() {
@Override
public Object apply(Object o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, 0);
comp.apply(new IgniteClosure<Integer, Object>() {
@Override
public Object apply(Integer o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, Collections.singletonList(0));
comp.apply(new IgniteClosure<Integer, Object>() {
@Override
public Object apply(Integer o) {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
}, Collections.singletonList(0), new IgniteReducer<Object, Object>() {
@Override
public boolean collect(@Nullable Object o) {
return true;
}
@Override
public Object reduce() {
return null;
}
});
List<IgniteCallable<Object>> calls = new ArrayList<>();
for (int i = 0; i < GRID_CNT * 2; ++i) {
calls.add(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
return null;
}
});
}
comp.call(calls.get(0));
comp.call(calls);
comp.call(calls, new IgniteReducer<Object, Object>() {
@Override
public boolean collect(@Nullable Object o) {
return true;
}
@Override
public Object reduce() {
return null;
}
});
List<IgniteRunnable> runs = new ArrayList<>();
for (int i = 0; i < GRID_CNT * 2; ++i) {
runs.add(new IgniteRunnable() {
@Override
public void run() {
assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
}
});
}
comp.run(runs.get(0));
comp.run(runs);
comp.execute(TestTask.class, null);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method igniteOperationsTest.
/**
* @throws Exception If failed.
*/
private void igniteOperationsTest() throws Exception {
final Ignite client = startClientGrid(serverCount());
final IgniteCache<Object, Object> dfltCache = client.cache(DEFAULT_CACHE_NAME);
final CountDownLatch recvLatch = new CountDownLatch(1);
assertNotNull(dfltCache);
doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check compute.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.compute();
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.compute();
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteCompute comp = (IgniteCompute) o;
Collection<UUID> uuids = comp.broadcast(new IgniteCallable<UUID>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public UUID call() throws Exception {
return ignite.cluster().localNode().id();
}
});
assertFalse(uuids.isEmpty());
for (UUID uuid : uuids) assertNotNull(uuid);
return true;
}
}), // Check ping node.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.cluster().pingNode(new UUID(0, 0));
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.cluster().pingNode(new UUID(0, 0));
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
Boolean pingNode = (Boolean) o;
assertFalse(pingNode);
return true;
}
}), // Check register remote listener.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.events().remoteListen(null, new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
return true;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.events().remoteListen(null, new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
return true;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
UUID remoteId = (UUID) o;
assertNotNull(remoteId);
client.events().stopRemoteListen(remoteId);
return true;
}
}), // Check message operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {
@Override
public boolean apply(UUID uuid, Object o) {
if (o.equals("Test message."))
recvLatch.countDown();
return true;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {
@Override
public boolean apply(UUID uuid, Object o) {
if (o.equals("Test message."))
recvLatch.countDown();
return true;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteMessaging msg = client.message();
msg.send(null, "Test message.");
try {
assertTrue(recvLatch.await(2, SECONDS));
} catch (InterruptedException ignored) {
fail("Message wasn't received.");
}
return true;
}
}), // Check executor.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.executorService().submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 42;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.executorService().submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 42;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
Future<Integer> fut = (Future<Integer>) o;
try {
assertEquals(42, (int) fut.get());
} catch (Exception ignored) {
fail("Failed submit task.");
}
return true;
}
})));
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridMultithreadedJobStealingSelfTest method testJoinedNodeCanStealJobs.
/**
* Test newly joined node can steal jobs.
*
* @throws Exception If test failed.
*/
@Test
public void testJoinedNodeCanStealJobs() throws Exception {
final AtomicReference<Exception> fail = new AtomicReference<>(null);
final AtomicInteger stolen = new AtomicInteger(0);
final AtomicInteger noneStolen = new AtomicInteger(0);
final GridConcurrentHashSet nodes = new GridConcurrentHashSet();
int threadsNum = 10;
final int jobsPerTask = 4;
jobExecutedLatch = new CountDownLatch(threadsNum);
final IgniteInternalFuture<Long> future = GridTestUtils.runMultiThreadedAsync(new Runnable() {
/**
*/
@Override
public void run() {
try {
final IgniteCompute compute = ignite.compute().withAsync();
compute.execute(new JobStealingTask(jobsPerTask), null);
JobStealingResult res = (JobStealingResult) compute.future().get();
info("Task result: " + res);
stolen.addAndGet(res.stolen);
noneStolen.addAndGet(res.nonStolen);
nodes.addAll(res.nodes);
} catch (IgniteException e) {
log.error("Failed to execute task.", e);
fail.getAndSet(e);
}
}
}, threadsNum, "JobStealingThread");
// Wait for first job begin execution.
jobExecutedLatch.await();
startGrid(2);
for (Ignite g : G.allGrids()) info("Metrics [nodeId=" + g.cluster().localNode().id() + ", metrics=" + g.cluster().localNode().metrics() + ']');
future.get();
assertNull("Test failed with exception: ", fail.get());
// Total jobs number is threadsNum * 4
assertEquals("Incorrect processed jobs number", threadsNum * jobsPerTask, stolen.get() + noneStolen.get());
assertFalse("No jobs were stolen.", stolen.get() == 0);
for (Ignite g : G.allGrids()) assertTrue("Node get no jobs.", nodes.contains(g.name()));
assertTrue("Stats [stolen=" + stolen + ", noneStolen=" + noneStolen + ']', Math.abs(stolen.get() - 2 * noneStolen.get()) <= 8);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectComputeApi.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectComputeApi() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCompute comp = client.compute();
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
comp.call(new DummyClosure());
comp.broadcast(new DummyClosure());
return null;
}
});
}
Aggregations