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();
}
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();
}
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();
}
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) {
}
}
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());
}
Aggregations