### Question:
DatabaseResourceService extends AbstractService { protected ClassLoader getClassLoader(String database) { return classLoaderCache.get(database); } DatabaseResourceService(String name); @Override synchronized void start(); @Override synchronized void stop(); Collection<LensSessionImpl.ResourceEntry> getResourcesForDatabase(String database); static final String NAME; static final String LOAD_RESOURCES_ERRORS; }### Answer:
@Test public void verifyClassLoader() throws Exception { try { Class clz = Class.forName("ClassLoaderTestClass", true, getClass().getClassLoader()); Assert.fail("Expected class loading to fail"); } catch (Throwable th) { log.error("Expected error " + th + " msg = "+th.getMessage(), th); } Class clz = Class.forName(TEST_CLASS, true, dbResService.getClassLoader(DB1)); Assert.assertNotNull(clz); }
@Test public void testClassLoaderCreated() throws Exception { ClassLoader db1Loader = dbResService.getClassLoader(DB1); ClassLoader db2Loader = dbResService.getClassLoader(DB2); Assert.assertNotNull(db1Loader); Assert.assertNotNull(db2Loader); Assert.assertTrue(db1Loader != db2Loader); }
@Test public void testJarsLoaded() throws Exception { Assert.assertTrue(isJarLoaded(dbResService.getClassLoader(DB1), DB1), DB1 + " jar should be loaded"); Assert.assertTrue(isJarLoaded(dbResService.getClassLoader(DB2), DB2), DB2 + " jar should be loaded"); Assert.assertFalse(isJarLoaded(dbResService.getClassLoader(DB2), DB1)); Assert.assertFalse(isJarLoaded(dbResService.getClassLoader(DB1), DB2)); }