Search in sources :

Example 6 with ServiceDescriptor

use of org.apache.dubbo.rpc.model.ServiceDescriptor in project dubbo by alibaba.

the class RestProtocolTest method testRestProtocolWithContextPath.

@Test
public void testRestProtocolWithContextPath() {
    DemoServiceImpl server = new DemoServiceImpl();
    Assertions.assertFalse(server.isCalled());
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("rest://127.0.0.1:" + port + "/a/b/c?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
    this.registerProvider(url, server, DemoService.class);
    ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class);
    repository.registerProvider(url.getPathKey(), server, serviceDescriptor, null, null);
    Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url));
    url = URL.valueOf("rest://127.0.0.1:" + port + "/a/b/c/?version=1.0.0&interface=org.apache.dubbo.rpc.protocol.rest.DemoService");
    Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
    DemoService client = proxy.getProxy(invoker);
    String result = client.sayHello("haha");
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 7 with ServiceDescriptor

use of org.apache.dubbo.rpc.model.ServiceDescriptor in project dubbo by alibaba.

the class RestProtocolTest method registerProvider.

private void registerProvider(URL url, Object impl, Class<?> interfaceClass) {
    ServiceDescriptor serviceDescriptor = repository.registerService(interfaceClass);
    repository.registerProvider(url.getServiceKey(), impl, serviceDescriptor, null, null);
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor)

Example 8 with ServiceDescriptor

use of org.apache.dubbo.rpc.model.ServiceDescriptor in project dubbo by alibaba.

the class RegistryProtocolTest method testExport.

@Test
public void testExport() {
    RegistryProtocol registryProtocol = getRegistryProtocol();
    // registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());
    ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
    ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    // The same invoker, exporter that multiple exported are different
    Assertions.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) RegistryProtocol(org.apache.dubbo.registry.integration.RegistryProtocol) DubboInvoker(org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker) RegistryProtocol(org.apache.dubbo.registry.integration.RegistryProtocol) Protocol(org.apache.dubbo.rpc.Protocol) DubboProtocol(org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 9 with ServiceDescriptor

use of org.apache.dubbo.rpc.model.ServiceDescriptor in project dubbo by alibaba.

the class RegistryProtocolTest method testNotifyOverride_notmatch.

// @Test
// public void testNotifyOverride() throws Exception {
// URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
// Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
// 
// ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
// ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
// 
// Exporter<?> exporter = protocol.export(invoker);
// RegistryProtocol rprotocol = getRegistryProtocol();
// NotifyListener listener = getListener(rprotocol);
// List<URL> urls = new ArrayList<URL>();
// urls.add(URL.valueOf("override://0.0.0.0/?timeout=1000"));
// urls.add(URL.valueOf("override://0.0.0.0/" + service + "?timeout=100"));
// urls.add(URL.valueOf("override://0.0.0.0/" + service + "?x=y"));
// listener.notify(urls);
// 
// assertTrue(exporter.getInvoker().isAvailable());
// assertEquals("100", exporter.getInvoker().getUrl().getParameter("timeout"));
// assertEquals("y", exporter.getInvoker().getUrl().getParameter("x"));
// 
// exporter.unexport();
// //        int timeout = ConfigUtils.getServerShutdownTimeout();
// //        Thread.sleep(timeout + 1000);
// //        assertEquals(false, exporter.getInvoker().isAvailable());
// destroyRegistryProtocol();
// 
// }
/**
 * The name of the service does not match and can't override invoker
 * Service name matching, service version number mismatch
 */
@Test
public void testNotifyOverride_notmatch() throws Exception {
    URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
    ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = getRegistryProtocol();
    NotifyListener listener = getListener(rprotocol);
    List<URL> urls = new ArrayList<URL>();
    urls.add(URL.valueOf("override://0.0.0.0/org.apache.dubbo.registry.protocol.HackService?timeout=100"));
    listener.notify(urls);
    assertTrue(exporter.getInvoker().isAvailable());
    assertNull(exporter.getInvoker().getUrl().getParameter("timeout"));
    exporter.unexport();
    destroyRegistryProtocol();
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) RegistryProtocol(org.apache.dubbo.registry.integration.RegistryProtocol) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL) NotifyListener(org.apache.dubbo.registry.NotifyListener) Test(org.junit.jupiter.api.Test)

Example 10 with ServiceDescriptor

use of org.apache.dubbo.rpc.model.ServiceDescriptor in project dubbo by alibaba.

the class RegistryProtocolTest method testDestoryRegistry.

/**
 * Test destory registry, exporter can be normal by destroyed
 */
@Test
public void testDestoryRegistry() {
    URL newRegistryUrl = registryUrl.addParameter(EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    ServiceDescriptor descriptor = ApplicationModel.getServiceRepository().registerService(DemoService.class);
    ApplicationModel.getServiceRepository().registerProvider(service, new DemoServiceImpl(), descriptor, null, null);
    Exporter<?> exporter = protocol.export(invoker);
    destroyRegistryProtocol();
    try {
        Thread.sleep(ConfigurationUtils.getServerShutdownTimeout() + 100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertFalse(exporter.getInvoker().isAvailable());
}
Also used : ServiceDescriptor(org.apache.dubbo.rpc.model.ServiceDescriptor) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceDescriptor (org.apache.dubbo.rpc.model.ServiceDescriptor)13 URL (org.apache.dubbo.common.URL)5 ServiceRepository (org.apache.dubbo.rpc.model.ServiceRepository)5 Test (org.junit.jupiter.api.Test)4 RegistryProtocol (org.apache.dubbo.registry.integration.RegistryProtocol)2 MethodDescriptor (org.apache.dubbo.rpc.model.MethodDescriptor)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Cleanable (org.apache.dubbo.common.serialize.Cleanable)1 ObjectInput (org.apache.dubbo.common.serialize.ObjectInput)1 ServiceConfigBase (org.apache.dubbo.config.ServiceConfigBase)1 NotifyListener (org.apache.dubbo.registry.NotifyListener)1 Protocol (org.apache.dubbo.rpc.Protocol)1 DubboInvoker (org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker)1 DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol)1