Search in sources :

Example 61 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class EnumBak method testGenricCustomArg.

// verify compatibility when 2.0.5 invokes 2.0.3, enum in custom parameter
@Ignore
@Test
public void testGenricCustomArg() {
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=2000000");
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    Object obj = demoProxy.$invoke("get", new String[] { "com.alibaba.dubbo.rpc.CustomArgument" }, new Object[] { arg });
    System.out.println("obj---------->" + obj);
    reference.destroy();
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) HashMap(java.util.HashMap) URL(com.alibaba.dubbo.common.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 62 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class EnumBak method testGenericEnum.

@Test
public void testGenericEnum() throws InterruptedException {
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    URL consumerurl = serviceurl;
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].class.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
    System.out.println("obj---------->" + obj);
    invoker.destroy();
    reference.destroy();
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 63 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class HessianProtocolTest method testOverload.

@Test
public void testOverload() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&hessian.overload.method=true&hessian2.request=false");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertEquals("Hello, haha", result);
    result = client.sayHello("haha", 1);
    Assert.assertEquals("Hello, haha. ", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 64 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class AbstractSerializationTest method test_URL_mutable_withType.

// ================ final field test ================
@Test
public void test_URL_mutable_withType() throws Exception {
    URL data = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue");
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(data);
    objectOutput.flushBuffer();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
    URL actual = (URL) deserialize.readObject(URL.class);
    assertEquals(data, actual);
    assertEquals(data.getParameters(), actual.getParameters());
    try {
        deserialize.readObject();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 65 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class ThriftCodecTest method testEncodeExceptionResponse.

@Test
public void testEncodeExceptionResponse() throws Exception {
    URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName());
    Channel channel = new MockedChannel(url);
    Request request = createRequest();
    RpcResult rpcResult = new RpcResult();
    String exceptionMessage = "failed";
    rpcResult.setException(new RuntimeException(exceptionMessage));
    Response response = new Response();
    response.setResult(rpcResult);
    response.setId(request.getId());
    ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);
    ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString");
    ThriftCodec.cachedRequest.put(request.getId(), rd);
    codec.encode(channel, bos, response);
    byte[] buf = new byte[bos.writerIndex() - 4];
    System.arraycopy(bos.array(), 4, buf, 0, bos.writerIndex() - 4);
    ByteArrayInputStream bis = new ByteArrayInputStream(buf);
    if (bis.markSupported()) {
        bis.mark(0);
    }
    TIOStreamTransport transport = new TIOStreamTransport(bis);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    Assert.assertEquals(ThriftCodec.MAGIC, protocol.readI16());
    Assert.assertEquals(protocol.readI32() + 4, bos.writerIndex());
    int headerLength = protocol.readI16();
    Assert.assertEquals(ThriftCodec.VERSION, protocol.readByte());
    Assert.assertEquals(Demo.Iface.class.getName(), protocol.readString());
    Assert.assertEquals(request.getId(), protocol.readI64());
    if (bis.markSupported()) {
        bis.reset();
        bis.skip(headerLength);
    }
    TMessage message = protocol.readMessageBegin();
    Assert.assertEquals("echoString", message.name);
    Assert.assertEquals(TMessageType.EXCEPTION, message.type);
    Assert.assertEquals(ThriftCodec.getSeqId(), message.seqid);
    TApplicationException exception = TApplicationException.read(protocol);
    protocol.readMessageEnd();
    Assert.assertEquals(exceptionMessage, exception.getMessage());
}
Also used : Demo(com.alibaba.dubbo.rpc.gen.thrift.Demo) Channel(com.alibaba.dubbo.remoting.Channel) Request(com.alibaba.dubbo.remoting.exchange.Request) RpcResult(com.alibaba.dubbo.rpc.RpcResult) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) URL(com.alibaba.dubbo.common.URL) ChannelBuffer(com.alibaba.dubbo.remoting.buffer.ChannelBuffer) TApplicationException(org.apache.thrift.TApplicationException) Response(com.alibaba.dubbo.remoting.exchange.Response) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ByteArrayInputStream(java.io.ByteArrayInputStream) TMessage(org.apache.thrift.protocol.TMessage) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)297 Test (org.junit.Test)169 ArrayList (java.util.ArrayList)73 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)64 HashMap (java.util.HashMap)45 Result (com.alibaba.dubbo.rpc.Result)37 Invoker (com.alibaba.dubbo.rpc.Invoker)36 Map (java.util.Map)36 List (java.util.List)30 Invocation (com.alibaba.dubbo.rpc.Invocation)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 RpcException (com.alibaba.dubbo.rpc.RpcException)22 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)20 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)18 RpcResult (com.alibaba.dubbo.rpc.RpcResult)17 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 Set (java.util.Set)12 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)11 Protocol (com.alibaba.dubbo.rpc.Protocol)11