下面列出了怎么用com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService的API类实例代码及写法,或者点击链接到github查看源代码。
@BeforeClass
public static void setUp() {
StringBuilder buf = new StringBuilder();
StringBuilder buf2 = new StringBuilder();
Method[] methods = DemoService.class.getMethods();
for (Method method : methods) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (buf2.length() > 0) {
buf2.append("\r\n");
}
buf2.append(method.getName());
buf.append(ReflectUtils.getName(method));
}
detailMethods = buf.toString();
methodsName = buf2.toString();
ProtocolUtils.closeAll();
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "echo(\"ok\")");
assertTrue(result.contains("ok"));
EasyMock.reset(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = mock(Channel.class);
mockInvoker = mock(Invoker.class);
given(mockChannel.getAttribute("telnet.service")).willReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
mockChannel.setAttribute("telnet.service", "DemoService");
givenLastCall();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
givenLastCall();
mockChannel.setAttribute("telnet.service", "demo");
givenLastCall();
mockChannel.removeAttribute("telnet.service");
givenLastCall();
given(mockInvoker.getInterface()).willReturn(DemoService.class);
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20884/demo"));
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
mockInvoker = mock(Invoker.class);
given(mockInvoker.getInterface()).willReturn(DemoService.class);
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20886/demo"));
given(mockInvoker.invoke(any(Invocation.class))).willReturn(new RpcResult("ok"));
mockChannel = mock(Channel.class);
given(mockChannel.getAttribute("telnet.service")).willReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555"));
given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886"));
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() throws RemotingException {
mockInvoker = mock(Invoker.class);
given(mockInvoker.getInterface()).willReturn(DemoService.class);
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20886/demo"));
given(mockInvoker.invoke(any(Invocation.class))).willReturn(new RpcResult("ok"));
mockChannel = mock(Channel.class);
given(mockChannel.getAttribute("telnet.service")).willReturn(null);
given(mockChannel.getLocalAddress()).willReturn(NetUtils.toAddress("127.0.0.1:5555"));
given(mockChannel.getRemoteAddress()).willReturn(NetUtils.toAddress("127.0.0.1:20886"));
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "echo(\"ok\")");
assertTrue(result.contains("ok"));
}
@Test
public void testDubboProtocolMultiService() throws Exception
{
DemoService service = new DemoServiceImpl();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
RemoteService remote = new RemoteServiceImpl();
protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
service.sayHello("world");
// test netty client
assertEquals("world", service.echo("world"));
assertEquals("hello [email protected]" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
EchoService serviceEcho = (EchoService)service;
assertEquals(serviceEcho.$echo("test"), "test");
EchoService remoteEecho = (EchoService)remote;
assertEquals(remoteEecho.$echo("ok"), "ok");
}
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
int port = NetUtils.getAvailablePort();
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "-l");
assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
EasyMock.reset(mockChannel);
}
@Test
public void testDubboProtocolMultiService() throws Exception
{
DemoService service = new DemoServiceImpl();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
RemoteService remote = new RemoteServiceImpl();
protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
service.sayHello("world");
// test netty client
assertEquals("world", service.echo("world"));
assertEquals("hello [email protected]" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
EchoService serviceEcho = (EchoService)service;
assertEquals(serviceEcho.$echo("test"), "test");
EchoService remoteEecho = (EchoService)remote;
assertEquals(remoteEecho.$echo("ok"), "ok");
}
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
int port = NetUtils.getAvailablePort();
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "-l");
assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = EasyMock.createMock(Channel.class);
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
mockChannel.setAttribute("telnet.service", "DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "demo");
EasyMock.expectLastCall().anyTimes();
mockChannel.removeAttribute("telnet.service");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
EasyMock.reset(mockChannel, mockInvoker);
}
@BeforeClass
public static void setUp() {
StringBuilder buf = new StringBuilder();
StringBuilder buf2 = new StringBuilder();
Method[] methods = DemoService.class.getMethods();
for (Method method : methods) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (buf2.length() > 0) {
buf2.append("\r\n");
}
buf2.append(method.getName());
buf.append(ReflectUtils.getName(method));
}
detailMethods = buf.toString();
methodsName = buf2.toString();
ProtocolUtils.closeAll();
}
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
int port = NetUtils.getAvailablePort();
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "-l");
assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Test
public void testListDefault() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "");
assertEquals("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\r\n"
+ methodsName, result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = EasyMock.createMock(Channel.class);
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
mockChannel.setAttribute("telnet.service", "DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "demo");
EasyMock.expectLastCall().anyTimes();
mockChannel.removeAttribute("telnet.service");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = EasyMock.createMock(Channel.class);
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
mockChannel.setAttribute("telnet.service", "DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "demo");
EasyMock.expectLastCall().anyTimes();
mockChannel.removeAttribute("telnet.service");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
EasyMock.reset(mockChannel, mockInvoker);
}
@BeforeClass
public static void setUp() {
StringBuilder buf = new StringBuilder();
StringBuilder buf2 = new StringBuilder();
Method[] methods = DemoService.class.getMethods();
for (Method method : methods) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (buf2.length() > 0) {
buf2.append("\r\n");
}
buf2.append(method.getName());
buf.append(ReflectUtils.getName(method));
}
detailMethods = buf.toString();
methodsName = buf2.toString();
ProtocolUtils.closeAll();
}
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
int port = NetUtils.getAvailablePort();
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "-l");
assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Test
public void testListDefault() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "");
assertEquals("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\r\n"
+ methodsName, result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = EasyMock.createMock(Channel.class);
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
mockChannel.setAttribute("telnet.service", "DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "demo");
EasyMock.expectLastCall().anyTimes();
mockChannel.removeAttribute("telnet.service");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
EasyMock.reset(mockChannel, mockInvoker);
}
@Test
public void testDubboProtocolMultiService() throws Exception
{
DemoService service = new DemoServiceImpl();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
RemoteService remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
service.sayHello("world");
// test netty client
assertEquals("world", service.echo("world"));
assertEquals("hello [email protected]" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
EchoService serviceEcho = (EchoService)service;
assertEquals(serviceEcho.$echo("test"), "test");
EchoService remoteEecho = (EchoService)remote;
assertEquals(remoteEecho.$echo("ok"), "ok");
}
@Test
public void testDubboProtocolMultiService() throws Exception
{
DemoService service = new DemoServiceImpl();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
RemoteService remote = new RemoteServiceImpl();
protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
service.sayHello("world");
// test netty client
assertEquals("world", service.echo("world"));
assertEquals("hello [email protected]" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
EchoService serviceEcho = (EchoService)service;
assertEquals(serviceEcho.$echo("test"), "test");
EchoService remoteEecho = (EchoService)remote;
assertEquals(remoteEecho.$echo("ok"), "ok");
}
@SuppressWarnings("unchecked")
@Before
public void setUp() {
mockChannel = EasyMock.createMock(Channel.class);
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
mockChannel.setAttribute("telnet.service", "DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService");
EasyMock.expectLastCall().anyTimes();
mockChannel.setAttribute("telnet.service", "demo");
EasyMock.expectLastCall().anyTimes();
mockChannel.removeAttribute("telnet.service");
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeDefaultSService() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "DemoService.echo(\"ok\")");
assertTrue(result.contains("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\"ok\"\r\n"));
EasyMock.reset(mockChannel, mockInvoker);
}
@SuppressWarnings("unchecked")
@Test
public void testInvokeAutoFindMethod() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20883/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.expect(mockChannel.getLocalAddress()).andReturn(NetUtils.toAddress("127.0.0.1:5555")).anyTimes();
EasyMock.expect(mockChannel.getRemoteAddress()).andReturn(NetUtils.toAddress("127.0.0.1:20883")).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = invoke.telnet(mockChannel, "echo(\"ok\")");
assertTrue(result.contains("ok"));
EasyMock.reset(mockChannel, mockInvoker);
}
@BeforeClass
public static void setUp() {
StringBuilder buf = new StringBuilder();
StringBuilder buf2 = new StringBuilder();
Method[] methods = DemoService.class.getMethods();
for (Method method : methods) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (buf2.length() > 0) {
buf2.append("\r\n");
}
buf2.append(method.getName());
buf.append(ReflectUtils.getName(method));
}
detailMethods = buf.toString();
methodsName = buf2.toString();
ProtocolUtils.closeAll();
}
@SuppressWarnings("unchecked")
@Test
public void testListDetail() throws RemotingException {
int port = NetUtils.getAvailablePort();
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:"+port+"/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "-l");
assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService -> dubbo://127.0.0.1:"+port+"/demo", result);
EasyMock.reset(mockChannel);
}
@SuppressWarnings("unchecked")
@Test
public void testListDefault() throws RemotingException {
mockInvoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
EasyMock.replay(mockChannel, mockInvoker);
DubboProtocol.getDubboProtocol().export(mockInvoker);
String result = list.telnet(mockChannel, "");
assertEquals("Use default service com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService.\r\n\r\n"
+ methodsName, result);
EasyMock.reset(mockChannel);
}