use of com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration in project sofa-boot by sofastack.
the class ApplicationRuntimeModelTest method test.
@Test
public void test() throws Exception {
// new ApplicationRuntimeModel Instance
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setAppName("testCase");
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
// new DeploymentDescriptorConfiguration instance
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
// add first SOFAIsle module
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.common");
URL jarUrl = new URL("jar:file:/whatever/path/demo.jar!/isle-module.config");
DeploymentDescriptor dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
// add second SOFAIsle module
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
URL fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
// test DeploymentDescriptor which misses Module-Name property
props = new Properties();
props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertFalse(application.isModuleDeployment(dd));
// missing com.alipay.util module
Assert.assertEquals(2, application.getDeployRegistry().getPendingEntries().size());
Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(0).getKey()));
Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(1).getKey()));
Assert.assertEquals(null, application.getDeployRegistry().getEntry("com.alipay.util").getWaitsFor());
Assert.assertEquals("com.alipay.util", application.getDeployRegistry().getEntry("com.alipay.dal").getWaitsFor().iterator().next().getKey());
// add missing module
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.util");
jarUrl = new URL("jar:file:/demo/path/demo.jar!/isle-module.config");
dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
Assert.assertEquals(0, application.getDeployRegistry().getPendingEntries().size());
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration 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.DeploymentDescriptorConfiguration 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.DeploymentDescriptorConfiguration in project sofa-boot by sofastack.
the class TestModelCreatingStage method getAllDeployments.
@Override
protected void getAllDeployments(ApplicationRuntimeModel application) throws IOException {
for (String prefix : modulePrefixes) {
Enumeration<URL> urls = appClassLoader.getResources(prefix + "/" + SofaBootConstants.SOFA_MODULE_FILE);
if (urls == null || !urls.hasMoreElements()) {
continue;
}
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
UrlResource urlResource = new UrlResource(url);
Properties props = new Properties();
props.load(urlResource.getInputStream());
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
DeploymentDescriptor dd = DeploymentBuilder.build(url, props, deploymentDescriptorConfiguration, appClassLoader);
if (application.isModuleDeployment(dd)) {
if (sofaModuleProfileChecker.acceptModule(dd)) {
application.addDeployment(dd);
} else {
application.addInactiveDeployment(dd);
}
}
}
}
}
use of com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration in project sofa-boot by alipay.
the class ApplicationRuntimeModelTest method test.
@Test
public void test() throws Exception {
// new ApplicationRuntimeModel Instance
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setAppName("testCase");
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
// new DeploymentDescriptorConfiguration instance
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
// add first SOFAIsle module
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.common");
URL jarUrl = new URL("jar:file:/whatever/path/demo.jar!/isle-module.config");
DeploymentDescriptor dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
// add second SOFAIsle module
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
URL fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
// test DeploymentDescriptor which misses Module-Name property
props = new Properties();
props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
fileUrl = new URL("file:/demo/path/isle-module.config");
dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertFalse(application.isModuleDeployment(dd));
// missing com.alipay.util module
Assert.assertEquals(2, application.getDeployRegistry().getPendingEntries().size());
Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(0).getKey()));
Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(1).getKey()));
Assert.assertEquals(null, application.getDeployRegistry().getEntry("com.alipay.util").getWaitsFor());
Assert.assertEquals("com.alipay.util", application.getDeployRegistry().getEntry("com.alipay.dal").getWaitsFor().iterator().next().getKey());
// add missing module
props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.util");
jarUrl = new URL("jar:file:/demo/path/demo.jar!/isle-module.config");
dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
Assert.assertEquals(0, application.getDeployRegistry().getPendingEntries().size());
}
Aggregations