Skip to content

Commit

Permalink
Fix RegistryProtocol registerStatedUrl NPE. (apache#7610)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 authored and goodjava committed May 6, 2021
1 parent 9913af1 commit 55ab457
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ public String getUniqueServiceName() {
return URL.buildKey(interfaceName, getGroup(), getVersion());
}

@Override
public String getVersion() {
return StringUtils.isEmpty(this.version) ? (consumer != null ? consumer.getVersion() : this.version) : this.version;
}

@Override
public String getGroup() {
return StringUtils.isEmpty(this.group) ? (consumer != null ? consumer.getGroup() : this.group) : this.group;
}

public abstract T get();

public abstract void destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,15 @@ public String getUniqueServiceName() {
return URL.buildKey(interfaceName, getGroup(), getVersion());
}

@Override
public String getGroup() {
return StringUtils.isEmpty(this.group) ? (provider != null ? provider.getGroup() : this.group) : this.group;
}

@Override
public String getVersion() {
return StringUtils.isEmpty(this.version) ? (provider != null ? provider.getVersion() : this.version) : this.version;
}

@Override
protected void computeValidRegistryIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.config.Constants.SHUTDOWN_TIMEOUT_KEY;
import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY;
import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
Expand Down Expand Up @@ -154,6 +156,23 @@ public void testExport() throws Exception {
Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class));
}

@Test
public void testVersionAndGroupConfigFromProvider() {
//Service no configuration version , the Provider configured.
service.getProvider().setVersion("1.0.0");
service.getProvider().setGroup("groupA");
service.export();

String serviceVersion = service.getVersion();
String serviceVersion2 = service.toUrl().getParameter(VERSION_KEY);

String group = service.getGroup();
String group2 = service.toUrl().getParameter(GROUP_KEY);

assertEquals(serviceVersion2, serviceVersion);
assertEquals(group, group2);
}

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

0 comments on commit 55ab457

Please sign in to comment.