This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e3eee7c9 RATIS-2069. RaftMetaConf command sets incorrect peerAddress 
pattern. (#1075)
4e3eee7c9 is described below

commit 4e3eee7c9f603d89b701921c3ab877134b342f0e
Author: Sadanand Shenoy <[email protected]>
AuthorDate: Sat May 4 00:10:53 2024 +0530

    RATIS-2069. RaftMetaConf command sets incorrect peerAddress pattern. (#1075)
---
 .../org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java | 2 +-
 .../apache/ratis/shell/cli/sh/LocalCommandIntegrationTest.java   | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git 
a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java
 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java
index 9f0558c5e..e258d863b 100644
--- 
a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java
+++ 
b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java
@@ -91,7 +91,7 @@ public class RaftMetaConfCommand extends AbstractCommand {
       }
       InetSocketAddress inetSocketAddress = parseInetSocketAddress(
           peerIdWithAddressArray[peerIdWithAddressArray.length - 1]);
-      String addressString = inetSocketAddress.toString();
+      String addressString = inetSocketAddress.getHostString() + ":" + 
inetSocketAddress.getPort();
       if (addresses.contains(addressString)) {
         printf("Found duplicated address: %s. Please make sure the address of 
peer have no duplicated value.",
             addressString);
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/LocalCommandIntegrationTest.java
 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/LocalCommandIntegrationTest.java
index 4a07e372c..a85c247d6 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/LocalCommandIntegrationTest.java
+++ 
b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/LocalCommandIntegrationTest.java
@@ -78,11 +78,11 @@ public class LocalCommandIntegrationTest {
     int index = 1;
     generateRaftConf(tempDir.resolve(RAFT_META_CONF), index);
 
-     String[] testPeersListArray = 
{"peer1_ID|host1:9872,peer2_ID|host2:9872,peer3_ID|host3:9872",
+     String[] testPeersListArray = 
{"peer1_ID|localhost:9872,peer2_ID|host2:9872,peer3_ID|host3:9872",
       "host1:9872,host2:9872,host3:9872"};
 
     for (String peersListStr : testPeersListArray) {
-      generateRaftConf(tempDir, index);
+      generateRaftConf(tempDir.resolve(RAFT_META_CONF), index);
       StringPrintStream out = new StringPrintStream();
       RatisShell shell = new RatisShell(out.getPrintStream());
       int ret = shell.run("local", "raftMetaConf", "-peers", peersListStr, 
"-path", tempDir.toString());
@@ -99,6 +99,11 @@ public class LocalCommandIntegrationTest {
 
       Assertions.assertEquals(index + 1, indexFromNewConf);
 
+      String addressRegex = "^[a-zA-Z0-9.-]+:\\d+$";
+      Pattern pattern = Pattern.compile(addressRegex);
+      peers.forEach(p -> Assertions.assertTrue(
+          pattern.matcher(p.getAddress()).matches()));
+
       String peersListStrFromNewMetaConf;
       if (containsPeerId(peersListStr)) {
         peersListStrFromNewMetaConf = peers.stream()

Reply via email to