use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.
the class BeanHierarchyTest method test.
@Test
public void test() throws Exception {
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setAppName(this.getClass().getName());
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.module");
File moduleDirectory = new File("target/test-classes/module/sofa-module.properties");
DeploymentDescriptor dd = DeploymentBuilder.build(moduleDirectory.toURI().toURL(), props, deploymentDescriptorConfiguration, this.getClass().getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
refreshApplication(application);
BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
for (BeanStat bn : ((BeanLoadCostBeanFactory) beanFactory).getBeanStats()) {
if (bn.getBeanClassName().contains("testService")) {
Assert.assertEquals(3, bn.getChildren().size());
for (BeanStat cbn : bn.getChildren()) {
if (cbn.getChildren().size() > 1) {
Assert.assertEquals(3, cbn.getChildren().size());
}
}
}
}
ApplicationContext applicationContext = application.getResolvedDeployments().get(0).getApplicationContext();
String moduleName = applicationContext.getId();
Assert.assertEquals("com.alipay.module", moduleName);
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.
the class FailModuleTest method test.
@Test
public void test() {
ApplicationRuntimeModel applicationRuntimeModel = (ApplicationRuntimeModel) applicationContext.getBean(SofaBootConstants.APPLICATION);
// contains three Deployments
Assert.assertEquals(3, applicationRuntimeModel.getAllDeployments().size());
Assert.assertEquals(2, applicationRuntimeModel.getInstalled().size());
Assert.assertEquals(1, applicationRuntimeModel.getFailed().size());
// check module not in installed list
DeploymentDescriptor failModule = applicationRuntimeModel.getFailed().get(0);
Assert.assertEquals("com.alipay.sofa.fail", failModule.getModuleName());
Assert.assertFalse(applicationRuntimeModel.getInstalled().contains(failModule));
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.
the class FailModuleWithParallelTest method test.
@Test
public void test() {
ApplicationRuntimeModel applicationRuntimeModel = (ApplicationRuntimeModel) applicationContext.getBean(SofaBootConstants.APPLICATION);
// contains three Deployments
Assert.assertEquals(3, applicationRuntimeModel.getAllDeployments().size());
Assert.assertEquals(2, applicationRuntimeModel.getInstalled().size());
Assert.assertEquals(1, applicationRuntimeModel.getFailed().size());
// check module not in installed list
DeploymentDescriptor failModule = applicationRuntimeModel.getFailed().get(0);
Assert.assertEquals("com.alipay.sofa.fail", failModule.getModuleName());
Assert.assertFalse(applicationRuntimeModel.getInstalled().contains(failModule));
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.
the class SofaModuleProfileCheckerTest method test.
@Test
public void test() throws Exception {
// new DeploymentDescriptorConfiguration instance
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
// test dev profile
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.MODULE_PROFILE, "dev");
URL fileUrl = new URL("file:/demo/path/isle-module.config");
DeploymentDescriptor dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
// test product profile
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.MODULE_PROFILE, "product");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
// test !dev profile
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.MODULE_PROFILE, "!dev");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertFalse(sofaModuleProfileChecker.acceptModule(dd));
// test test,grey profile
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.MODULE_PROFILE, "dev,grey");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
// test test,grey profile
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.MODULE_PROFILE, "test,grey");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertFalse(sofaModuleProfileChecker.acceptModule(dd));
// test no profile, default pass
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.
the class ModuleHealthChecker method isHealthy.
@Override
public Health isHealthy() {
Health.Builder builder = new Health.Builder();
ApplicationRuntimeModel application = applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class);
for (DeploymentDescriptor deploymentDescriptor : application.getInstalled()) {
builder.withDetail(deploymentDescriptor.getName(), "passed");
}
for (DeploymentDescriptor deploymentDescriptor : application.getAllInactiveDeployments()) {
builder.withDetail(deploymentDescriptor.getName(), "inactive");
}
for (DeploymentDescriptor deploymentDescriptor : application.getFailed()) {
builder.withDetail(deploymentDescriptor.getName(), "failed");
}
if (application.getFailed().size() == 0) {
return builder.status(Status.UP).build();
} else {
return builder.status(Status.DOWN).build();
}
}
Aggregations