Add delay export test case (#3447)
authorLiZhen <LiZhenNet@users.noreply.github.com>
Tue, 12 Feb 2019 08:16:16 +0000 (16:16 +0800)
committerXiaoJie Li <lixiaojie@apache.org>
Tue, 12 Feb 2019 08:16:16 +0000 (16:16 +0800)
dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java

index 1030bf3..dc3d253 100644 (file)
@@ -31,7 +31,6 @@ import org.apache.dubbo.rpc.Exporter;
 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.junit.jupiter.api.Test;
 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.hasEntry;
 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<DemoServiceImpl> service = new ServiceConfig<DemoServiceImpl>();
     private ServiceConfig<DemoServiceImpl> service2 = new ServiceConfig<DemoServiceImpl>();
-
+    private ServiceConfig<DemoServiceImpl> delayService = new ServiceConfig<DemoServiceImpl>();
 
     @BeforeEach
     public void setUp() throws Exception {
@@ -104,6 +105,14 @@ public class ServiceConfigTest {
         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 class ServiceConfigTest {
         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 {