Search in sources :

Example 21 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class GenericServiceTest method testGenericFindComplexObject4FullServiceMetadata.

@Test
public void testGenericFindComplexObject4FullServiceMetadata() {
    DemoService server = new DemoServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000");
    Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
    String var1 = "v1";
    int var2 = 234;
    long l = 555;
    String[] var3 = { "var31", "var32" };
    List<Integer> var4 = Arrays.asList(2, 4, 8);
    ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2;
    // ComplexObject complexObject = createComplexObject(var1, var2, l, var3, var4, testEnum);
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    Object result = client.$invoke("findComplexObject", new String[] { "java.lang.String", "int", "long", "java.lang.String[]", "java.util.List", "org.apache.dubbo.service.ComplexObject$TestEnum" }, new Object[] { var1, var2, l, var3, var4, testEnum });
    Assertions.assertNotNull(result);
    ComplexObject r = map2bean((Map) result);
    Assertions.assertEquals(r, createComplexObject(var1, var2, l, var3, var4, testEnum));
    invoker.destroy();
    exporter.unexport();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) DemoService(org.apache.dubbo.service.DemoService) URL(org.apache.dubbo.common.URL) ComplexObject(org.apache.dubbo.service.ComplexObject) ComplexObject(org.apache.dubbo.service.ComplexObject) Protocol(org.apache.dubbo.rpc.Protocol) DemoServiceImpl(org.apache.dubbo.service.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 22 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class XmlRpcProtocolTest method testXmlRpcProtocolForServerJetty9.

@Test
public void testXmlRpcProtocolForServerJetty9() {
    XmlRpcServiceImpl server = new XmlRpcServiceImpl();
    Assertions.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0&server=jetty9");
    Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
    Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
    XmlRpcService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 23 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class XmlRpcProtocolTest method testCustomException.

@Test
@Disabled
public void testCustomException() {
    XmlRpcServiceImpl server = new XmlRpcServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0&server=jetty9");
    Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
    Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
    XmlRpcService client = proxyFactory.getProxy(invoker);
    try {
        client.customException();
        Assertions.fail();
    } catch (XmlRpcServiceImpl.MyException expected) {
    }
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 24 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerInvoke_failmock.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerInvoke_failmock() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter(MOCK_KEY, "fail:return null").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName())).addParameter("invoke_return_error", "true");
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa").addParameters(url.getParameters());
    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    Invoker<IHelloService> cluster = getClusterInvokerMock(url, mInvoker1);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("aa", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Protocol(org.apache.dubbo.rpc.Protocol) MockProtocol(org.apache.dubbo.rpc.support.MockProtocol) MockProtocol(org.apache.dubbo.rpc.support.MockProtocol) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 25 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock.

/**
 * Test if mock policy works fine: force-mock
 */
@Test
public void testMockInvokerInvoke_forcemock() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(MOCK_KEY, "force:return null").addParameter(REFER_KEY, URL.encode(PATH_KEY + "=" + IHelloService.class.getName()));
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa&getSomething3xx.mock=return xx").addParameters(url.getParameters());
    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    Invoker<IHelloService> cluster = getClusterInvokerMock(url, mInvoker1);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assertions.assertEquals("aa", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assertions.assertNull(ret.getValue());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Protocol(org.apache.dubbo.rpc.Protocol) MockProtocol(org.apache.dubbo.rpc.support.MockProtocol) MockProtocol(org.apache.dubbo.rpc.support.MockProtocol) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Protocol (org.apache.dubbo.rpc.Protocol)37 Test (org.junit.jupiter.api.Test)33 URL (org.apache.dubbo.common.URL)32 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)25 GenericService (org.apache.dubbo.rpc.service.GenericService)10 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)6 DemoService (org.apache.dubbo.service.DemoService)6 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)6 Result (org.apache.dubbo.rpc.Result)5 DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol)5 ComplexObject (org.apache.dubbo.service.ComplexObject)5 RpcException (org.apache.dubbo.rpc.RpcException)4 MockProtocol (org.apache.dubbo.rpc.support.MockProtocol)4 HashMap (java.util.HashMap)3 MetricsService (org.apache.dubbo.monitor.MetricsService)3 RegistryProtocol (org.apache.dubbo.registry.integration.RegistryProtocol)3 IMetricManager (com.alibaba.metrics.IMetricManager)2 MetricObject (com.alibaba.metrics.common.MetricObject)2 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2