Skip to content

Commit

Permalink
[fix][broker] Fix getFinalReplicatorDispatchRateMap
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
nodece committed Mar 6, 2025
1 parent 7dd7e00 commit 9cfe603
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -189,11 +190,11 @@ public Set<String> getReplicationClustersSet() {
*/
public Map<String, DispatchRateImpl> getFinalReplicatorDispatchRateMap(String currentCluster) {
if (replicatorDispatchRateMap.containsKey(currentCluster)) {
return replicatorDispatchRateMap;
return Collections.unmodifiableMap(replicatorDispatchRateMap);
} else {
Map<String, DispatchRateImpl> result = new HashMap<>(replicatorDispatchRateMap);
result.put(currentCluster, replicatorDispatchRate);
return result;
return Collections.unmodifiableMap(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void testGetReplicatorDispatchRateMap() {
// Put r1-cluster and dispatch rate to the map, and then check if the map includes that.
String r1ClusterName = currentClusterName;
DispatchRateImpl r1DispatchRate = DispatchRateImpl.builder().build();
topicPolicies.getFinalReplicatorDispatchRateMap(currentClusterName).put(r1ClusterName, r1DispatchRate);
topicPolicies.getReplicatorDispatchRateMap().put(r1ClusterName, r1DispatchRate);
result = topicPolicies.getFinalReplicatorDispatchRateMap(currentClusterName);
assertEquals(result.size(), 1);
assertEquals(result.get(r1ClusterName), r1DispatchRate);

// Put r2-cluster and dispatch rate to the map, and then check if the map includes that.
String r2ClusterName = "r2-cluster";
DispatchRateImpl r2DispatchRate = DispatchRateImpl.builder().build();
topicPolicies.getFinalReplicatorDispatchRateMap(currentClusterName).put(r2ClusterName, r2DispatchRate);
topicPolicies.getReplicatorDispatchRateMap().put(r2ClusterName, r2DispatchRate);
result = topicPolicies.getFinalReplicatorDispatchRateMap(currentClusterName);
assertEquals(result.size(), 2);
assertEquals(result.get(r2ClusterName), r2DispatchRate);
Expand Down

0 comments on commit 9cfe603

Please sign in to comment.