Skip to content

Commit cb07d25

Browse files
authored
Exception is thrown when component failed to register (#1361)
* Exception is thrown when component failed to register Signed-off-by: JermaineHua <[email protected]> * Fix testSofaServiceClassNotAssignableFromInterfaceType ut Signed-off-by: JermaineHua <[email protected]> * Fix testServiceBinding Signed-off-by: JermaineHua <[email protected]> * testBindingInstanceIsNotAssignableFromInterfaceType Signed-off-by: JermaineHua <[email protected]> --------- Signed-off-by: JermaineHua <[email protected]>
1 parent 3aab05e commit cb07d25

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private ComponentInfo doRegister(ComponentInfo ci) {
167167
ci.register();
168168
} catch (Throwable t) {
169169
SofaLogger.error(ErrorCode.convert("01-03003", ci.getName()), t);
170-
return null;
170+
throw new ServiceRuntimeException(ErrorCode.convert("01-03003", ci.getName()));
171171
}
172172

173173
SofaLogger.info("Registering component: {}", ci.getName());
@@ -189,6 +189,7 @@ private ComponentInfo doRegister(ComponentInfo ci) {
189189
} catch (Throwable t) {
190190
ci.exception(new Exception(t));
191191
SofaLogger.error(ErrorCode.convert("01-03004", ci.getName()), t);
192+
throw new ServiceRuntimeException(ErrorCode.convert("01-03004", ci.getName()));
192193
}
193194

194195
return ci;

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.AfterClass;
2525
import org.junit.Assert;
2626
import org.junit.Test;
27+
import org.springframework.beans.factory.BeanCreationException;
2728
import org.springframework.boot.SpringApplication;
2829
import org.springframework.boot.WebApplicationType;
2930
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -68,7 +69,8 @@ public void testSofaServiceClassNotAssignableFromInterfaceType() throws IOExcept
6869
TestSofaServiceNotAssignableFromInterfaceTypeConfiguration.class);
6970
springApplication.setWebApplicationType(WebApplicationType.NONE);
7071
springApplication.setDefaultProperties(properties);
71-
springApplication.run();
72+
73+
Assert.assertThrows(BeanCreationException.class, springApplication::run);
7274

7375
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
7476
Assert

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOExcep
134134
serviceParam.setInstance(new Object());
135135
serviceParam.setInterfaceType(SampleService.class);
136136
serviceParam.addBindingParam(jvmBindingParam);
137-
serviceClient.service(serviceParam);
137+
Assert.assertThrows(Exception.class, ()-> serviceClient.service(serviceParam));
138138

139139
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
140140
Assert

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public void testServiceBinding() throws IOException {
6666
SofaBindingTestIsNotAssignableFromInterfaceTypeConfiguration.class);
6767
springApplication.setWebApplicationType(WebApplicationType.NONE);
6868
springApplication.setDefaultProperties(properties);
69-
springApplication.run();
69+
70+
Assert.assertThrows(Exception.class, springApplication::run);
7071

7172
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
7273
Assert

0 commit comments

Comments
 (0)