Skip to content

Commit

Permalink
[Dubbo-3106]Make getRegistered return unmodifiable collection. #3106 (#…
Browse files Browse the repository at this point in the history
…3425)

* make getRegistered return unmodifiable collection. #3106

* fix ci failure
  • Loading branch information
kezhenxu94 authored and CrazyHZM committed Feb 21, 2019
1 parent 112ad0c commit a40c2f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Expand Up @@ -37,6 +37,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -118,15 +119,15 @@ protected void setUrl(URL url) {
}

public Set<URL> getRegistered() {
return registered;
return Collections.unmodifiableSet(registered);
}

public Map<URL, Set<NotifyListener>> getSubscribed() {
return subscribed;
return Collections.unmodifiableMap(subscribed);
}

public Map<URL, Map<String, List<URL>>> getNotified() {
return notified;
return Collections.unmodifiableMap(notified);
}

public File getCacheFile() {
Expand Down
Expand Up @@ -96,7 +96,9 @@ public void testRegister() throws Exception {
abstractRegistry.register(mockUrl);
assert abstractRegistry.getRegistered().contains(mockUrl);
//test multiple urls
abstractRegistry.getRegistered().clear();
for (URL url : abstractRegistry.getRegistered()) {
abstractRegistry.unregister(url);
}
List<URL> urlList = getList();
for (URL url : urlList) {
abstractRegistry.register(url);
Expand All @@ -122,14 +124,16 @@ public void testRegisterIfURLNULL() throws Exception {
public void testUnregister() throws Exception {
//test one unregister
URL url = new URL("dubbo", "192.168.0.1", 2200);
abstractRegistry.getRegistered().add(url);
abstractRegistry.register(url);
abstractRegistry.unregister(url);
MatcherAssert.assertThat(false, Matchers.equalTo(abstractRegistry.getRegistered().contains(url)));
//test multiple unregisters
abstractRegistry.getRegistered().clear();
for (URL u : abstractRegistry.getRegistered()) {
abstractRegistry.unregister(u);
}
List<URL> urlList = getList();
for (URL urlSub : urlList) {
abstractRegistry.getRegistered().add(urlSub);
abstractRegistry.register(urlSub);
}
for (URL urlSub : urlList) {
abstractRegistry.unregister(urlSub);
Expand Down
Expand Up @@ -92,7 +92,9 @@ public void testRegister() {
Set<URL> registered;
// clear first
registered = registry.getRegistered();
registered.clear();
for (URL url : registered) {
registry.unregister(url);
}

for (int i = 0; i < 2; i++) {
registry.register(serviceUrl);
Expand Down

0 comments on commit a40c2f8

Please sign in to comment.