use of org.apache.ignite.testframework.GridTestClassLoader 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.testframework.GridTestClassLoader in project ignite by apache.
the class GridP2PUndeploySelfTest method processTestUndeployLocalTasks.
/**
* @param depMode deployment mode.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void processTestUndeployLocalTasks(DeploymentMode depMode) throws Exception {
try {
this.depMode = depMode;
Ignite ignite1 = startGrid(1);
Ignite ignite2 = startGrid(2);
ClassLoader tstClsLdr = new GridTestClassLoader(GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
Class<? extends ComputeTask<?, ?>> task1 = (Class<? extends ComputeTask<?, ?>>) tstClsLdr.loadClass(GridP2PTestTask.class.getName());
ignite1.compute().localDeployTask(task1, tstClsLdr);
ignite1.compute().execute(task1.getName(), 1);
ignite2.compute().localDeployTask(task1, tstClsLdr);
ignite2.compute().execute(task1.getName(), 2);
LocalDeploymentSpi spi1 = spis.get(ignite1.name());
LocalDeploymentSpi spi2 = spis.get(ignite2.name());
assert spi1.findResource(task1.getName()) != null;
assert spi2.findResource(task1.getName()) != null;
assert ignite1.compute().localTasks().containsKey(task1.getName());
assert ignite2.compute().localTasks().containsKey(task1.getName());
ignite2.compute().undeployTask(task1.getName());
// Wait for undeploy.
Thread.sleep(1000);
assert spi1.findResource(task1.getName()) == null;
assert spi2.findResource(task1.getName()) == null;
assert !ignite1.compute().localTasks().containsKey(task1.getName());
assert !ignite2.compute().localTasks().containsKey(task1.getName());
} finally {
stopGrid(2);
stopGrid(1);
}
}
use of org.apache.ignite.testframework.GridTestClassLoader 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.testframework.GridTestClassLoader 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.testframework.GridTestClassLoader in project ignite by apache.
the class MarshallerContextLockingSelfTest method testMultithreadedUpdate.
/**
* Multithreaded test, used custom class loader
*/
public void testMultithreadedUpdate() throws Exception {
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
GridTestClassLoader classLoader = new GridTestClassLoader(InternalExecutor.class.getName(), MarshallerContextImpl.class.getName(), MarshallerContextImpl.CombinedMap.class.getName(), MappingStoreTask.class.getName(), MarshallerMappingFileStore.class.getName(), MarshallerMappingTransport.class.getName());
Thread.currentThread().setContextClassLoader(classLoader);
Class clazz = classLoader.loadClass(InternalExecutor.class.getName());
Object internelExecutor = clazz.newInstance();
clazz.getMethod("executeTest", GridTestLog4jLogger.class, GridKernalContext.class).invoke(internelExecutor, log, ctx);
return null;
}
}, THREADS);
final CountDownLatch arrive = new CountDownLatch(THREADS);
// Wait for all pending tasks in closure processor to complete.
for (int i = 0; i < THREADS; i++) {
ctx.closure().runLocalSafe(new GridPlainRunnable() {
@Override
public void run() {
arrive.countDown();
try {
arrive.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInterruptedException(e);
}
}
}, true);
}
arrive.await();
assertTrue(InternalExecutor.counter.get() == 0);
assertTrue(!innerLog.contains("Exception"));
assertTrue(innerLog.contains("File already locked"));
}
Aggregations