use of org.apache.ignite.lang.IgniteCallable in project ignite by apache.
the class GridClosureSerializationTest method testAttributesSerializationFailure.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "Convert2Lambda" })
public void testAttributesSerializationFailure() throws Exception {
final IgniteEx ignite0 = grid(0);
final IgniteEx ignite1 = grid(1);
GridTestUtils.assertThrows(null, new Callable<Object>() {
@JobContextResource
private ComputeJobContext jobCtx;
@Override
public Object call() throws Exception {
ignite1.compute(ignite1.cluster().forNode(ignite0.localNode())).call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
jobCtx.setAttribute("test-attr", new BrokenAttribute());
return null;
}
});
return null;
}
}, IgniteException.class, null);
}
use of org.apache.ignite.lang.IgniteCallable in project ignite by apache.
the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.
/**
* @throws Exception If fails.
*/
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.lang.IgniteCallable in project ignite by apache.
the class IgniteLockAbstractSelfTest method checkReentrantLock.
/**
* @throws Exception If failed.
*/
private void checkReentrantLock(final boolean fair) throws Exception {
// Test API.
checkLock(fair);
checkFailoverSafe(fair);
// Test main functionality.
IgniteLock lock1 = grid(0).reentrantLock("lock", true, fair, true);
assertFalse(lock1.isLocked());
lock1.lock();
IgniteFuture<Object> fut = grid(0).compute().callAsync(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@LoggerResource
private IgniteLogger log;
@Nullable
@Override
public Object call() throws Exception {
// Test reentrant lock in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteLock lock = ignite.reentrantLock("lock", true, fair, true);
assert lock != null;
log.info("Thread is going to wait on reentrant lock: " + Thread.currentThread().getName());
assert lock.tryLock(1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName());
lock.unlock();
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
assert lock1.isHeldByCurrentThread();
assert lock1.getHoldCount() == 1;
lock1.lock();
assert lock1.isHeldByCurrentThread();
assert lock1.getHoldCount() == 2;
lock1.unlock();
lock1.unlock();
// Ensure there are no hangs.
fut.get();
// Test operations on removed lock.
lock1.close();
checkRemovedReentrantLock(lock1);
}
use of org.apache.ignite.lang.IgniteCallable in project ignite by apache.
the class GridP2PLocalDeploymentSelfTest method testConcurrentDeploymentWithDelegatingClassloader.
/**
* Tests concurrent deployment using delegating classloader for the task.
*/
public void testConcurrentDeploymentWithDelegatingClassloader() throws Exception {
depMode = DeploymentMode.SHARED;
// Force rmvQueue removal task to run very often.
System.setProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL, "1");
System.setProperty(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK, "true");
try {
final Ignite ignite = startGrid();
final ClassLoader delegate = ignite.getClass().getClassLoader();
final ClassLoader root = new DelegateClassLoader(null, delegate);
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!stop.get()) {
final Class<?> clazz = root.loadClass("org.apache.ignite.p2p.GridP2PLocalDeploymentSelfTest$TestClosure");
ignite.compute().call((IgniteCallable) clazz.getDeclaredConstructor(ClassLoader.class).newInstance(root));
}
return null;
}
}, 1);
ignite.scheduler().runLocal(new Runnable() {
@Override
public void run() {
stop.set(true);
}
}, 10, TimeUnit.SECONDS);
fut.get();
} finally {
stopAllGrids();
System.clearProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL);
System.clearProperty(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK);
}
}
Aggregations