Skip to content

Commit

Permalink
Merge pull request #1 from HzjNeverStop/support_mock
Browse files Browse the repository at this point in the history
Major refactor and improvements
  • Loading branch information
Peng-YM authored Aug 25, 2023
2 parents 4a30116 + 4e18845 commit 7428693
Show file tree
Hide file tree
Showing 90 changed files with 4,303 additions and 2,120 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<properties>
<revision>4.1.0-SNAPSHOT</revision>
<sofa.boot.version>${revision}</sofa.boot.version>
<spring.boot.version>3.0.7</spring.boot.version>
<spring.boot.version>3.1.2</spring.boot.version>
<!--project-->
<java.version>17</java.version>
<project.encoding>UTF-8</project.encoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

Expand All @@ -54,7 +53,7 @@ public class ReadinessAutoConfiguration {
.getLogger(ReadinessAutoConfiguration.class);

@Bean
@ConditionalOnMissingBean(value = ReadinessCheckListener.class, search = SearchStrategy.CURRENT)
@ConditionalOnMissingBean(value = ReadinessCheckListener.class)
public ReadinessCheckListener readinessCheckListener(HealthCheckerProcessor healthCheckerProcessor,
HealthIndicatorProcessor healthIndicatorProcessor,
ReadinessCheckCallbackProcessor afterReadinessCheckCallbackProcessor,
Expand Down
11 changes: 0 additions & 11 deletions sofa-boot-project/sofa-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,6 @@
<artifactId>hessian</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>test-sofa-boot</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public class SofaRuntimeProperties {
*/
private boolean referenceHealthCheckMoreDetailEnable;

/**
* Whether support register duplicate service component.
*/
private boolean serviceCanBeDuplicate = true;

public boolean isSkipJvmReferenceHealthCheck() {
return skipJvmReferenceHealthCheck;
}
Expand Down Expand Up @@ -187,4 +192,12 @@ public boolean isReferenceHealthCheckMoreDetailEnable() {
public void setReferenceHealthCheckMoreDetailEnable(boolean referenceHealthCheckMoreDetailEnable) {
this.referenceHealthCheckMoreDetailEnable = referenceHealthCheckMoreDetailEnable;
}

public boolean isServiceCanBeDuplicate() {
return serviceCanBeDuplicate;

Check warning on line 197 in sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeProperties.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeProperties.java#L197

Added line #L197 was not covered by tests
}

public void setServiceCanBeDuplicate(boolean serviceCanBeDuplicate) {
this.serviceCanBeDuplicate = serviceCanBeDuplicate;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# AutoConfigurationImportListener
org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
com.alipay.sofa.boot.autoconfigure.detect.LegacyAutoConfigurationDetectListener

# Add TestExecutionListener
org.springframework.test.context.TestExecutionListener=com.alipay.sofa.test.SofaBootTestExecutionListener
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ com.alipay.sofa.boot.autoconfigure.tracer.mongo.MongoAutoConfiguration
com.alipay.sofa.boot.autoconfigure.tracer.flexible.FlexibleAutoConfiguration
com.alipay.sofa.boot.autoconfigure.tracer.springmvc.OpenTracingSpringMvcAutoConfiguration
com.alipay.sofa.boot.autoconfigure.tracer.feign.FeignClientAutoConfiguration
com.alipay.sofa.boot.autoconfigure.ark.SofaArkAutoConfiguration
com.alipay.sofa.boot.autoconfigure.test.SofaTestAutoConfiguration
com.alipay.sofa.boot.autoconfigure.ark.SofaArkAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void customSofaRuntimeContextProperties() {
.withPropertyValues("sofa.boot.runtime.serviceInterfaceTypeCheck=true")
.withPropertyValues("sofa.boot.runtime.skipJvmReferenceHealthCheckList=com.alipay.sofa.isle.sample.facade.SampleJvmService:annotationImpl,com.alipay.sofa.isle.sample.facade.SampleJvmService")
.withPropertyValues("sofa.boot.runtime.referenceHealthCheckMoreDetailEnable=true")
.withPropertyValues("sofa.boot.runtime.serviceCanBeDuplicate=false")
.run((context) -> {
SofaRuntimeContext.Properties properties= context.getBean(SofaRuntimeContext.class).getProperties();
assertThat(properties.isSkipJvmReferenceHealthCheck()).isTrue();
Expand All @@ -108,6 +109,7 @@ public void customSofaRuntimeContextProperties() {
assertThat(properties.isServiceInterfaceTypeCheck()).isTrue();
assertThat(properties.getSkipJvmReferenceHealthCheckList()).containsExactly("com.alipay.sofa.isle.sample.facade.SampleJvmService:annotationImpl", "com.alipay.sofa.isle.sample.facade.SampleJvmService");
assertThat(properties.isReferenceHealthCheckMoreDetailEnable()).isTrue();
assertThat(properties.isServiceCanBeDuplicate()).isFalse();
});
}

Expand Down
7 changes: 0 additions & 7 deletions sofa-boot-project/sofa-boot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class ServiceComponent extends AbstractComponent {

private final Map<String, Property> properties = new ConcurrentHashMap<>();

private final boolean canBeDuplicate;

public ServiceComponent(Implementation implementation, Service service,
BindingAdapterFactory bindingAdapterFactory,
SofaRuntimeContext sofaRuntimeContext) {
Expand All @@ -67,6 +69,7 @@ public ServiceComponent(Implementation implementation, Service service,
this.service = service;
this.bindingAdapterFactory = bindingAdapterFactory;
this.sofaRuntimeContext = sofaRuntimeContext;
this.canBeDuplicate = sofaRuntimeContext.getProperties().isServiceCanBeDuplicate();
}

@Override
Expand Down Expand Up @@ -322,4 +325,9 @@ public HealthResult isHealthy() {
healthResult.setHealthReport(report);
return healthResult;
}

@Override
public boolean canBeDuplicate() {
return this.canBeDuplicate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static class Properties {
private boolean serviceInterfaceTypeCheck = false;
private List<String> skipJvmReferenceHealthCheckList = new ArrayList<>();
private boolean referenceHealthCheckMoreDetailEnable = false;
private boolean serviceCanBeDuplicate = true;

public boolean isSkipJvmReferenceHealthCheck() {
return skipJvmReferenceHealthCheck;
Expand Down Expand Up @@ -183,5 +184,13 @@ public boolean isReferenceHealthCheckMoreDetailEnable() {
public void setReferenceHealthCheckMoreDetailEnable(boolean referenceHealthCheckMoreDetailEnable) {
this.referenceHealthCheckMoreDetailEnable = referenceHealthCheckMoreDetailEnable;
}

public boolean isServiceCanBeDuplicate() {
return serviceCanBeDuplicate;
}

public void setServiceCanBeDuplicate(boolean serviceCanBeDuplicate) {
this.serviceCanBeDuplicate = serviceCanBeDuplicate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@
@ExtendWith(MockitoExtension.class)
public class ServiceComponentTests {

private Service service;
private Service service;

private ServiceComponent serviceComponent;
private ServiceComponent serviceComponent;

@Mock
private Implementation implementation;
private Implementation implementation;

@Mock
private BindingAdapterFactory bindingAdapterFactory;
private BindingAdapterFactory bindingAdapterFactory;

@Mock
private SofaRuntimeContext sofaRuntimeContext;
private SofaRuntimeContext sofaRuntimeContext;

private SofaRuntimeContext.Properties properties;

@BeforeEach
public void setUp() {
service = new ServiceImpl("", SampleService.class, new SampleServiceImpl());
properties = new SofaRuntimeContext.Properties();
when(sofaRuntimeContext.getProperties()).thenReturn(properties);
serviceComponent = new ServiceComponent(implementation, service, bindingAdapterFactory,
sofaRuntimeContext);
}
Expand Down Expand Up @@ -310,6 +314,14 @@ void healthSuccessWhenHaveException() {
assertThat(healthResult.getHealthReport()).isEqualTo("[jvm,passed] [error]");
}

@Test
void canBeDuplicate() {
properties.setServiceCanBeDuplicate(true);
serviceComponent = new ServiceComponent(implementation, service, bindingAdapterFactory,
sofaRuntimeContext);
assertThat(serviceComponent.canBeDuplicate()).isTrue();
}

static class SampleServiceImpl implements SampleService {

@Override
Expand Down
10 changes: 2 additions & 8 deletions sofa-boot-project/sofa-boot-core/test-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>runtime-sofa-boot</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>isle-sofa-boot</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit 7428693

Please sign in to comment.