Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo-3106]Make getRegistered return unmodifiable collection. #3106 #3425

Merged
merged 2 commits into from Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,6 +38,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 @@ -119,15 +120,15 @@ protected void setUrl(URL url) {
}

public Set<URL> getRegistered() {
return registered;
return Collections.unmodifiableSet(registered);
kezhenxu94 marked this conversation as resolved.
Show resolved Hide resolved
}

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