8000 Add isle module uts by HzjNeverStop · Pull Request #1154 · sofastack/sofa-boot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add isle module uts #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ public void loadSpringContext(DeploymentDescriptor deployment,
SofaDefaultListableBeanFactory beanFactory = SofaSpringContextSupport.createBeanFactory(classLoader, this::createBeanFactory);

SofaGenericApplicationContext context = SofaSpringContextSupport.createApplicationContext(beanFactory, this::createApplicationContext);
BufferingApplicationStartup bufferingApplicationStartup = new BufferingApplicationStartup(startupReporter.getBufferSize());
context.setApplicationStartup(bufferingApplicationStartup);
if (startupReporter != null) {
BufferingApplicationStartup bufferingApplicationStartup = new BufferingApplicationStartup(startupReporter.getBufferSize());
context.setApplicationStartup(bufferingApplicationStartup);
}

context.setId(deployment.getModuleName());
if (!CollectionUtils.isEmpty(activeProfiles)) {
Expand Down Expand Up @@ -155,24 +157,28 @@ protected ConfigurableApplicationContext getSpringParentContext(DeploymentDescri

protected void loadBeanDefinitions(DeploymentDescriptor deployment,
BeanDefinitionReader beanDefinitionReader) {
for (Map.Entry<String, Resource> entry : deployment.getSpringResources().entrySet()) {
String fileName = entry.getKey();
beanDefinitionReader.loadBeanDefinitions(entry.getValue());
deployment.addInstalledSpringXml(fileName);
if (deployment.getSpringResources() != null) {
for (Map.Entry<String, Resource> entry : deployment.getSpringResources().entrySet()) {
String fileName = entry.getKey();
beanDefinitionReader.loadBeanDefinitions(entry.getValue());
deployment.addInstalledSpringXml(fileName);
}
}
}

protected void addPostProcessors(SofaDefaultListableBeanFactory beanFactory) {
sofaPostProcessorShareManager.getRegisterSingletonMap().forEach((beanName, singletonObject) -> {
if (!beanFactory.containsBeanDefinition(beanName)) {
beanFactory.registerSingleton(beanName, singletonObject);
}
});
sofaPostProcessorShareManager.getRegisterBeanDefinitionMap().forEach((beanName, beanDefinition) -> {
if (!beanFactory.containsBeanDefinition(beanName)) {
beanFactory.registerBeanDefinition(beanName, beanDefinition);
}
});
if (sofaPostProcessorShareManager != null) {
sofaPostProcessorShareManager.getRegisterSingletonMap().forEach((beanName, singletonObject) -> {
if (!beanFactory.containsBeanDefinition(beanName)) {
beanFactory.registerSingleton(beanName, singletonObject);
}
});
sofaPostProcessorShareManager.getRegisterBeanDefinitionMap().forEach((beanName, beanDefinition) -> {
if (!beanFactory.containsBeanDefinition(beanName)) {
beanFactory.registerBeanDefinition(beanName, beanDefinition);
}
});
}
}

public boolean isAllowBeanOverriding() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void start() {
pipelineContext.process();
} catch (Throwable t) {
LOGGER.error(ErrorCode.convert("01-10000"), t);
throw new RuntimeException(t);
throw new RuntimeException(ErrorCode.convert("01-10000"), t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void doProcess() throws Exception {
logFailedModules();
}

private void logInstalledModules() {
protected void logInstalledModules() {
List<DeploymentDescriptor> deploys = application.getInstalled();
StringBuilder stringBuilder = new StringBuilder();
long totalTime = 0;
Expand Down Expand Up @@ -100,7 +100,7 @@ private void logInstalledModules() {
LOGGER.info(stringBuilder.toString());
}

private void logFailedModules() {
protected void logFailedModules() {
List<DeploymentDescriptor> deploys = application.getFailed();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("\n").append("Spring context initialize failed module list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@
*/
public class SpringContextInstallStage extends AbstractPipelineStage implements InitializingBean {

private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(SpringContextInstallStage.class);
private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(SpringContextInstallStage.class);

public static final String SOFA_MODULE_REFRESH_EXECUTOR_BEAN_NAME = "sofaModuleRefreshExecutor";
public static final String SOFA_MODULE_REFRESH_EXECUTOR_BEAN_NAME = "sofaModuleRefreshExecutor";

public static final String SPRING_CONTEXT_INSTALL_STAGE_NAME = "SpringContextInstallStage";
public static final String SPRING_CONTEXT_INSTALL_STAGE_NAME = "SpringContextInstallStage";

private SpringContextLoader springContextLoader;
protected SpringContextLoader springContextLoader;

private boolean moduleStartUpParallel;
protected boolean moduleStartUpParallel;

private boolean ignoreModuleInstallFailure;
protected boolean ignoreModuleInstallFailure;

private ExecutorService moduleRefreshExecutorService;
protected ExecutorService moduleRefreshExecutorService;

@Override
public void afterPropertiesSet() throws Exception {
Expand Down Expand Up @@ -227,8 +227,10 @@ protected void refreshAndCollectCost(DeploymentDescriptor deployment) {
moduleStat.setThreadName(Thread.currentThread().getName());
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) deployment
.getApplicationContext();
moduleStat.setChildren(startupReporter.generateBeanStats(ctx));
((ChildrenStat<ModuleStat>) baseStat).addChild(moduleStat);
if (startupReporter != null && baseStat != null) {
moduleStat.setChildren(startupReporter.generateBeanStats(ctx));
((ChildrenStat<ModuleStat>) baseStat).addChild(moduleStat);
}
}

protected void doRefreshSpringContext(DeploymentDescriptor deployment) {
Expand Down Expand Up @@ -257,10 +259,6 @@ private void throwModuleInstallFailure() throws DeploymentException {
throw new DeploymentException(ErrorCode.convert("01-11007", failedModuleNames));
}

public SpringContextLoader getSpringContextLoader() {
return springContextLoader;
}

public void setSpringContextLoader(SpringContextLoader springContextLoader) {
this.springContextLoader = springContextLoader;
}
Expand All @@ -281,14 +279,6 @@ public void setModuleStartUpParallel(boolean moduleStartUpParallel) {
this.moduleStartUpParallel = moduleStartUpParallel;
}

public ExecutorService getModuleRefreshExecutorService() {
return moduleRefreshExecutorService;
}

public void setModuleRefreshExecutorService(ExecutorService moduleRefreshExecutorService) {
this.moduleRefreshExecutorService = moduleRefreshExecutorService;
}

@Override
public String getName() {
return SPRING_CONTEXT_INSTALL_STAGE_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alipay.sofa.boot.isle.deployment.DeploymentDescriptorConfiguration;
import com.alipay.sofa.boot.isle.deployment.DeploymentDescriptorFactory;
import com.alipay.sofa.boot.isle.deployment.FileDeploymentDescriptor;
import com.alipay.sofa.boot.isle.profile.DefaultSofaModuleProfileChecker;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -60,6 +61,9 @@ public void addSofaModule() throws Exception {
// new ApplicationRuntimeModel Instance
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
DefaultSofaModuleProfileChecker checker = new DefaultSofaModuleProfileChecker();
application.setSofaModuleProfileChecker(checker);
assertThat(application.getSofaModuleProfileChecker()).isEqualTo(checker);

// add first SOFAIsle module
Properties props = new Properties();
Expand Down Expand Up @@ -103,7 +107,9 @@ public void addSofaModule() throws Exception {
public void addMissModuleNameModule() throws Exception {
// new ApplicationRuntimeModel Instance
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
DefaultModuleDeploymentValidator validator = new DefaultModuleDeploymentValidator();
application.setModuleDeploymentValidator(validator);
assertThat(application.getModuleDeploymentValidator()).isEqualTo(validator);

//DeploymentDescriptor which misses Module-Name property
Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.boot.isle;

import com.alipay.sofa.boot.isle.deployment.DeploymentDescriptor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author huzijie
* @version MockDeploymentDescriptor.java, v 0.1 2023年04月07日 11:28 AM huzijie Exp $
*/
public class MockDeploymentDescriptor implements DeploymentDescriptor {

private final String name;

private ApplicationContext applicationContext;

private final List<String> requireModules = new ArrayList<>();

private String springParent;

private Map<String, Resource> springResources;
private List<String> installedSpringXml;

public MockDeploymentDescriptor(String name) {
this.name = name;
}

public void addRequiredModule(String name) {
requireModules.add(name);
}

public void setSpringParent(String springParent) {
this.springParent = springParent;
}

public void setSpringResources(Map<String, Resource> springResources) {
this.springResources = springResources;
}

@Override
public String getModuleName() {
return name;
}

@Override
public String getName() {
return name;
}

@Override
public List<String> getRequiredModules() {
return requireModules;
}

@Override
public String getProperty(String key) {
return null;
}

@Override
public String getSpringParent() {
return springParent;
}

@Override
public ClassLoader getClassLoader() {
return null;
}

@Override
public void setApplicationContext(ApplicationContext context) {
this.applicationContext = context;
}

@Override
public ApplicationContext getApplicationContext() {
return applicationContext;
}

@Override
public void addInstalledSpringXml(String fileName) {
if (installedSpringXml == null) {
installedSpringXml = new ArrayList<>();
}
installedSpringXml.add(fileName);
}

@Override
public List<String> getInstalledSpringXml() {
return installedSpringXml;
}

@Override
public boolean isSpringPowered() {
return false;
}

@Override
public void startDeploy() {

}

@Override
public void deployFinish() {

}

@Override
public Map<String, Resource> getSpringResources() {
return springResources;
}

@Override
public long getElapsedTime() {
return 0;
}

@Override
public long getStartTime() {
return 0;
}

@Override
public void setIgnoreRequireModule(boolean ignoreRequireModule) {

}

@Override
public int compareTo(DeploymentDescriptor o) {
return o.getName().compareTo(this.getName());
}
}
Loading
0