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));
}
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);
}
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);
}
}
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);
}
}
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));
}
Aggregations