Search in sources :

Example 6 with BizModel

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));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 7 with BizModel

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"));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 8 with BizModel

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());
}
Also used : Optional(java.util.Optional) URLClassLoader(java.net.URLClassLoader) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 9 with BizModel

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);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 10 with BizModel

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);
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) BizState(com.alipay.sofa.ark.spi.model.BizState) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Aggregations

BizModel (com.alipay.sofa.ark.container.model.BizModel)31 Test (org.junit.Test)22 BaseTest (com.alipay.sofa.ark.container.BaseTest)18 Biz (com.alipay.sofa.ark.spi.model.Biz)12 ITest (com.alipay.sofa.ark.container.testdata.ITest)11 URL (java.net.URL)11 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)8 HandleArchiveStage (com.alipay.sofa.ark.container.pipeline.HandleArchiveStage)4 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)3 URLClassLoader (java.net.URLClassLoader)3 HashSet (java.util.HashSet)3 BizClassLoader (com.alipay.sofa.ark.container.service.classloader.BizClassLoader)2 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)2 ExplodedBizArchive (com.alipay.sofa.ark.loader.ExplodedBizArchive)2 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)2 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)2 Plugin (com.alipay.sofa.ark.spi.model.Plugin)2 Attributes (java.util.jar.Attributes)2 ArkClient (com.alipay.sofa.ark.api.ArkClient)1 JarBizArchive (com.alipay.sofa.ark.loader.JarBizArchive)1