Skip to content

Commit

Permalink
support proxy for provider side. apache#67
Browse files Browse the repository at this point in the history
  • Loading branch information
diecui1202 committed Jun 1, 2018
1 parent 286fb12 commit 3c14399
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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);
}
}
Original file line number Diff line number Diff line change
@@ -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 3c14399

Please sign in to comment.