Skip to content

Commit

Permalink
fix: trim peer str (#1115)
Browse files Browse the repository at this point in the history
* 去除空格

* Update ConfigurationTest.java

* tests: fix test, remove unused equals

---------

Co-authored-by: fangtiecheng <[email protected]>
  • Loading branch information
mindfocus and fangtiecheng authored Jun 25, 2024
1 parent aefb594 commit a71fae7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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))) {
if (isLearner) {
addLearner(peer);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ 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());
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)));
}

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

0 comments on commit a71fae7

Please sign in to comment.