Skip to content

Commit

Permalink
fix compilation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
linxin committed Nov 20, 2024
1 parent 7123f00 commit 669860c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -79,18 +80,18 @@ public void setup() throws Exception {
assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0);
final List<PeerId> peers = TestUtils.generatePeers(3);

final LinkedHashSet<PeerId> learners = new LinkedHashSet<>();
final Map<PeerId, PeerId> learners = new ConcurrentHashMap<>();
//2 learners
for (int i = 0; i < 2; i++) {
learners.add(new PeerId(TestUtils.getMyIp(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i));
learners.put(new PeerId(TestUtils.getMyIp(), TestUtils.INIT_PORT + LEARNER_PORT_STEP + i), Configuration.NULL_PEERID);
}

this.cluster = new TestCluster(this.groupId, this.dataPath, peers, learners, 300);
for (final PeerId peer : peers) {
this.cluster.start(peer.getEndpoint());
}

for (final PeerId peer : learners) {
for (final PeerId peer : learners.keySet()) {
this.cluster.startLearner(peer);
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public void testLearnerServices() throws Exception {
}
}
assertEquals(0, this.cluster.getFsmByPeer(learner3).getLogs().size());
List<PeerId> oldLearners = new ArrayList<PeerId>(this.conf.getLearners());
List<PeerId> oldLearners = new ArrayList<>(this.conf.getLearners().keySet());
assertEquals(oldLearners, this.cliService.getLearners(this.groupId, this.conf));
assertEquals(oldLearners, this.cliService.getAliveLearners(this.groupId, this.conf));

Expand Down Expand Up @@ -279,7 +280,7 @@ public void testSnapshot() throws Exception {
for (final PeerId peer : this.conf) {
assertTrue(this.cliService.snapshot(this.groupId, peer).isOk());
}
for (final PeerId peer : this.conf.getLearners()) {
for (final PeerId peer : this.conf.getLearners().keySet()) {
assertTrue(this.cliService.snapshot(this.groupId, peer).isOk());
}
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -87,13 +88,13 @@ public synchronized List<TestCluster> removeAll() {
private final int electionTimeoutMs;
private final Lock lock = new ReentrantLock();

private LinkedHashSet<PeerId> learners;
private Map<PeerId, PeerId> learners;

public LinkedHashSet<PeerId> getLearners() {
public Map<PeerId, PeerId> getLearners() {
return this.learners;
}

public void setLearners(final LinkedHashSet<PeerId> learners) {
public void setLearners(final Map<PeerId, PeerId> learners) {
this.learners = learners;
}

Expand All @@ -106,11 +107,11 @@ public TestCluster(final String name, final String dataPath, final List<PeerId>
}

public TestCluster(final String name, final String dataPath, final List<PeerId> peers, final int electionTimeoutMs) {
this(name, dataPath, peers, new LinkedHashSet<>(), 300);
this(name, dataPath, peers, new ConcurrentHashMap<>(), 300);
}

public TestCluster(final String name, final String dataPath, final List<PeerId> peers,
final LinkedHashSet<PeerId> learners, final int electionTimeoutMs) {
final Map<PeerId, PeerId> learners, final int electionTimeoutMs) {
super();
this.name = name;
this.dataPath = dataPath;
Expand All @@ -131,7 +132,7 @@ public boolean start(final Endpoint addr, final int priority) throws Exception {
}

public boolean startLearner(final PeerId peer) throws Exception {
this.learners.add(peer);
this.learners.put(peer, Configuration.NULL_PEERID);
return this.start(peer.getEndpoint(), false, 300);
}

Expand Down Expand Up @@ -338,7 +339,7 @@ public List<Node> getFollowers() {
this.lock.lock();
try {
for (final NodeImpl node : this.nodes) {
if (!node.isLeader() && !this.learners.contains(node.getServerId())) {
if (!node.isLeader() && !this.learners.containsKey(node.getServerId())) {
ret.add(node);
}
}
Expand Down

0 comments on commit 669860c

Please sign in to comment.