use of com.alipay.sofa.ark.spi.event.ArkEvent in project sofa-ark by alipay.
the class ArkBootRunnerTest method test.
@Test
public void test() {
Assert.assertNotNull(sampleService);
Assert.assertNotNull(pluginManagerService);
Assert.assertTrue("SampleService".equals(sampleService.say()));
ArkBootRunner runner = new ArkBootRunner(ArkBootRunnerTest.class);
Field field = ReflectionUtils.findField(ArkBootRunner.class, "runner");
Assert.assertNotNull(field);
ReflectionUtils.makeAccessible(field);
BlockJUnit4ClassRunner springRunner = (BlockJUnit4ClassRunner) ReflectionUtils.getField(field, runner);
Assert.assertTrue(springRunner.getClass().getCanonicalName().equals(SpringRunner.class.getCanonicalName()));
ClassLoader loader = springRunner.getTestClass().getJavaClass().getClassLoader();
Assert.assertTrue(loader.getClass().getCanonicalName().equals(TestClassLoader.class.getCanonicalName()));
Assert.assertEquals(0, TestValueHolder.getTestValue());
eventAdminService.sendEvent(new ArkEvent() {
@Override
public String getTopic() {
return "test-event-A";
}
});
Assert.assertEquals(10, TestValueHolder.getTestValue());
eventAdminService.sendEvent(new ArkEvent() {
@Override
public String getTopic() {
return "test-event-B";
}
});
Assert.assertEquals(20, TestValueHolder.getTestValue());
}
use of com.alipay.sofa.ark.spi.event.ArkEvent 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.spi.event.ArkEvent in project sofa-ark by alipay.
the class ArkClientTest method testBizArguments.
@Test
public void testBizArguments() throws Throwable {
EventAdminService eventAdminService = arkServiceContainer.getService(EventAdminService.class);
List<String> topicList = new ArrayList<>();
EventHandler eventHandler = new EventHandler<ArkEvent>() {
@Override
public void handleEvent(ArkEvent event) {
topicList.add(event.getTopic());
}
@Override
public int getPriority() {
return 0;
}
};
eventAdminService.register(eventHandler);
File bizFile3 = ArkClient.createBizSaveFile("biz-demo", "3.0.0");
FileUtils.copyInputStreamToFile(bizUrl3.openStream(), bizFile3);
ArkClient.installBiz(bizFile3);
// ArkClient.installBiz(new File(bizUrl3.getFile()));
ArkClient.uninstallBiz("biz-demo", "3.0.0");
File bizFile33 = ArkClient.createBizSaveFile("biz-demo", "3.0.0");
FileUtils.copyInputStreamToFile(bizUrl3.openStream(), bizFile33);
ArkClient.installBiz(bizFile33, new String[] { "demo" });
ArkClient.uninstallBiz("biz-demo", "3.0.0");
Assert.assertEquals("BEFORE-INVOKE-BIZ-START", topicList.get(0));
Assert.assertEquals("No arguments", topicList.get(1));
Assert.assertEquals("AFTER-INVOKE-BIZ-START", topicList.get(2));
// new event
Assert.assertEquals("BEFORE-RECYCLE-BIZ", topicList.get(4));
Assert.assertEquals("demo", topicList.get(7));
}
Aggregations