Java Code Examples for com.alibaba.dubbo.common.URL#valueOf()
The following examples show how to use
com.alibaba.dubbo.common.URL#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompatibleFilterFilterTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testInvokerNonJsonEnumSerialization() { invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes(); EasyMock.replay(invocation); invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); Result filterResult = compatibleFilter.invoke(invoker, invocation); assertEquals(Type.High, filterResult.getValue()); }
Example 2
Source File: EnumBak.java From dubbox with Apache License 2.0 | 6 votes |
@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.class, serviceurl); protocol.export(invoker); URL consumerurl = serviceurl; Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl); DemoService demoProxy = (DemoService)proxy.getProxy(reference); Type type = demoProxy.enumlength(Type.High); System.out.println(type); Assert.assertEquals(Type.High, type); invoker.destroy(); reference.destroy(); }
Example 3
Source File: EnumBak.java From dubbox with Apache License 2.0 | 6 votes |
@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.class, serviceurl); protocol.export(invoker); synchronized (EnumBak.class) { EnumBak.class.wait(); } // URL consumerurl = serviceurl; // Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl); // DemoService demoProxy = (DemoService)proxyFactory.createProxy(reference); //// System.out.println(demoProxy.getThreadName()); // System.out.println("byte:"+demoProxy.getbyte((byte)-128)); // // invoker.destroy(); // reference.destroy(); }
Example 4
Source File: EchoFilterTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testEcho() { Invocation invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("$echo").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes(); EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes(); EasyMock.replay(invocation); Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); Result filterResult = echoFilter.invoke(invoker, invocation); assertEquals("hello", filterResult.getValue()); }
Example 5
Source File: EnumBak.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@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.class, serviceurl); protocol.export(invoker); synchronized (EnumBak.class) { EnumBak.class.wait(); } // URL consumerurl = serviceurl; // Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl); // DemoService demoProxy = (DemoService)proxyFactory.createProxy(reference); //// System.out.println(demoProxy.getThreadName()); // System.out.println("byte:"+demoProxy.getbyte((byte)-128)); // // invoker.destroy(); // reference.destroy(); }
Example 6
Source File: TpsLimitFilterTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test(expected = RpcException.class) 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) { assertTrue(i >= 5); throw e; } } }
Example 7
Source File: HttpProtocolTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testCustomException() { HttpServiceImpl server = new HttpServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0"); Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url)); Invoker<HttpService> invoker = protocol.refer(HttpService.class, url); HttpService client = proxyFactory.getProxy(invoker); try { client.customException(); fail(); } catch (HttpServiceImpl.MyException expected) { } invoker.destroy(); exporter.unexport(); }
Example 8
Source File: EnumBak.java From dubbo3 with Apache License 2.0 | 6 votes |
@Test public void testNormal(){ int port = NetUtils.getAvailablePort(); URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?proxy=jdk" + "&interface=" + DemoService.class.getName() + "&timeout=" + Integer.MAX_VALUE ); DemoService demo = new DemoServiceImpl(); Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl); protocol.export(invoker); URL consumerurl = serviceurl; Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl); DemoService demoProxy = (DemoService)proxy.getProxy(reference); // System.out.println(demoProxy.getThreadName()); Assert.assertEquals((byte)-128, demoProxy.getbyte((byte)-128)); // invoker.destroy(); reference.destroy(); }
Example 9
Source File: ReferenceCountExchangeClientTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void init(int connections){ int port = NetUtils.getAvailablePort(); URL demoUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/demo?"+Constants.CONNECTIONS_KEY+"="+connections); URL helloUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/hello?"+Constants.CONNECTIONS_KEY+"="+connections); demoExporter = export(new DemoServiceImpl(), IDemoService.class, demoUrl); helloExporter = export(new HelloServiceImpl(), IHelloService.class, helloUrl); demoServiceInvoker = (Invoker<IDemoService>) referInvoker(IDemoService.class, demoUrl); demoService = proxy.getProxy(demoServiceInvoker); Assert.assertEquals("demo", demoService.demo()); helloServiceInvoker = (Invoker<IHelloService>) referInvoker(IHelloService.class, helloUrl); helloService = proxy.getProxy(helloServiceInvoker); Assert.assertEquals("hello", helloService.hello()); demoClient = getClient(demoServiceInvoker); helloClient = getClient(helloServiceInvoker); }
Example 10
Source File: EchoFilterTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testNonEcho() { Invocation invocation = mock(Invocation.class); given(invocation.getMethodName()).willReturn("echo"); given(invocation.getParameterTypes()).willReturn(new Class<?>[]{Enum.class}); given(invocation.getArguments()).willReturn(new Object[]{"hello"}); given(invocation.getAttachments()).willReturn(null); Invoker<DemoService> invoker = mock(Invoker.class); given(invoker.isAvailable()).willReturn(true); given(invoker.getInterface()).willReturn(DemoService.class); RpcResult result = new RpcResult(); result.setValue("High"); given(invoker.invoke(invocation)).willReturn(result); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); given(invoker.getUrl()).willReturn(url); Result filterResult = echoFilter.invoke(invoker, invocation); assertEquals("High", filterResult.getValue()); }
Example 11
Source File: DubboInvokerAvilableTest.java From dubbox with Apache License 2.0 | 5 votes |
@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.class, url); DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url); ExchangeClient[] clients = getClients(invoker); clients[0].close(); Assert.assertEquals(false, invoker.isAvailable()); }
Example 12
Source File: DubboAppContextFilterTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testInvokeApplicationKey() { Invoker invoker = mock(Invoker.class); Invocation invocation = mock(Invocation.class); URL url = URL.valueOf("test://test:111/test?application=serviceA"); when(invoker.getUrl()).thenReturn(url); filter.invoke(invoker, invocation); verify(invoker).invoke(invocation); String application = RpcContext.getContext().getAttachment(DubboUtils.DUBBO_APPLICATION_KEY); assertEquals("serviceA", application); }
Example 13
Source File: AbstractMonitorFactoryTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testMonitorFactoryCache() throws Exception { URL url = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostAddress() + ":2233"); Monitor monitor1 = monitorFactory.getMonitor(url); Monitor monitor2 = monitorFactory.getMonitor(url); Assert.assertEquals(monitor1, monitor2); }
Example 14
Source File: HeartbeatHandlerTest.java From dubbo-remoting-netty4 with Apache License 2.0 | 5 votes |
@Test public void testHeartbeat() throws Exception { URL serverURL = URL.valueOf("header://localhost:55555?transporter=netty4"); serverURL = serverURL.addParameter(Constants.HEARTBEAT_KEY, 1000); TestHeartbeatHandler handler = new TestHeartbeatHandler(); server = Exchangers.bind(serverURL, handler); System.out.println("Server bind successfully"); client = Exchangers.connect(serverURL); Thread.sleep(10000); System.err.println("++++++++++++++ disconnect count " + handler.disconnectCount); System.err.println("++++++++++++++ connect count " + handler.connectCount); Assert.assertTrue(handler.disconnectCount == 0); Assert.assertTrue(handler.connectCount == 1); }
Example 15
Source File: ExtensionLoaderTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testLoadActivateExtension() throws Exception { // test default URL url = URL.valueOf("test://localhost/test"); List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "default_group"); Assert.assertEquals(1, list.size()); Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class); // test group url = url.addParameter(Constants.GROUP_KEY, "group1"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "group1"); Assert.assertEquals(1, list.size()); Assert.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class); // test value url = url.removeParameter(Constants.GROUP_KEY); url = url.addParameter(Constants.GROUP_KEY, "value"); url = url.addParameter("value", "value"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "value"); Assert.assertEquals(1, list.size()); Assert.assertTrue(list.get(0).getClass() == ValueActivateExtImpl.class); // test order url = URL.valueOf("test://localhost/test"); url = url.addParameter(Constants.GROUP_KEY, "order"); list = ExtensionLoader.getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "order"); Assert.assertEquals(2, list.size()); Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class); Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl2.class); }
Example 16
Source File: AbstractCacheFactoryTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
protected Cache constructCache() { URL url = URL.valueOf("test://test:11/test?cache=lru"); Invocation invocation = new RpcInvocation(); return getCacheFactory().getCache(url, invocation); }
Example 17
Source File: UrlUtilsTest.java From dubbo3 with Apache License 2.0 | 4 votes |
@Test public void testIsMatch3() { URL consumerUrl = URL.valueOf("dubbo://127.0.0.1:20880/com.xxx.XxxService?version=1.0.0&group=aa"); URL providerUrl = URL.valueOf("http://127.0.0.1:8080/com.xxx.XxxService?version=1.0.0&group=test"); assertFalse(UrlUtils.isMatch(consumerUrl, providerUrl)); }
Example 18
Source File: ThriftCodecTest.java From dubbox with Apache License 2.0 | 4 votes |
@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() ); }
Example 19
Source File: UrlUtilsTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Test public void testIsMatch3() { URL consumerUrl = URL.valueOf("dubbo://127.0.0.1:20880/com.xxx.XxxService?version=1.0.0&group=aa"); URL providerUrl = URL.valueOf("http://127.0.0.1:8080/com.xxx.XxxService?version=1.0.0&group=test"); assertFalse(UrlUtils.isMatch(consumerUrl, providerUrl)); }
Example 20
Source File: UrlUtilsTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testIsMatch2() { URL consumerUrl = URL.valueOf("dubbo://127.0.0.1:20880/com.xxx.XxxService?version=2.0.0&group=test"); URL providerUrl = URL.valueOf("http://127.0.0.1:8080/com.xxx.XxxService?version=1.0.0&group=test"); assertFalse(UrlUtils.isMatch(consumerUrl, providerUrl)); }