Skip to content

Commit

Permalink
Add delay export test case (#3447)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiZhenNet authored and lixiaojiee committed Feb 12, 2019
1 parent 36c75d7 commit fa2316e
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fa2316e

Please sign in to comment.