diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java index 1030bf35406..dc3d253a937 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java @@ -31,7 +31,6 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.service.GenericService; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -40,6 +39,7 @@ import org.mockito.Mockito; import java.util.Collections; +import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_BEAN; import static org.apache.dubbo.common.Constants.GENERIC_SERIALIZATION_DEFAULT; @@ -52,6 +52,7 @@ import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.withSettings; public class ServiceConfigTest { @@ -60,7 +61,7 @@ public class ServiceConfigTest { private Exporter exporter = Mockito.mock(Exporter.class); private ServiceConfig service = new ServiceConfig(); private ServiceConfig service2 = new ServiceConfig(); - + private ServiceConfig delayService = new ServiceConfig(); @BeforeEach public void setUp() throws Exception { @@ -104,6 +105,14 @@ public void setUp() throws Exception { service2.setMethods(Collections.singletonList(method)); service2.setProxy("testproxyfactory"); + delayService.setProvider(provider); + delayService.setApplication(app); + delayService.setRegistry(registry); + delayService.setInterface(DemoService.class); + delayService.setRef(new DemoServiceImpl()); + delayService.setMethods(Collections.singletonList(method)); + delayService.setDelay(100); + ConfigManager.getInstance().clear(); } @@ -143,6 +152,16 @@ public void testProxy() throws Exception { assertEquals(2, TestProxyFactory.count); // local injvm and registry protocol, so expected is 2 } + + @Test + public void testDelayExport() throws Exception { + delayService.export(); + assertTrue(delayService.getExportedUrls().isEmpty()); + //add 300ms to ensure that the delayService has been exported + TimeUnit.MILLISECONDS.sleep(delayService.getDelay() + 300); + assertThat(delayService.getExportedUrls(), hasSize(1)); + } + @Test @Disabled("cannot pass in travis") public void testUnexport() throws Exception {