From 4f8b1394e254b5a0e2f948c08fe280f60256074d Mon Sep 17 00:00:00 2001 From: JermaineHua Date: Fri, 21 Mar 2025 12:31:12 +0800 Subject: [PATCH 1/4] Exception is thrown when component failed to register Signed-off-by: JermaineHua --- .../sofa/runtime/component/impl/ComponentManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java index 9dd8cf92e..d5c6ff90f 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java @@ -167,7 +167,7 @@ private ComponentInfo doRegister(ComponentInfo ci) { ci.register(); } catch (Throwable t) { SofaLogger.error(ErrorCode.convert("01-03003", ci.getName()), t); - return null; + throw new ServiceRuntimeException(ErrorCode.convert("01-03003", ci.getName())); } SofaLogger.info("Registering component: {}", ci.getName()); @@ -189,6 +189,7 @@ private ComponentInfo doRegister(ComponentInfo ci) { } catch (Throwable t) { ci.exception(new Exception(t)); SofaLogger.error(ErrorCode.convert("01-03004", ci.getName()), t); + throw new ServiceRuntimeException(ErrorCode.convert("01-03004", ci.getName())); } return ci; From 3a7ef41021547c31cce22827f59925cb486b8c99 Mon Sep 17 00:00:00 2001 From: JermaineHua Date: Wed, 9 Apr 2025 16:59:35 +0800 Subject: [PATCH 2/4] Fix testSofaServiceClassNotAssignableFromInterfaceType ut Signed-off-by: JermaineHua --- .../runtime/test/AnnotationSofaServiceTypeCheckFailTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java index 013d6fa86..ff7d28d62 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/AnnotationSofaServiceTypeCheckFailTest.java @@ -24,6 +24,7 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; +import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -68,7 +69,8 @@ public void testSofaServiceClassNotAssignableFromInterfaceType() throws IOExcept TestSofaServiceNotAssignableFromInterfaceTypeConfiguration.class); springApplication.setWebApplicationType(WebApplicationType.NONE); springApplication.setDefaultProperties(properties); - springApplication.run(); + + Assert.assertThrows(BeanCreationException.class, springApplication::run); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert From b0af3d1e473eed721b844e896444f1d8b3ffa08d Mon Sep 17 00:00:00 2001 From: JermaineHua Date: Wed, 9 Apr 2025 17:14:30 +0800 Subject: [PATCH 3/4] Fix testServiceBinding Signed-off-by: JermaineHua --- .../sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java index e3c6e9b3b..af69e62ba 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/XMLSofaServiceTypeCheckFailTest.java @@ -66,7 +66,8 @@ public void testServiceBinding() throws IOException { SofaBindingTestIsNotAssignableFromInterfaceTypeConfiguration.class); springApplication.setWebApplicationType(WebApplicationType.NONE); springApplication.setDefaultProperties(properties); - springApplication.run(); + + Assert.assertThrows(Exception.class, springApplication::run); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert From a4ea6b62439e6344a56f8a2edf4fdccc82323334 Mon Sep 17 00:00:00 2001 From: JermaineHua Date: Wed, 9 Apr 2025 17:24:47 +0800 Subject: [PATCH 4/4] testBindingInstanceIsNotAssignableFromInterfaceType Signed-off-by: JermaineHua --- .../java/com/alipay/sofa/runtime/test/ClientFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java index cc18cff3f..4a22fec90 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/ClientFactoryTest.java @@ -134,7 +134,7 @@ public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOExcep serviceParam.setInstance(new Object()); serviceParam.setInterfaceType(SampleService.class); serviceParam.addBindingParam(jvmBindingParam); - serviceClient.service(serviceParam); + Assert.assertThrows(Exception.class, ()-> serviceClient.service(serviceParam)); String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding")); Assert