Search in sources :

Example 1 with RegistryProtocol

use of com.alibaba.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.

the class RegistryProtocolTest method testExport.

@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());
    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.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
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
}
Also used : FailfastCluster(com.alibaba.dubbo.rpc.cluster.support.FailfastCluster) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) DubboInvoker(com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker) DubboProtocol(com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 2 with RegistryProtocol

use of com.alibaba.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.

the class RegistryProtocolTest method testDefaultPort.

@Test
public void testDefaultPort() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    assertEquals(9090, registryProtocol.getDefaultPort());
}
Also used : RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) Test(org.junit.Test)

Example 3 with RegistryProtocol

use of com.alibaba.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.

the class RegistryProtocolTest method testNotifyOverride_notmatch.

/**
 * 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(Constants.EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
    NotifyListener listener = getListener(rprotocol);
    List<URL> urls = new ArrayList<URL>();
    urls.add(URL.valueOf("override://0.0.0.0/com.alibaba.dubbo.registry.protocol.HackService?timeout=100"));
    listener.notify(urls);
    assertEquals(true, exporter.getInvoker().isAvailable());
    assertEquals(null, exporter.getInvoker().getUrl().getParameter("timeout"));
    exporter.unexport();
    destroyRegistryProtocol();
}
Also used : RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) NotifyListener(com.alibaba.dubbo.registry.NotifyListener) Test(org.junit.Test)

Example 4 with RegistryProtocol

use of com.alibaba.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.

the class RegistryProtocolTest method testNotifyOverride.

@Test
public void testNotifyOverride() throws Exception {
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = RegistryProtocol.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);
    assertEquals(true, 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();
}
Also used : RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) NotifyListener(com.alibaba.dubbo.registry.NotifyListener) Test(org.junit.Test)

Example 5 with RegistryProtocol

use of com.alibaba.dubbo.registry.integration.RegistryProtocol in project dubbo by alibaba.

the class RegistryProtocolTest method testExportUrlNull.

@Test(expected = IllegalArgumentException.class)
public void testExportUrlNull() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    Invoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, registryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    registryProtocol.export(invoker);
}
Also used : FailfastCluster(com.alibaba.dubbo.rpc.cluster.support.FailfastCluster) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) DubboInvoker(com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker) DubboProtocol(com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) Test(org.junit.Test)

Aggregations

RegistryProtocol (com.alibaba.dubbo.registry.integration.RegistryProtocol)5 Test (org.junit.Test)5 URL (com.alibaba.dubbo.common.URL)3 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)2 Protocol (com.alibaba.dubbo.rpc.Protocol)2 FailfastCluster (com.alibaba.dubbo.rpc.cluster.support.FailfastCluster)2 DubboInvoker (com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker)2 DubboProtocol (com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol)2 ArrayList (java.util.ArrayList)2