Skip to content
Permalink
Browse files
Merge pull request #1873, support proxy for provider side.
fixes #67
  • Loading branch information
jerrick-zhu authored and chickenlj committed Jun 1, 2018
1 parent e1171fa commit f4c210b6d6846cc72f92997b52c3dd4c563347be
Showing 4 changed files with 61 additions and 1 deletion.
@@ -500,6 +500,13 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
if (logger.isInfoEnabled()) {
logger.info("Register dubbo service " + interfaceClass.getName() + " url " + url + " to registry " + registryURL);
}

// For providers, this is used to enable custom proxy to generate invoker
String proxy = url.getParameter(Constants.PROXY_KEY);
if (StringUtils.isNotEmpty(proxy)) {
registryURL = registryURL.addParameter(Constants.PROXY_KEY, proxy);
}

Invoker<?> invoker = proxyFactory.getInvoker(ref, (Class) interfaceClass, registryURL.addParameterAndEncoded(Constants.EXPORT_KEY, url.toFullString()));
DelegateProviderMetaDataInvoker wrapperInvoker = new DelegateProviderMetaDataInvoker(invoker, this);

@@ -21,6 +21,7 @@
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.config.api.DemoService;
import com.alibaba.dubbo.config.api.Greeting;
import com.alibaba.dubbo.config.mock.TestProxyFactory;
import com.alibaba.dubbo.config.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.config.mock.MockProtocol2;
import com.alibaba.dubbo.config.mock.MockRegistryFactory2;
@@ -45,6 +46,7 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.withSettings;

@@ -53,6 +55,7 @@ public class ServiceConfigTest {
private Registry registryDelegate = Mockito.mock(Registry.class);
private Exporter exporter = Mockito.mock(Exporter.class);
private ServiceConfig<DemoServiceImpl> service = new ServiceConfig<DemoServiceImpl>();
private ServiceConfig<DemoServiceImpl> service2 = new ServiceConfig<DemoServiceImpl>();


@Before
@@ -87,6 +90,14 @@ public void setUp() throws Exception {
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setMethods(Collections.singletonList(method));

service2.setProvider(provider);
service2.setApplication(app);
service2.setRegistry(registry);
service2.setInterface(DemoService.class);
service2.setRef(new DemoServiceImpl());
service2.setMethods(Collections.singletonList(method));
service2.setProxy("testproxyfactory");
}

@Test
@@ -112,6 +123,14 @@ public void testExport() throws Exception {
Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class));
}

@Test
public void testProxy() throws Exception {
service2.export();

assertThat(service2.getExportedUrls(), hasSize(1));
assertEquals(2, TestProxyFactory.count); // local injvm and registry protocol, so expected is 2
}

@Test
@Ignore("cannot pass in travis")
public void testUnexport() throws Exception {
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.dubbo.config.mock;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.proxy.jdk.JdkProxyFactory;

public class TestProxyFactory extends JdkProxyFactory {
public static int count = 0;

@Override
public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws RpcException {
count++;
return super.getInvoker(proxy, type, url);
}
}
@@ -1 +1,2 @@
mockproxyfactory=com.alibaba.dubbo.config.mock.MockProxyFactory
mockproxyfactory=com.alibaba.dubbo.config.mock.MockProxyFactory
testproxyfactory=com.alibaba.dubbo.config.mock.TestProxyFactory

0 comments on commit f4c210b

Please sign in to comment.