Search in sources :

Example 11 with Biz

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);
}
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 12 with Biz

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

Example 13 with Biz

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

Example 14 with Biz

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));
}
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 15 with Biz

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

Aggregations

Biz (com.alipay.sofa.ark.spi.model.Biz)38 Test (org.junit.Test)14 BaseTest (com.alipay.sofa.ark.container.BaseTest)13 BizModel (com.alipay.sofa.ark.container.model.BizModel)12 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)6 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)6 Plugin (com.alipay.sofa.ark.spi.model.Plugin)5 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)3 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)2 ExecutableArchive (com.alipay.sofa.ark.spi.archive.ExecutableArchive)2 PluginArchive (com.alipay.sofa.ark.spi.archive.PluginArchive)2 AfterBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizSwitchEvent)2 BeforeBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent)2 BeforeBizSwitchEvent (com.alipay.sofa.ark.spi.event.biz.BeforeBizSwitchEvent)2 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)2 EventAdminService (com.alipay.sofa.ark.spi.service.event.EventAdminService)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 MainMethodRunner (com.alipay.sofa.ark.bootstrap.MainMethodRunner)1 OrderComparator (com.alipay.sofa.ark.common.util.OrderComparator)1