Search in sources :

Example 1 with DemoServiceImpl

use of org.apache.dubbo.config.provider.impl.DemoServiceImpl in project dubbo by alibaba.

the class ReferenceConfigTest method testInjvm.

@Test
@Disabled("Disabled due to Github Actions environment")
public void testInjvm() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("test-protocol-random-port");
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress(registryUrl);
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    ServiceConfig<DemoService> demoService;
    demoService = new ServiceConfig<DemoService>();
    demoService.setInterface(DemoService.class);
    demoService.setRef(new DemoServiceImpl());
    demoService.setApplication(application);
    demoService.setRegistry(registry);
    demoService.setProtocol(protocol);
    ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
    rc.setApplication(application);
    rc.setRegistry(registry);
    rc.setInterface(DemoService.class.getName());
    rc.setScope(SCOPE_REMOTE);
    try {
        System.setProperty("java.net.preferIPv4Stack", "true");
        demoService.export();
        rc.get();
        Assertions.assertTrue(!LOCAL_PROTOCOL.equalsIgnoreCase(rc.getInvoker().getUrl().getProtocol()));
    } finally {
        System.clearProperty("java.net.preferIPv4Stack");
        rc.destroy();
        demoService.unexport();
    }
    // Manually trigger dubbo resource recycling.
    DubboBootstrap.getInstance().destroy();
}
Also used : DemoService(org.apache.dubbo.config.api.DemoService) DemoServiceImpl(org.apache.dubbo.config.provider.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with DemoServiceImpl

use of org.apache.dubbo.config.provider.impl.DemoServiceImpl in project dubbo by alibaba.

the class ServiceConfigTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    MockProtocol2.delegate = protocolDelegate;
    MockRegistryFactory2.registry = registryDelegate;
    Mockito.when(protocolDelegate.export(Mockito.any(Invoker.class))).thenReturn(exporter);
    ApplicationConfig app = new ApplicationConfig("app");
    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setName("mockprotocol2");
    ProviderConfig provider = new ProviderConfig();
    provider.setExport(true);
    provider.setProtocol(protocolConfig);
    RegistryConfig registry = new RegistryConfig();
    registry.setProtocol("mockprotocol2");
    registry.setAddress("N/A");
    ArgumentConfig argument = new ArgumentConfig();
    argument.setIndex(0);
    argument.setCallback(false);
    MethodConfig method = new MethodConfig();
    method.setName("echo");
    method.setArguments(Collections.singletonList(argument));
    service.setProvider(provider);
    service.setApplication(app);
    service.setRegistry(registry);
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.setMethods(Collections.singletonList(method));
    service2.setProvider(provider);
    service2.setApplication(app);
    service2.setRegistry(registry);
    service2.setInterface(DemoService.class);
    service2.setRef(new DemoServiceImpl());
    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);
// ApplicationModel.getConfigManager().clear();
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) DemoServiceImpl(org.apache.dubbo.config.provider.impl.DemoServiceImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with DemoServiceImpl

use of org.apache.dubbo.config.provider.impl.DemoServiceImpl in project dubbo by apache.

the class ReferenceConfigTest method testInjvm.

@Test
@Disabled("Disabled due to Github Actions environment")
public void testInjvm() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("test-protocol-random-port");
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress(registryUrl);
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    ServiceConfig<DemoService> demoService;
    demoService = new ServiceConfig<DemoService>();
    demoService.setInterface(DemoService.class);
    demoService.setRef(new DemoServiceImpl());
    demoService.setApplication(application);
    demoService.setRegistry(registry);
    demoService.setProtocol(protocol);
    ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
    rc.setApplication(application);
    rc.setRegistry(registry);
    rc.setInterface(DemoService.class.getName());
    rc.setScope(SCOPE_REMOTE);
    try {
        System.setProperty("java.net.preferIPv4Stack", "true");
        demoService.export();
        rc.get();
        Assertions.assertTrue(!LOCAL_PROTOCOL.equalsIgnoreCase(rc.getInvoker().getUrl().getProtocol()));
    } finally {
        System.clearProperty("java.net.preferIPv4Stack");
        rc.destroy();
        demoService.unexport();
    }
    // Manually trigger dubbo resource recycling.
    DubboBootstrap.getInstance().destroy();
}
Also used : DemoService(org.apache.dubbo.config.api.DemoService) DemoServiceImpl(org.apache.dubbo.config.provider.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with DemoServiceImpl

use of org.apache.dubbo.config.provider.impl.DemoServiceImpl in project dubbo by apache.

the class ReferenceConfigTest method testReferenceRetry.

/**
 * unit test for dubbo-1765
 */
@Test
public void testReferenceRetry() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("test-reference-retry");
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress(registryUrl);
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("mockprotocol");
    ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
    rc.setApplication(application);
    rc.setRegistry(registry);
    rc.setInterface(DemoService.class.getName());
    boolean success = false;
    DemoService demoService = null;
    try {
        demoService = rc.get();
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assertions.assertFalse(success);
    Assertions.assertNull(demoService);
    ServiceConfig<DemoService> sc = new ServiceConfig<DemoService>();
    sc.setInterface(DemoService.class);
    sc.setRef(new DemoServiceImpl());
    sc.setApplication(application);
    sc.setRegistry(registry);
    sc.setProtocol(protocol);
    try {
        System.setProperty("java.net.preferIPv4Stack", "true");
        sc.export();
        demoService = rc.get();
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        rc.destroy();
        sc.unexport();
        System.clearProperty("java.net.preferIPv4Stack");
    }
    Assertions.assertTrue(success);
    Assertions.assertNotNull(demoService);
}
Also used : DemoService(org.apache.dubbo.config.api.DemoService) DemoServiceImpl(org.apache.dubbo.config.provider.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 5 with DemoServiceImpl

use of org.apache.dubbo.config.provider.impl.DemoServiceImpl in project dubbo by apache.

the class ServiceConfigTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    MockProtocol2.delegate = protocolDelegate;
    MockRegistryFactory2.registry = registryDelegate;
    Mockito.when(protocolDelegate.export(Mockito.any(Invoker.class))).thenReturn(exporter);
    ApplicationConfig app = new ApplicationConfig("app");
    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setName("mockprotocol2");
    ProviderConfig provider = new ProviderConfig();
    provider.setExport(true);
    provider.setProtocol(protocolConfig);
    RegistryConfig registry = new RegistryConfig();
    registry.setProtocol("mockprotocol2");
    registry.setAddress("N/A");
    ArgumentConfig argument = new ArgumentConfig();
    argument.setIndex(0);
    argument.setCallback(false);
    MethodConfig method = new MethodConfig();
    method.setName("echo");
    method.setArguments(Collections.singletonList(argument));
    service.setProvider(provider);
    service.setApplication(app);
    service.setRegistry(registry);
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.setMethods(Collections.singletonList(method));
    service2.setProvider(provider);
    service2.setApplication(app);
    service2.setRegistry(registry);
    service2.setInterface(DemoService.class);
    service2.setRef(new DemoServiceImpl());
    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);
// ApplicationModel.getConfigManager().clear();
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) DemoServiceImpl(org.apache.dubbo.config.provider.impl.DemoServiceImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DemoServiceImpl (org.apache.dubbo.config.provider.impl.DemoServiceImpl)6 DemoService (org.apache.dubbo.config.api.DemoService)4 Test (org.junit.jupiter.api.Test)4 Invoker (org.apache.dubbo.rpc.Invoker)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Disabled (org.junit.jupiter.api.Disabled)2