From 581a20351f50a1e045babd3a1115c365ff55d7a0 Mon Sep 17 00:00:00 2001 From: Bela Ban Date: Fri, 4 Aug 2023 17:46:34 +0200 Subject: [PATCH] Fixed getSiteNames(): returning duplicates by using a list instead of a set --- src/org/jgroups/protocols/relay/RELAY.java | 2 +- src/org/jgroups/protocols/relay/RELAY2.java | 2 +- src/org/jgroups/protocols/relay/Relayer.java | 9 +++------ .../org/jgroups/tests/BaseLeaveTest.java | 2 +- .../org/jgroups/tests/RelayRpcDispatcherTest.java | 10 +++++----- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/org/jgroups/protocols/relay/RELAY.java b/src/org/jgroups/protocols/relay/RELAY.java index d31abf0464b..1f67610fb1a 100644 --- a/src/org/jgroups/protocols/relay/RELAY.java +++ b/src/org/jgroups/protocols/relay/RELAY.java @@ -223,7 +223,7 @@ public Route getRoute(String site_name) { * @return A {@link List} of sites name that are currently up or {@code null} if this node is not a Site Master (i.e. * {@link #isSiteMaster()} returns false). */ - public List getCurrentSites() { + public Collection getCurrentSites() { Relayer rel=relayer; return rel == null ? null : rel.getSiteNames(); } diff --git a/src/org/jgroups/protocols/relay/RELAY2.java b/src/org/jgroups/protocols/relay/RELAY2.java index 70ebede7188..9510618d3b0 100644 --- a/src/org/jgroups/protocols/relay/RELAY2.java +++ b/src/org/jgroups/protocols/relay/RELAY2.java @@ -477,7 +477,7 @@ protected void startRelayer(Relayer2 rel, String bridge_name) { protected String _printTopology(Relayer rel) { Map local_sitemasters=new HashMap<>(); - List all_sites=rel.getSiteNames(); + Collection all_sites=rel.getSiteNames(); List> topo_reqs=new ArrayList<>(); for(String site_name: all_sites) { Route r=rel.getRoute(site_name); diff --git a/src/org/jgroups/protocols/relay/Relayer.java b/src/org/jgroups/protocols/relay/Relayer.java index 1bcc279106d..af7a1d4fb79 100644 --- a/src/org/jgroups/protocols/relay/Relayer.java +++ b/src/org/jgroups/protocols/relay/Relayer.java @@ -5,10 +5,7 @@ import org.jgroups.logging.Log; import org.jgroups.util.Util; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; import java.util.stream.Collectors; @@ -110,9 +107,9 @@ protected synchronized Route getForwardingRouteMatching(String site, Address sen return null; } - protected List getSiteNames() { + protected Collection getSiteNames() { return Stream.concat(Stream.of(relay.site()), routes.keySet().stream()) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); } protected static boolean isExcluded(Route route, String... excluded_sites) { diff --git a/tests/junit-functional/org/jgroups/tests/BaseLeaveTest.java b/tests/junit-functional/org/jgroups/tests/BaseLeaveTest.java index 984e3da65ad..7eb3c569b1a 100644 --- a/tests/junit-functional/org/jgroups/tests/BaseLeaveTest.java +++ b/tests/junit-functional/org/jgroups/tests/BaseLeaveTest.java @@ -280,7 +280,7 @@ protected boolean checkQueue() { System.out.printf("-- sorted requests from %s to: %s\n", requests, l); requests.clear(); requests.addAll(l); - process(requests); + process(); } return false; } diff --git a/tests/junit-functional/org/jgroups/tests/RelayRpcDispatcherTest.java b/tests/junit-functional/org/jgroups/tests/RelayRpcDispatcherTest.java index 8513115b74e..6fa670f1a8e 100644 --- a/tests/junit-functional/org/jgroups/tests/RelayRpcDispatcherTest.java +++ b/tests/junit-functional/org/jgroups/tests/RelayRpcDispatcherTest.java @@ -269,16 +269,16 @@ protected static Route getRoute(JChannel ch, String site_name) { return relay.getRoute(site_name); } - protected List getCurrentSites(JChannel channel) { + protected static Collection getCurrentSites(JChannel channel) { RELAY relay=channel.getProtocolStack().findProtocol(RELAY.class); return relay.getCurrentSites(); } - protected void assertSiteView(JChannel channel, Collection sitesName) { - List sites = getCurrentSites(channel); + protected static void assertSiteView(JChannel channel, Collection siteNames) { + Collection sites=getCurrentSites(channel); assert sites != null; - assert sites.size() == sitesName.size(); - for (String site : sitesName) + assert sites.size() == siteNames.size(); + for(String site: siteNames) assert sites.contains(site); }