use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassLoaderTest method testDenyImportResourceStems.
@Test
public void testDenyImportResourceStems() {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("pluginA").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setExportResources("export/folderA/*,export/folderB/*").setExportClasses(ITest.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassAndResourceCache();
BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
bizModel.setBizName("bizA").setBizVersion("1.0.0").setClassPath(new URL[0]).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
bizModel.setDenyImportResources("export/folderA/*,export/folderB/test3.xml");
bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
bizModel.setDenyImportClasses(StringUtils.EMPTY_STRING);
bizManagerService.registerBiz(bizModel);
String testResource1 = "export/folderA/test1.xml";
String testResource2 = "export/folderA/test2.xml";
String testResource3 = "export/folderB/test3.xml";
String testResource4 = "export/folderB/test4.xml";
Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource1));
Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource2));
Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource3));
// testResource4 not in deny-import
Assert.assertNotNull(bizModel.getBizClassLoader().getResource(testResource4));
Assert.assertEquals(pluginA.getPluginClassLoader().getResource(testResource4), bizModel.getBizClassLoader().getResource(testResource4));
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassLoaderTest method testGetPluginClassResource.
@Test
public void testGetPluginClassResource() {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages("").setExportClasses(ITest.class.getName()).setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassAndResourceCache();
BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[0]).setDenyImportClasses(StringUtils.EMPTY_STRING).setDenyImportResources(StringUtils.EMPTY_STRING).setDenyImportPackages(StringUtils.EMPTY_STRING).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
Assert.assertNotNull(bizModel.getBizClassLoader().getResource(ITest.class.getName().replace(".", "/") + ".class"));
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassLoaderTest method testCacheResource.
@Test
public void testCacheResource() throws NoSuchFieldException, IllegalAccessException {
BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[] {}).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
ClassLoader cl = bizModel.getBizClassLoader();
String name = "META-INF/services/javax.script.ScriptEngineFactory";
URL res1 = cl.getResource(name);
Assert.assertNotNull(res1);
Assert.assertNotNull(cl.getResource(name));
Cache<String, Optional<URL>> urlResourceCache = getUrlResourceCache(cl);
Assert.assertNotNull(urlResourceCache.getIfPresent(name));
Assert.assertNotNull(urlResourceCache.getIfPresent(name).get());
// not existing url
String notExistingName = "META-INF/services/javax.script.ScriptEngineFactory/NotExisting";
URL notExistingRes = cl.getResource(notExistingName);
Assert.assertNull(notExistingRes);
Assert.assertNull(cl.getResource(notExistingName));
Assert.assertNotNull(urlResourceCache.getIfPresent(notExistingName));
Assert.assertFalse(urlResourceCache.getIfPresent(notExistingName).isPresent());
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizManagerServiceTest method testDuplicatedRegisterBiz.
@Test
public void testDuplicatedRegisterBiz() {
Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
Assert.assertFalse(bizManagerService.registerBiz(biz));
Assert.assertTrue(bizManagerService.getBiz("test-biz").size() == 1);
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizManagerServiceTest method testBizGet.
@Test
public void testBizGet() {
Biz biz = bizManagerService.getBizByIdentity("test-biz:1.0.0");
Assert.assertNotNull(biz);
Set<String> stringSet = bizManagerService.getAllBizNames();
Assert.assertTrue(stringSet.size() == 1);
Assert.assertTrue(stringSet.contains("test-biz"));
biz = bizManagerService.getActiveBiz("test-biz");
Assert.assertNull(biz);
BizState bizState = bizManagerService.getBizState("test-biz:1.0.0");
Assert.assertTrue(bizState == BizState.RESOLVED);
bizState = bizManagerService.getBizState("test-biz", "1.0.0");
Assert.assertTrue(bizState == BizState.RESOLVED);
bizState = bizManagerService.getBizState("ss", "xx");
Assert.assertTrue(bizState == BizState.UNRESOLVED);
biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.1").setBizState(BizState.RESOLVED).setPriority("10");
bizManagerService.registerBiz(biz);
List<Biz> bizList = bizManagerService.getBizInOrder();
Assert.assertTrue(bizList.size() == 2);
Assert.assertTrue(bizList.get(0).getBizVersion().equals("1.0.1"));
Assert.assertTrue(bizList.get(1).getBizVersion().equals("1.0.0"));
biz = bizManagerService.getActiveBiz("test-biz");
Assert.assertNull(biz);
bizManagerService.activeBiz("test-biz", "1.0.1");
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.1") == BizState.RESOLVED);
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.0") == BizState.RESOLVED);
biz = bizManagerService.getBiz("test-biz", "1.0.1");
((BizModel) biz).setBizState(BizState.DEACTIVATED);
bizManagerService.activeBiz("test-biz", "1.0.1");
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.1") == BizState.ACTIVATED);
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.0") == BizState.RESOLVED);
bizManagerService.activeBiz("test-biz", "1.0.0");
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.1") == BizState.ACTIVATED);
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.0") == BizState.RESOLVED);
biz = bizManagerService.getBiz("test-biz", "1.0.0");
((BizModel) biz).setBizState(BizState.DEACTIVATED);
bizManagerService.activeBiz("test-biz", "1.0.0");
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.0") == BizState.ACTIVATED);
Assert.assertTrue(bizManagerService.getBizState("test-biz", "1.0.1") == BizState.DEACTIVATED);
}
Aggregations