Skip to content

Commit

Permalink
try fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjing2 committed Sep 13, 2024
1 parent 2d0e5ae commit da02a9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@ public class ArkTomcatServletWebServerFactory extends TomcatServletWebServerFact
public WebServer getWebServer(ServletContextInitializer... initializers) {
ArkLoggerFactory.getDefaultLogger().info("getWebServer EmbededServerService is {}",
embeddedServerService);
System.out.println(String.format("getWebServer EmbededServerService is %s",
embeddedServerService));
if (embeddedServerService == null && ArkClient.getInjectionService() != null) {
// 非应用上下文 (例如: Spring Management Context) 没有经历 Start 生命周期, 不会被注入 ArkServiceInjectProcessor,
// 因此 @ArkInject 没有被处理, 需要手动处理
ArkClient.getInjectionService().inject(this);
}
System.out.println(String.format("getWebServer EmbededServerService is %s",
embeddedServerService));
if (embeddedServerService == null) {
// 原有的逻辑中也有这个空值判断, 不确定注入后是否还会有用例会导致 embeddedServerService 为空
// 因此仍保留此 if 空值判断
return super.getWebServer(initializers);
}
System.out.println(String.format("getWebServer EmbededServerService is %s",
embeddedServerService));
if (embeddedServerService.getEmbedServer(getPort()) == null) {
synchronized (lock) {
if (embeddedServerService.getEmbedServer(getPort()) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
*/
package com.alipay.sofa.ark.springboot.web;

import com.alipay.sofa.ark.api.ArkClient;
import com.alipay.sofa.ark.container.model.BizModel;
import com.alipay.sofa.ark.container.service.ArkServiceContainer;
import com.alipay.sofa.ark.container.service.ArkServiceContainerHolder;
import com.alipay.sofa.ark.container.service.biz.BizManagerServiceImpl;
import com.alipay.sofa.ark.spi.service.registry.RegistryService;
import com.alipay.sofa.ark.spi.service.injection.InjectionService;
import com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory.StaticResourceConfigurer;
import com.google.inject.Injector;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.core.StandardContext;
Expand Down Expand Up @@ -51,23 +49,18 @@ public class ArkTomcatServletWebServerFactoryTest {
private ArkTomcatServletWebServerFactory arkTomcatServletWebServerFactory = new ArkTomcatServletWebServerFactory();

private ClassLoader currentThreadContextClassLoader;
private InjectionService injectionService;

@Before
public void setUp() throws Exception {

ArkServiceContainer arkServiceContainer = ArkServiceContainerHolder.getContainer();
if (arkServiceContainer != null) {
Field field = ArkServiceContainer.class.getDeclaredField("injector");
field.setAccessible(true);
Injector injector = (Injector) field.get(arkServiceContainer);
arkServiceContainer.getService(RegistryService.class).unPublishServices(all -> true);
injector.getAllBindings().clear();
}
public void setUp() {
injectionService = ArkClient.getInjectionService();
ArkClient.setInjectionService(null);
currentThreadContextClassLoader = currentThread().getContextClassLoader();
}

@After
public void tearDown() {
ArkClient.setInjectionService(injectionService);
currentThread().setContextClassLoader(currentThreadContextClassLoader);
}

Expand Down

0 comments on commit da02a9e

Please sign in to comment.