use of org.apache.ignite.compute.ComputeTask in project ignite by apache.
the class GridP2PRemoteClassLoadersSelfTest method processTestDifferentRemoteClassLoader.
/**
* @param depMode deployment mode.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void processTestDifferentRemoteClassLoader(DeploymentMode depMode) throws Exception {
try {
this.depMode = depMode;
GridP2PTestStaticVariable.staticVar = 0;
Ignite ignite1 = startGrid(1);
startGrid(2);
waitForRemoteNodes(ignite1, 1);
ClassLoader tstClsLdr1 = new GridTestClassLoader(Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask.class.getName(), GridP2PRemoteTestJob.class.getName());
ClassLoader tstClsLdr2 = new GridTestClassLoader(Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask1.class.getName(), GridP2PRemoteTestJob.class.getName());
Class<? extends ComputeTask<?, ?>> task1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr1.loadClass(GridP2PRemoteTestTask.class.getName());
Class<? extends ComputeTask<?, ?>> task2 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr2.loadClass(GridP2PRemoteTestTask1.class.getName());
Object res1 = ignite1.compute().execute(task1.newInstance(), null);
Object res2 = ignite1.compute().execute(task2.newInstance(), null);
info("Check results.");
// One remote p2p class loader
assert res1 != null : "res1 != null";
assert res1 instanceof Long : "res1 instanceof Long != true";
assert res1.equals(0L) : "Invalid res2 value: " + res1;
// Another remote p2p class loader.
assert res2 != null : "res2 == null";
assert res2 instanceof Long : "res2 instanceof Long != true";
assert res2.equals(0L) : "Invalid res2 value: " + res2;
info("Tests passed.");
} finally {
stopGrid(2);
stopGrid(1);
}
}
use of org.apache.ignite.compute.ComputeTask in project ignite by apache.
the class IgniteExplicitImplicitDeploymentSelfTest method execExplicitDeployP2P.
/**
* @param byCls If {@code true} than executes task by Class.
* @param byTask If {@code true} than executes task instance.
* @param byName If {@code true} than executes task by class name.
* @throws Exception If test failed.
*/
@SuppressWarnings("unchecked")
private void execExplicitDeployP2P(boolean byCls, boolean byTask, boolean byName) throws Exception {
Ignite ignite1 = null;
Ignite ignite2 = null;
try {
ignite1 = startGrid(1);
ignite2 = startGrid(2);
ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), GridDeploymentResourceTestTask.class.getName(), GridDeploymentResourceTestJob.class.getName());
ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), GridDeploymentResourceTestTask.class.getName(), GridDeploymentResourceTestJob.class.getName());
Class<? extends ComputeTask<String, Integer>> taskCls = (Class<? extends ComputeTask<String, Integer>>) ldr2.loadClass(GridDeploymentResourceTestTask.class.getName());
if (byCls) {
ignite1.compute().localDeployTask(taskCls, ldr1);
// Even though the task is deployed with resource class loader,
// when we execute it, it will be redeployed with task class-loader.
Integer res = ignite1.compute().execute(taskCls, null);
assert res != null;
assert res == 2 : "Invalid response: " + res;
}
if (byTask) {
ignite1.compute().localDeployTask(taskCls, ldr1);
// Even though the task is deployed with resource class loader,
// when we execute it, it will be redeployed with task class-loader.
Integer res = ignite1.compute().execute(taskCls.newInstance(), null);
assert res != null;
assert res == 2 : "Invalid response: " + res;
}
if (byName) {
ignite1.compute().localDeployTask(taskCls, ldr1);
// Even though the task is deployed with resource class loader,
// when we execute it, it will be redeployed with task class-loader.
Integer res = (Integer) ignite1.compute().execute(taskCls.getName(), null);
assert res != null;
assert res == 1 : "Invalid response: " + res;
}
} finally {
stopGrid(ignite2);
stopGrid(ignite1);
}
}
use of org.apache.ignite.compute.ComputeTask in project ignite by apache.
the class GridMultipleVersionsDeploymentSelfTest method testMultipleVersionsLocalDeploy.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings("unchecked")
public void testMultipleVersionsLocalDeploy() throws Exception {
try {
Ignite ignite = startGrid(1);
ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), EXCLUDE_CLASSES);
ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), EXCLUDE_CLASSES);
Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) ldr1.loadClass(GridDeploymentTestTask.class.getName());
Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>) ldr2.loadClass(GridDeploymentTestTask.class.getName());
ignite.compute().localDeployTask(taskCls1, ldr1);
// Task will wait for the signal.
ComputeTaskFuture fut = executeAsync(ignite.compute(), "GridDeploymentTestTask", null);
// We should wait here when to be sure that job has been started.
// Since we loader task/job classes with different class loaders we cannot
// use any kind of mutex because of the illegal state exception.
// We have to use timer here. DO NOT CHANGE 2 seconds. This should be enough
// on Bamboo.
Thread.sleep(2000);
assert checkDeployed(ignite, "GridDeploymentTestTask");
// Deploy new one - this should move first task to the obsolete list.
ignite.compute().localDeployTask(taskCls2, ldr2);
boolean deployed = checkDeployed(ignite, "GridDeploymentTestTask");
Object res = fut.get();
ignite.compute().undeployTask("GridDeploymentTestTask");
// New one should be deployed.
assert deployed;
// Wait for the execution.
assert res.equals(1);
} finally {
stopGrid(1);
}
}
use of org.apache.ignite.compute.ComputeTask in project ignite by apache.
the class P2PGridifySelfTest method processTestBothNodesDeploy.
/**
* @param depMode deployment mode.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void processTestBothNodesDeploy(DeploymentMode depMode) throws Exception {
int res = 0;
try {
this.depMode = depMode;
Ignite ignite1 = startGrid(1);
startGrid(2);
GridTestClassLoader tstClsLdr = new GridTestClassLoader(Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), getClass().getClassLoader(), GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.loadClass(GridP2PTestTask.class.getName());
ignite1.compute().localDeployTask(taskCls1, taskCls1.getClassLoader());
res = executeGridify(1);
ignite1.compute().undeployTask(taskCls1.getName());
} finally {
stopGrid(2);
stopGrid(1);
}
// P2P deployment
assert res == 10 : "Invalid gridify result: " + res;
}
use of org.apache.ignite.compute.ComputeTask in project ignite by apache.
the class GridP2PHotRedeploymentSelfTest method processTestClassLoaderHotRedeployment.
/**
* @param depMode deployment mode.
* @throws Exception If failed.
*/
private void processTestClassLoaderHotRedeployment(DeploymentMode depMode) throws Exception {
try {
this.depMode = depMode;
Ignite ignite1 = startGrid(1);
Ignite ignite2 = startGrid(2);
waitForDiscovery(ignite1, ignite2);
ClassLoader ldr1 = getExternalClassLoader();
ClassLoader ldr2 = getExternalClassLoader();
Class<? extends ComputeTask<Object, Integer>> taskCls1 = (Class<? extends ComputeTask<Object, Integer>>) ldr1.loadClass(TASK_NAME);
Class<? extends ComputeTask<Object, Integer>> taskCls2 = (Class<? extends ComputeTask<Object, Integer>>) ldr2.loadClass(TASK_NAME);
// Check that different instances used.
assert taskCls1.getClassLoader() != taskCls2.getClassLoader();
assert taskCls1 != taskCls2;
// final AtomicBoolean undeployed = new AtomicBoolean(false);
//
// grid2.events().localListen(new GridLocalEventListener() {
// @Override public void onEvent(GridEvent evt) {
// if (evt.type() == EVT_TASK_UNDEPLOYED) {
// assert ((GridDeploymentEvent)evt).alias().equals(TASK_NAME);
//
// undeployed.set(true);
// }
// }
// }, EVT_TASK_UNDEPLOYED);
ignite2.compute().localDeployTask(taskCls1, taskCls1.getClassLoader());
Integer res1 = ignite1.compute().execute(taskCls1, Collections.singletonList(ignite2.cluster().localNode().id()));
assert res1 != null;
info("Result1: " + res1);
Integer res2 = ignite1.compute().execute(taskCls2, Collections.singletonList(ignite2.cluster().localNode().id()));
assert res2 != null;
info("Result2: " + res2);
assert !res1.equals(res2);
// Thread.sleep(P2P_TIMEOUT * 2);
//
// assert undeployed.get();
} finally {
stopGrid(2);
stopGrid(1);
}
}
Aggregations