Here are the examples of the java api com.alibaba.dubbo.common.URL.valueOf() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
448 Examples
19
Source : UnsubscribePageHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Page handle(URL url) {
String consumer = url.getParameterAndDecoded("consumer");
if (consumer == null || consumer.length() == 0) {
throw new IllegalArgumentException("Please input consumer parameter.");
}
URL consumerUrl = URL.valueOf(consumer);
RegistryContainer.getInstance().getRegistry().unsubscribe(consumerUrl, NotifyListenerAdapter.NOTIFY_LISTENER);
String parameter;
if (url.hasParameter("service")) {
parameter = "service=" + url.getParameter("service");
} else if (url.hasParameter("host")) {
parameter = "host=" + url.getParameter("host");
} else if (url.hasParameter("application")) {
parameter = "application=" + url.getParameter("application");
} else {
parameter = "service=" + consumerUrl.getServiceInterface();
}
return new Page("<script type=\"text/javascript\">window.location.href=\"consumers.html?" + parameter + "\";</script>");
}
19
Source : UnregisterPageHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Page handle(URL url) {
String provider = url.getParameterAndDecoded("provider");
if (provider == null || provider.length() == 0) {
throw new IllegalArgumentException("Please input provider parameter.");
}
URL providerUrl = URL.valueOf(provider);
RegistryContainer.getInstance().getRegistry().unregister(providerUrl);
String parameter;
if (url.hasParameter("service")) {
parameter = "service=" + url.getParameter("service");
} else if (url.hasParameter("host")) {
parameter = "host=" + url.getParameter("host");
} else if (url.hasParameter("application")) {
parameter = "application=" + url.getParameter("application");
} else {
parameter = "service=" + providerUrl.getServiceInterface();
}
return new Page("<script type=\"text/javascript\">window.location.href=\"providers.html?" + parameter + "\";</script>");
}
19
Source : AbstractTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected URL getUrl() {
return URL.valueOf("thrift://127.0.0.1:" + PORT + "/" + getInterface().getName());
}
19
Source : RmiProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testRmiProtocol() throws Exception {
{
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
service = proxy.getProxy(protocol.refer(DemoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
replacedertEquals(service.getSize(null), -1);
replacedertEquals(service.getSize(new String[] { "", "", "" }), 3);
Object result = service.invoke("rmi://127.0.0.1:9001/TestService", "invoke");
replacedertEquals("rmi://127.0.0.1:9001/TestService:invoke", result);
rpcExporter.unexport();
}
{
RemoteService remoteService = new RemoteServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
remoteService = proxy.getProxy(protocol.refer(RemoteService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
remoteService.getThreadName();
for (int i = 0; i < 100; i++) {
String say = remoteService.sayHello("abcd");
replacedertEquals("hello abcd@" + RemoteServiceImpl.clreplaced.getName(), say);
}
rpcExporter.unexport();
}
}
19
Source : RmiProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/*
@Test
public void test_getRemoteClreplaced() throws Exception {
Clreplaced<NonStdRmiInterface> clazz = RmiProtocol.getRemoteClreplaced(NonStdRmiInterface.clreplaced);
replacedertEquals(clazz, RmiProtocol.getRemoteClreplaced(NonStdRmiInterface.clreplaced));
}
*/
@Test
public void testRmiProtocolTimeout() throws Exception {
System.setProperty("sun.rmi.transport.tcp.responseTimeout", "1000");
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
service = proxy.getProxy(protocol.refer(DemoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
try {
try {
service.throwTimeout();
} catch (RpcException e) {
replacedertEquals(true, e.isTimeout());
replacedertEquals(true, e.getMessage().contains("Read timed out"));
}
} finally {
rpcExporter.unexport();
}
}
19
Source : RmiProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
// FIXME RMI协议目前的实现不支持转型成 EchoService
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception {
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
// cast to EchoService
EchoService echo = proxy.getProxy(protocol.refer(EchoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
replacedertEquals(echo.$echo("test"), "test");
replacedertEquals(echo.$echo("abcdefg"), "abcdefg");
replacedertEquals(echo.$echo(1234), 1234);
rpcExporter.unexport();
RemoteService remoteService = new RemoteServiceImpl();
rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
// cast to EchoService
echo = proxy.getProxy(protocol.refer(EchoService.clreplaced, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
replacedertEquals(echo.$echo("test"), "test");
replacedertEquals(echo.$echo("abcdefg"), "abcdefg");
replacedertEquals(echo.$echo(1234), 1234);
rpcExporter.unexport();
}
19
Source : InjvmProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testIsInjvmRefer() throws Exception {
DemoService service = new DemoServiceImpl();
URL url = URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.clreplaced.getName());
Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.clreplaced, url));
exporters.add(exporter);
url = url.setProtocol("dubbo");
replacedertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
url = url.addParameter(Constants.GROUP_KEY, "*").addParameter(Constants.VERSION_KEY, "*");
replacedertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
19
Source : InjvmProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testLocalProtocol() throws Exception {
DemoService service = new DemoServiceImpl();
Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.clreplaced, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.clreplaced.getName())));
exporters.add(exporter);
service = proxy.getProxy(protocol.refer(DemoService.clreplaced, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.clreplaced.getName())));
replacedertEquals(service.getSize(new String[] { "", "", "" }), 3);
service.invoke("injvm://127.0.0.1/TestService", "invoke");
}
19
Source : HessianProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testHessianProtocol() {
HessianServiceImpl server = new HessianServiceImpl();
replacedert.replacedertFalse(server.isCalled());
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.clreplaced).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.clreplaced).getAdaptiveExtension();
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.clreplaced.getName() + "?version=1.0.0");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.clreplaced, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.clreplaced, url);
HessianService client = proxyFactory.getProxy(invoker);
String result = client.sayHello("haha");
replacedert.replacedertTrue(server.isCalled());
replacedert.replacedertEquals("Hello, haha", result);
invoker.destroy();
exporter.unexport();
}
19
Source : HessianProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testTimeOut() {
HessianServiceImpl server = new HessianServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.clreplaced).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.clreplaced).getAdaptiveExtension();
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.clreplaced.getName() + "?version=1.0.0&timeout=10");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.clreplaced, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.clreplaced, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.timeOut(6000);
fail();
} catch (RpcException expected) {
replacedert.replacedertEquals(true, expected.isTimeout());
} finally {
invoker.destroy();
exporter.unexport();
}
}
19
Source : HessianProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testCustomException() {
HessianServiceImpl server = new HessianServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.clreplaced).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.clreplaced).getAdaptiveExtension();
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.clreplaced.getName() + "?version=1.0.0");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.clreplaced, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.clreplaced, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.customException();
fail();
} catch (MyException expected) {
}
invoker.destroy();
exporter.unexport();
}
19
Source : HessianProtocolTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testHttpClient() {
HessianServiceImpl server = new HessianServiceImpl();
replacedert.replacedertFalse(server.isCalled());
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.clreplaced).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.clreplaced).getAdaptiveExtension();
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.clreplaced.getName() + "?version=1.0.0&client=httpclient");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.clreplaced, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.clreplaced, url);
HessianService client = proxyFactory.getProxy(invoker);
String result = client.sayHello("haha");
replacedert.replacedertTrue(server.isCalled());
replacedert.replacedertEquals("Hello, haha", result);
invoker.destroy();
exporter.unexport();
}
19
Source : ProtocolUtils.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static <T> T refer(Clreplaced<T> type, String url) {
return refer(type, URL.valueOf(url));
}
19
Source : ProtocolUtils.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static <T> Exporter<T> export(T instance, Clreplaced<T> type, String url) {
return export(instance, type, URL.valueOf(url));
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@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.clreplaced, serviceurl);
protocol.export(invoker);
URL consumerurl = serviceurl;
Invoker<GenericService> reference = protocol.refer(GenericService.clreplaced, consumerurl);
GenericService demoProxy = (GenericService) proxy.getProxy(reference);
Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].clreplaced.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
System.out.println("obj---------->" + obj);
invoker.destroy();
reference.destroy();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testNormal() {
int port = NetUtils.getAvailablePort();
URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?proxy=jdk" + "&interface=" + DemoService.clreplaced.getName() + "&timeout=" + Integer.MAX_VALUE);
DemoService demo = new DemoServiceImpl();
Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.clreplaced, serviceurl);
protocol.export(invoker);
URL consumerurl = serviceurl;
Invoker<DemoService> reference = protocol.refer(DemoService.clreplaced, consumerurl);
DemoService demoProxy = (DemoService) proxy.getProxy(reference);
// System.out.println(demoProxy.getThreadName());
replacedert.replacedertEquals((byte) -128, demoProxy.getbyte((byte) -128));
// invoker.destroy();
reference.destroy();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
// @Ignore
// @Test
public void testGenericExport() throws InterruptedException {
int port = NetUtils.getAvailablePort();
port = 20880;
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.clreplaced, serviceurl);
protocol.export(invoker);
// SERVER
Thread.sleep(Integer.MAX_VALUE);
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
// @Test
// 测试2.0.5调用2.0.3的兼容
public void testEnumCompat() {
int port = 20880;
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
Invoker<DemoService> reference = protocol.refer(DemoService.clreplaced, consumerurl);
DemoService demoProxy = (DemoService) proxy.getProxy(reference);
Type type = demoProxy.enumlength(Type.High);
System.out.println(type);
replacedert.replacedertEquals(Type.High, type);
reference.destroy();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
// @Test
// 测试2.0.5调用2.0.3的兼容 自定义类型参数中包含enum类型
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.clreplaced, 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();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
// @Test
// 测试2.0.5调用2.0.3的兼容
public void testGenricEnumCompat() {
int port = 20880;
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
Invoker<GenericService> reference = protocol.refer(GenericService.clreplaced, consumerurl);
GenericService demoProxy = (GenericService) proxy.getProxy(reference);
Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].clreplaced.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
System.out.println("obj---------->" + obj);
reference.destroy();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testNormalEnum() {
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.clreplaced, serviceurl);
protocol.export(invoker);
URL consumerurl = serviceurl;
Invoker<DemoService> reference = protocol.refer(DemoService.clreplaced, consumerurl);
DemoService demoProxy = (DemoService) proxy.getProxy(reference);
Type type = demoProxy.enumlength(Type.High);
System.out.println(type);
replacedert.replacedertEquals(Type.High, type);
invoker.destroy();
reference.destroy();
}
19
Source : EnumBak.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Ignore
@Test
public void testExportService() throws InterruptedException {
int port = NetUtils.getAvailablePort();
URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?proxy=jdk&timeout=" + Integer.MAX_VALUE);
DemoService demo = new DemoServiceImpl();
Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.clreplaced, serviceurl);
protocol.export(invoker);
synchronized (EnumBak.clreplaced) {
EnumBak.clreplaced.wait();
}
// URL consumerurl = serviceurl;
// Invoker<DemoService> reference = protocol.refer(DemoService.clreplaced, consumerurl);
// DemoService demoProxy = (DemoService)proxyFactory.createProxy(reference);
// // System.out.println(demoProxy.getThreadName());
// System.out.println("byte:"+demoProxy.getbyte((byte)-128));
//
// invoker.destroy();
// reference.destroy();
}
19
Source : RpcFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void testRpcFilter() throws Exception {
DemoService service = new DemoServiceImpl();
URL url = URL.valueOf("dubbo://127.0.0.1:9010/com.alibaba.dubbo.rpc.DemoService?service.filter=echo");
protocol.export(proxy.getInvoker(service, DemoService.clreplaced, url));
service = proxy.getProxy(protocol.refer(DemoService.clreplaced, url));
replacedertEquals("123", service.echo("123"));
// cast to EchoService
EchoService echo = proxy.getProxy(protocol.refer(EchoService.clreplaced, url));
replacedertEquals(echo.$echo("test"), "test");
replacedertEquals(echo.$echo("abcdefg"), "abcdefg");
replacedertEquals(echo.$echo(1234), 1234);
}
19
Source : MultiThreadTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void testDubboMulreplacedhreadInvoke() throws Exception {
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(new DemoServiceImpl(), DemoService.clreplaced, URL.valueOf("dubbo://127.0.0.1:20259/TestService")));
final AtomicInteger counter = new AtomicInteger();
final DemoService service = proxy.getProxy(protocol.refer(DemoService.clreplaced, URL.valueOf("dubbo://127.0.0.1:20259/TestService")));
replacedertEquals(service.getSize(new String[] { "123", "456", "789" }), 3);
final StringBuffer sb = new StringBuffer();
for (int i = 0; i < 1024 * 64 + 32; i++) sb.append('A');
replacedertEquals(sb.toString(), service.echo(sb.toString()));
ExecutorService exec = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
final int fi = i;
exec.execute(new Runnable() {
public void run() {
for (int i = 0; i < 30; i++) {
System.out.println(fi + ":" + counter.getAndIncrement());
replacedertEquals(service.echo(sb.toString()), sb.toString());
}
}
});
}
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
rpcExporter.unexport();
}
19
Source : DubboLazyConnectTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testSticky4() {
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf("dubbo://127.0.0.1:" + port + "/hi?" + Constants.LAZY_CONNECT_KEY + "=true");
ProtocolUtils.export(new DemoServiceImpl(), IDemoService.clreplaced, url);
IDemoService service = (IDemoService) ProtocolUtils.refer(IDemoService.clreplaced, url);
replacedert.replacedertEquals("ok", service.get());
}
19
Source : DubboLazyConnectTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test(expected = RpcException.clreplaced)
public void testSticky1() {
URL url = URL.valueOf("dubbo://127.0.0.1:9090/hi");
ProtocolUtils.refer(IDemoService.clreplaced, url);
}
19
Source : DubboLazyConnectTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test(expected = RpcException.clreplaced)
public void testSticky3() {
URL url = URL.valueOf("dubbo://127.0.0.1:9090/hi?" + Constants.LAZY_CONNECT_KEY + "=true");
IDemoService service = (IDemoService) ProtocolUtils.refer(IDemoService.clreplaced, url);
service.get();
}
19
Source : DubboLazyConnectTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testSticky2() {
URL url = URL.valueOf("dubbo://127.0.0.1:9090/hi?" + Constants.LAZY_CONNECT_KEY + "=true");
ProtocolUtils.refer(IDemoService.clreplaced, url);
}
19
Source : DubboInvokerAvilableTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void test_Lazy_ChannelReadOnly() throws Exception {
URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?lazy=true&connections=1");
ProtocolUtils.export(new DemoServiceImpl(), IDemoService.clreplaced, url);
DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.clreplaced, url);
replacedert.replacedertEquals(true, invoker.isAvailable());
try {
getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
fail();
} catch (IllegalStateException e) {
}
// invoke method --> init client
IDemoService service = (IDemoService) proxy.getProxy(invoker);
replacedert.replacedertEquals("ok", service.get());
replacedert.replacedertEquals(true, invoker.isAvailable());
getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
replacedert.replacedertEquals(false, invoker.isAvailable());
}
19
Source : DubboInvokerAvilableTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void test_NoInvokers() throws Exception {
URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?connections=1");
ProtocolUtils.export(new DemoServiceImpl(), IDemoService.clreplaced, url);
DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.clreplaced, url);
ExchangeClient[] clients = getClients(invoker);
clients[0].close();
replacedert.replacedertEquals(false, invoker.isAvailable());
}
19
Source : DubboInvokerAvilableTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void test_Normal_available() {
URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi");
ProtocolUtils.export(new DemoServiceImpl(), IDemoService.clreplaced, url);
DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.clreplaced, url);
replacedert.replacedertEquals(true, invoker.isAvailable());
invoker.destroy();
replacedert.replacedertEquals(false, invoker.isAvailable());
}
19
Source : DubboInvokerAvilableTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void test_Normal_ChannelReadOnly() throws Exception {
URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi");
ProtocolUtils.export(new DemoServiceImpl(), IDemoService.clreplaced, url);
DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.clreplaced, url);
replacedert.replacedertEquals(true, invoker.isAvailable());
getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
replacedert.replacedertEquals(false, invoker.isAvailable());
// 恢复状态,invoker共享连接
getClients(invoker)[0].removeAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY);
}
19
Source : RpcUtilsTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 场景:强制设置为不添加
* 验证:acctachment中没有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_forceNotAttache() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true&" + Constants.AUTO_ATTACH_INVOCATIONID_KEY + "=false");
Invocation inv = new RpcInvocation("test", new Clreplaced[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
replacedert.replacedertNull(RpcUtils.getInvocationId(inv));
}
19
Source : RpcUtilsTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 场景:异步调用,默认添加attachement
* 验证:当原始acctachment为null时,不能报错.
*/
@Test
public void testAttachInvocationIdIfAsync_nullAttachments() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv = new RpcInvocation("test", new Clreplaced[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
replacedert.replacedertTrue(RpcUtils.getInvocationId(inv) >= 0l);
}
19
Source : RpcUtilsTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 场景:同步调用,不默认添加acctachment
* 验证:acctachment中没有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_sync() {
URL url = URL.valueOf("dubbo://localhost/");
Invocation inv = new RpcInvocation("test", new Clreplaced[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
replacedert.replacedertNull(RpcUtils.getInvocationId(inv));
}
19
Source : RpcUtilsTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 场景:强制设置为添加
* 验证:acctachment中有添加id属性
*/
@Test
public void testAttachInvocationIdIfAsync_forceAttache() {
URL url = URL.valueOf("dubbo://localhost/?" + Constants.AUTO_ATTACH_INVOCATIONID_KEY + "=true");
Invocation inv = new RpcInvocation("test", new Clreplaced[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
replacedert.replacedertNotNull(RpcUtils.getInvocationId(inv));
}
19
Source : RpcUtilsTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 正常场景:url中表示了方法异步调用
* 验证:1. invocationId是否正常设置,2.幂等测试
*/
@Test
public void testAttachInvocationIdIfAsync_normal() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true");
Map<String, String> attachments = new HashMap<String, String>();
attachments.put("aa", "bb");
Invocation inv = new RpcInvocation("test", new Clreplaced[] {}, new String[] {}, attachments);
RpcUtils.attachInvocationIdIfAsync(url, inv);
long id1 = RpcUtils.getInvocationId(inv);
RpcUtils.attachInvocationIdIfAsync(url, inv);
long id2 = RpcUtils.getInvocationId(inv);
// 幂等操作验证
replacedert.replacedertTrue(id1 == id2);
replacedert.replacedertTrue(id1 >= 0);
replacedert.replacedertEquals("bb", attachments.get("aa"));
}
19
Source : TpsLimitFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test(expected = RpcException.clreplaced)
public void testFail() throws Exception {
URL url = URL.valueOf("test://test");
url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService");
url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
Invocation invocation = new MockInvocation();
for (int i = 0; i < 10; i++) {
try {
filter.invoke(invoker, invocation);
} catch (Exception e) {
replacedertTrue(i >= 5);
throw e;
}
}
}
19
Source : TpsLimitFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testWithoutCount() throws Exception {
URL url = URL.valueOf("test://test");
url = url.addParameter(Constants.INTERFACE_KEY, "com.alibaba.dubbo.rpc.file.TpsService");
url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
Invocation invocation = new MockInvocation();
filter.invoke(invoker, invocation);
}
19
Source : DeprecatedFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testDeprecatedFilter() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&echo." + Constants.DEPRECATED_KEY + "=true");
LogUtil.start();
deprecatedFilter.invoke(new MyInvoker<DemoService>(url), new MockInvocation());
replacedertEquals(1, LogUtil.findMessage("The service method com.alibaba.dubbo.rpc.support.DemoService.echo(String) is DEPRECATED"));
LogUtil.stop();
}
19
Source : ContextFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testWithAttachments() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
Result result = contextFilter.invoke(invoker, invocation);
replacedertNull(RpcContext.getContext().getInvoker());
}
19
Source : ConsumerContextFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testSetContext() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
consumerContextFilter.invoke(invoker, invocation);
replacedertEquals(invoker, RpcContext.getContext().getInvoker());
replacedertEquals(invocation, RpcContext.getContext().getInvocation());
replacedertEquals(NetUtils.getLocalHost() + ":0", RpcContext.getContext().getLocalAddressString());
replacedertEquals("test:11", RpcContext.getContext().getRemoteAddressString());
}
19
Source : ActiveLimitFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testInvokeNoActives() {
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=0");
Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url);
Invocation invocation = new MockInvocation();
activeLimitFilter.invoke(invoker, invocation);
}
19
Source : ActiveLimitFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testInvokeGreaterActives() {
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=1&timeout=1");
final Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url);
final Invocation invocation = new MockInvocation();
for (int i = 0; i < 100; i++) {
Thread thread = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
try {
activeLimitFilter.invoke(invoker, invocation);
} catch (RpcException expected) {
count++;
}
}
}
});
thread.start();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
replacedertNotSame(0, count);
}
19
Source : ActiveLimitFilterTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Test
public void testInvokeLessActives() {
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=10");
Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url);
Invocation invocation = new MockInvocation();
activeLimitFilter.invoke(invoker, invocation);
}
19
Source : MulticastGroup.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private void receive(String msg, InetSocketAddress remoteAddress) throws RemotingException {
if (msg.startsWith(JOIN)) {
String url = msg.substring(JOIN.length()).trim();
connect(URL.valueOf(url));
} else if (msg.startsWith(LEAVE)) {
String url = msg.substring(LEAVE.length()).trim();
disconnect(URL.valueOf(url));
}
}
19
Source : FileGroup.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private void changed() throws RemotingException {
try {
String[] lines = IOUtils.readLines(file);
for (String line : lines) {
connect(URL.valueOf(line));
}
} catch (IOException e) {
throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
}
}
19
Source : Networkers.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static Peer join(String group, String peer, ChannelHandler handler) throws RemotingException {
return join(URL.valueOf(group), URL.valueOf(peer), handler);
}
19
Source : Networkers.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static Group lookup(String group) throws RemotingException {
return lookup(URL.valueOf(group));
}
19
Source : ExchangeNetworkers.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static ExchangePeer join(String group, String peer, ExchangeHandler handler) throws RemotingException {
return join(URL.valueOf(group), URL.valueOf(peer), handler);
}
See More Examples