use of com.alipay.sofa.ark.spi.model.Biz 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.spi.model.Biz 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);
}
use of com.alipay.sofa.ark.spi.model.Biz in project sofa-ark by alipay.
the class BizManagerServiceTest method testRegisterBiz.
@Test
public void testRegisterBiz() {
Biz ret = bizManagerService.getBiz("test-biz", "1.0.0");
Assert.assertNotNull(ret);
}
use of com.alipay.sofa.ark.spi.model.Biz 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.spi.model.Biz 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);
}
Aggregations