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

fix: trim peer str #1115

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public boolean parse(final String conf) {
peerStr = peerStr.substring(0, index);
isLearner = true;
}
if (peer.parse(peerStr)) {
if (peer.parse(StringUtils.trim(peerStr))) {
mindfocus marked this conversation as resolved.
Show resolved Hide resolved
if (isLearner) {
addLearner(peer);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ public void testToStringParseEmpty() {
assertEquals(conf, newConf);
}

@Test
public void testToStringParseWithSpace() {
final String confStr = "localhost:8081, localhost:8082, localhost:8083";
final Configuration conf = JRaftUtils.getConfiguration(confStr);
assertEquals(3, conf.size());
for (final PeerId peer : conf) {
assertTrue(peer.toString().startsWith("localhost:80"));
}
assertFalse(conf.isEmpty());
assertEquals(confStr, conf.toString());
final Configuration newConf = new Configuration();
assertTrue(newConf.parse(conf.toString()));
assertEquals(3, newConf.getPeerSet().size());
assertTrue(newConf.contains(new PeerId("localhost", 8081)));
assertTrue(newConf.contains(new PeerId("localhost", 8082)));
assertTrue(newConf.contains(new PeerId("localhost", 8083)));
assertEquals(confStr, newConf.toString());
assertEquals(conf.hashCode(), newConf.hashCode());
assertEquals(conf, newConf);
}

@Test
public void testToStringParseStuff() {
final String confStr = "localhost:8081,localhost:8082,localhost:8083";
Expand Down
Loading