Search in sources :

Example 11 with BizModel

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

the class EventAdminServiceTest method test.

@Test
public void test() throws Throwable {
    try {
        Field field = EventAdminServiceImpl.class.getDeclaredField("SUBSCRIBER_MAP");
        field.setAccessible(true);
        map = (Map) field.get(null);
    } catch (Throwable throwable) {
        Assert.assertNull(throwable);
    }
    EventAdminService eventAdminService = ArkServiceContainerHolder.getContainer().getService(EventAdminService.class);
    eventAdminService.register(new LowPriorityMockEventHandler());
    eventAdminService.register(new HighPriorityMockEventHandler());
    eventAdminService.register(new BeforeBizStopEventHandler());
    ClassLoader bizClassLoader = getClass().getClassLoader();
    Biz biz = new BizModel().setBizState(BizState.DEACTIVATED).setBizName("mock name").setBizVersion("mock name").setClassLoader(bizClassLoader);
    Assert.assertNotNull(map.get(bizClassLoader));
    biz.stop();
    Assert.assertNull(map.get(bizClassLoader));
    Assert.assertTrue(mark == 50);
    EventHandler eventHandler = new LowPriorityMockEventHandler();
    eventAdminService.register(eventHandler);
    Assert.assertNotNull(map.get(bizClassLoader));
    eventAdminService.unRegister(eventHandler);
    Assert.assertFalse(((Set) map.get(bizClassLoader)).contains(eventHandler));
}
Also used : Field(java.lang.reflect.Field) Biz(com.alipay.sofa.ark.spi.model.Biz) EventAdminService(com.alipay.sofa.ark.spi.service.event.EventAdminService) EventHandler(com.alipay.sofa.ark.spi.service.event.EventHandler) BizModel(com.alipay.sofa.ark.container.model.BizModel) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 12 with BizModel

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

the class GlobalEventHandlerTest method testEvent.

@Test
public void testEvent() {
    Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    Plugin plugin = new PluginModel().setPluginName("test-plugin").setVersion("1.0.0");
    eventAdminService.sendEvent(new AfterBizStartupEvent(biz));
    Assert.assertTrue(result.size() == 3);
    Assert.assertTrue(result.contains("AbstractArkEvent->AfterBizStartupEvent"));
    eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
    Assert.assertTrue(result.size() == 5);
    // test for ArkEvent.class.isAssignableFrom(event.getClass()
    eventAdminService.sendEvent(new ArkEvent() {

        @Override
        public String getTopic() {
            return "ark-event";
        }
    });
    Assert.assertTrue(result.size() == 7);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BeforePluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent) Biz(com.alipay.sofa.ark.spi.model.Biz) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) BizModel(com.alipay.sofa.ark.container.model.BizModel) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) AbstractArkEvent(com.alipay.sofa.ark.spi.event.AbstractArkEvent) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 13 with BizModel

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

the class BizManagerServiceImpl method activeBiz.

@Override
public void activeBiz(String bizName, String bizVersion) {
    AssertUtils.isFalse(StringUtils.isEmpty(bizName), "Biz name must not be empty.");
    AssertUtils.isFalse(StringUtils.isEmpty(bizVersion), "Biz version must not be empty.");
    Biz biz = getBiz(bizName, bizVersion);
    Biz activeBiz = getActiveBiz(bizName);
    if (biz != null && biz.getBizState() == BizState.DEACTIVATED) {
        if (activeBiz != null) {
            ((BizModel) activeBiz).setBizState(BizState.DEACTIVATED);
        }
        ((BizModel) biz).setBizState(BizState.ACTIVATED);
    }
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) BizModel(com.alipay.sofa.ark.container.model.BizModel)

Example 14 with BizModel

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

the class HandleArchiveTest method testIncludeExcludeBiz.

@Test
public void testIncludeExcludeBiz() {
    try {
        HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
        System.setProperty(BIZ_ACTIVE_INCLUDE, "bizA:1.0.0");
        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.assertFalse(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("bizB");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
        bizModel.setBizName("bizC");
        Assert.assertTrue(handleArchiveStage.isBizExcluded(bizModel));
    } finally {
        System.clearProperty(BIZ_ACTIVE_INCLUDE);
        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 15 with BizModel

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

the class BizClassloaderTest method testLoadClassFromAgentClassLoader.

@Test
public void testLoadClassFromAgentClassLoader() throws ClassNotFoundException {
    BizModel bizModel = new BizModel();
    bizModel.setBizName("MockBiz").setClassPath(new URL[] {}).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
    bizManagerService.registerBiz(bizModel);
    BizClassLoader bizClassLoader = (BizClassLoader) bizModel.getBizClassLoader();
    Assert.assertNotNull(bizClassLoader.loadClass("SampleClass", false));
}
Also used : BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

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