/** */ public GridP2PClassLoadingSelfTest() { super(/*start grid*/false); tstClsLdr = new GridTestClassLoader( Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName() ); }
/** {@inheritDoc} */ @Override protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class<?> res = findLoadedClass(name); if (res != null) return res; boolean patch = false; for (String clsName : clsNames) if (name.equals(clsName)) patch = true; if (patch) { String path = name.replaceAll("\\.", "/") + ".class"; InputStream in = getResourceAsStream(path); if (in != null) { GridByteArrayList bytes = new GridByteArrayList(1024); try { bytes.readAll(in); } catch (IOException e) { throw new ClassNotFoundException("Failed to upload class ", e); } return defineClass(name, bytes.internalArray(), 0, bytes.size()); } throw new ClassNotFoundException("Failed to upload resource [class=" + path + ", parent classloader=" + getParent() + ']'); } // Maybe super knows. return super.loadClass(name, resolve); }
@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);
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public InputStream getResourceAsStream(String name) { if (rsrcs != null && rsrcs.containsKey(name)) return new StringBufferInputStream(rsrcs.get(name)); return getParent().getResourceAsStream(name); } }
/** * Tests marshal classes * * @throws Exception If test failed. */ @Test public void testExternalClassesMarshalling() throws Exception { ClassLoader tstClsLdr = new GridTestClassLoader( Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), getClass().getClassLoader(), GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName() ); ComputeTask<?, ?> inTask = (ComputeTask<?, ?>)tstClsLdr.loadClass(GridP2PTestTask.class.getName()). newInstance(); byte[] buf = marsh.marshal(inTask); ComputeTask<?, ?> outTask = marsh.unmarshal(buf, tstClsLdr); assert inTask != outTask; assert inTask.getClass().equals(outTask.getClass()); }
new GridTestClassLoader( Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask.class.getName(), GridP2PRemoteTestJob.class.getName() new GridTestClassLoader( Collections.EMPTY_MAP, getClass().getClassLoader(), GridP2PRemoteTestTask1.class.getName(), GridP2PRemoteTestJob.class.getName());
new GridTestClassLoader( Collections.<String, String>emptyMap(), getClass().getClassLoader(), GridP2PRemoteTestTask.class.getName(), GridP2PRemoteTestTask1.class.getName(),
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(),
ClassLoader ldr1 = new GridTestClassLoader( Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), ClassLoader ldr2 = new GridTestClassLoader( Collections.singletonMap("testResource", "2"), getClass().getClassLoader(),
ClassLoader ldr1 = new GridTestClassLoader( Collections.singletonMap("testResource", "1"), getClass().getClassLoader()); ClassLoader ldr2 = new GridTestClassLoader( Collections.singletonMap("testResource", "2"), getClass().getClassLoader(),
ignite2 = startGrid(2); ClassLoader ldr1 = new GridTestClassLoader( Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), ); ClassLoader ldr2 = new GridTestClassLoader( Collections.singletonMap("testResource", "2"), getClass().getClassLoader(),
ignite2 = startGrid(2); ClassLoader ldr1 = new GridTestClassLoader( Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), ); ClassLoader ldr2 = new GridTestClassLoader( Collections.singletonMap("testResource", "2"), getClass().getClassLoader(),
Ignite ignite2 = startGrid(2); ClassLoader tstClsLdr = new GridTestClassLoader(GridP2PTestTask.class.getName(), GridP2PTestJob.class.getName());
); ClassLoader ldr1 = new GridTestClassLoader( Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), EXCLUDE_CLASSES); ClassLoader ldr2 = new GridTestClassLoader( Collections.singletonMap("testResource", "2"), getClass().getClassLoader(),
Ignite ignite2 = startGrid(2); ClassLoader ldr = new GridTestClassLoader( Collections.singletonMap("org/apache/ignite/p2p/p2p.properties", "resource=loaded"), GridP2PTestTask.class.getName(),