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

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


The following commit(s) were added to refs/heads/master by this push:
     new ee8b308d922 Fix resetPeerListTest for unstable port binding #15038
ee8b308d922 is described below

commit ee8b308d922b2179c215fc829cb1972bf7213743
Author: Li Yu Heng <[email protected]>
AuthorDate: Fri Mar 7 16:41:43 2025 +0800

    Fix resetPeerListTest for unstable port binding #15038
---
 .../apache/iotdb/consensus/iot/StabilityTest.java  | 49 ++++++++++++++++++----
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git 
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/StabilityTest.java
 
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/StabilityTest.java
index 9fcbf9e03f1..5147632431f 100644
--- 
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/StabilityTest.java
+++ 
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/StabilityTest.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
 import org.apache.iotdb.common.rpc.thrift.TEndPoint;
 import org.apache.iotdb.commons.consensus.ConsensusGroupId;
 import org.apache.iotdb.commons.consensus.DataRegionId;
+import org.apache.iotdb.commons.exception.StartupException;
 import org.apache.iotdb.consensus.ConsensusFactory;
 import org.apache.iotdb.consensus.common.Peer;
 import org.apache.iotdb.consensus.config.ConsensusConfig;
@@ -38,6 +39,8 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -51,6 +54,8 @@ import static org.junit.Assert.assertTrue;
 
 public class StabilityTest {
 
+  private static Logger LOGGER = LoggerFactory.getLogger(StabilityTest.class);
+
   private final ConsensusGroupId dataRegionId = new DataRegionId(1);
 
   private final File storageDir = new File("target" + java.io.File.separator + 
"stability");
@@ -237,25 +242,53 @@ public class StabilityTest {
     peerList1And2.add(new Peer(dataRegionId, 2, new TEndPoint("0.0.0.0", 
basePort)));
     correctPeers.put(dataRegionId, peerList1And2);
     consensusImpl.recordCorrectPeerListBeforeStarting(correctPeers);
-    consensusImpl.start();
-    Assert.assertEquals(2, 
consensusImpl.getImpl(dataRegionId).getConfiguration().size());
-    consensusImpl.stop();
+    try {
+      consensusImpl.start();
+      Assert.assertEquals(2, 
consensusImpl.getImpl(dataRegionId).getConfiguration().size());
+      consensusImpl.stop();
+    } catch (IOException e) {
+      if (e.getCause() instanceof StartupException) {
+        LOGGER.info("Cannot start IoTConsensus because", e);
+      } else {
+        LOGGER.error("Failed because", e);
+        Assert.fail(e.getMessage());
+      }
+    }
 
     // test remove sync channel
     List<Peer> peerList1 = new ArrayList<>();
     peerList1.add(new Peer(dataRegionId, 1, new TEndPoint("0.0.0.0", 
basePort)));
     correctPeers.put(dataRegionId, peerList1);
     consensusImpl.recordCorrectPeerListBeforeStarting(correctPeers);
-    consensusImpl.start();
-    Assert.assertEquals(1, 
consensusImpl.getImpl(dataRegionId).getConfiguration().size());
-    consensusImpl.stop();
+    try {
+      consensusImpl.start();
+      Assert.assertEquals(1, 
consensusImpl.getImpl(dataRegionId).getConfiguration().size());
+      consensusImpl.stop();
+    } catch (IOException e) {
+      if (e.getCause() instanceof StartupException) {
+        LOGGER.info("Cannot start IoTConsensus because", e);
+      } else {
+        LOGGER.error("Failed because", e);
+        Assert.fail(e.getMessage());
+      }
+    }
 
     // test remove invalid peer
     List<Peer> peerList2 = new ArrayList<>();
     peerList2.add(new Peer(dataRegionId, 2, new TEndPoint("0.0.0.0", 
basePort)));
     correctPeers.put(dataRegionId, peerList2);
     consensusImpl.recordCorrectPeerListBeforeStarting(correctPeers);
-    consensusImpl.start();
-    Assert.assertNull(consensusImpl.getImpl(dataRegionId));
+    try {
+      consensusImpl.start();
+      Assert.assertNull(consensusImpl.getImpl(dataRegionId));
+      consensusImpl.stop();
+    } catch (IOException e) {
+      if (e.getCause() instanceof StartupException) {
+        LOGGER.info("Cannot start IoTConsensus because", e);
+      } else {
+        LOGGER.error("Failed because", e);
+        Assert.fail(e.getMessage());
+      }
+    }
   }
 }

Reply via email to