Search in sources :

Example 26 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class ClassLoaderServiceTest method testIsDeniedImportClass.

@Test
public void testIsDeniedImportClass() {
    Biz biz = new BizModel().setBizName("mockBiz").setBizVersion("1.0.0").setDenyImportPackages("a.c, a.b.c.*, a.b.c").setDenyImportClasses("").setBizState(BizState.RESOLVED);
    bizManagerService.registerBiz(biz);
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c.E"), "Exception error");
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.c.e.G"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c.E"), "Exception error");
    AssertUtils.isTrue(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c.e.G"), "Exception error");
    AssertUtils.isFalse(classloaderService.isDeniedImportClass(biz.getIdentity(), "a.b.c"), "Exception error");
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 27 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class HandleArchiveTest method testIncludeBiz.

@Test
public void testIncludeBiz() {
    try {
        HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
        System.setProperty(BIZ_ACTIVE_INCLUDE, "bizA:1.0.0");
        BizModel bizModel = new BizModel();
        bizModel.setBizName("bizA").setBizVersion("1.0.0");
        Assert.assertFalse(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("pluginB");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("pluginC");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
    } finally {
        System.clearProperty(BIZ_ACTIVE_INCLUDE);
    }
}
Also used : HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test)

Example 28 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class HandleArchiveTest method testExcludeBiz.

@Test
public void testExcludeBiz() {
    try {
        HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
        System.setProperty(BIZ_ACTIVE_EXCLUDE, "bizA:1.0.0,bizB:1.0.0");
        BizModel bizModel = new BizModel();
        bizModel.setBizName("bizA").setBizVersion("1.0.0");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("bizB");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("bizC");
        Assert.assertFalse(handleArchiveStage.isBizExcluded(bizModel));
    } finally {
        System.clearProperty(BIZ_ACTIVE_EXCLUDE);
    }
}
Also used : HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test)

Example 29 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class HandleArchiveTest method testNoIncludeExcludePlugin.

@Test
public void testNoIncludeExcludePlugin() {
    HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
    BizModel bizModel = new BizModel();
    bizModel.setBizName("bizA").setBizVersion("1.0.0");
    Assert.assertFalse(handleArchiveStage.isBizExcluded(bizModel));
    bizModel.setBizName("bizB");
    Assert.assertFalse(handleArchiveStage.isBizExcluded(bizModel));
}
Also used : HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test)

Example 30 with BizModel

use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.

the class BizFactoryServiceImpl method createBiz.

@Override
public Biz createBiz(File file) throws IOException {
    BizArchive bizArchive;
    if (ArkConfigs.isEmbedEnable()) {
        File unpackFile = new File(file.getAbsolutePath() + "-unpack");
        if (!unpackFile.exists()) {
            unpackFile = FileUtils.unzip(file, file.getAbsolutePath() + "-unpack");
        }
        if (file.exists()) {
            file.delete();
        }
        file = unpackFile;
        bizArchive = new ExplodedBizArchive(unpackFile);
    } else {
        JarFile bizFile = new JarFile(file);
        JarFileArchive jarFileArchive = new JarFileArchive(bizFile);
        bizArchive = new JarBizArchive(jarFileArchive);
    }
    BizModel biz = (BizModel) createBiz(bizArchive);
    biz.setBizTempWorkDir(file);
    return biz;
}
Also used : JarBizArchive(com.alipay.sofa.ark.loader.JarBizArchive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) ExplodedBizArchive(com.alipay.sofa.ark.loader.ExplodedBizArchive) BizModel(com.alipay.sofa.ark.container.model.BizModel) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) File(java.io.File) BizArchive(com.alipay.sofa.ark.spi.archive.BizArchive) JarBizArchive(com.alipay.sofa.ark.loader.JarBizArchive) ExplodedBizArchive(com.alipay.sofa.ark.loader.ExplodedBizArchive)

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