You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/07/12 09:58:23 UTC
[iotdb] branch jira6061_cp created (now bbfb33add54)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a change to branch jira6061_cp
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at bbfb33add54 finish
This branch includes the following new commits:
new bbfb33add54 finish
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[iotdb] 01/01: finish
Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch jira6061_cp
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit bbfb33add541e4af856f5fa1aff2026b3c2c6168
Author: OneSizeFitQuorum <ta...@apache.org>
AuthorDate: Wed Jul 12 16:33:38 2023 +0800
finish
Signed-off-by: OneSizeFitQuorum <ta...@apache.org>
---
.../apache/iotdb/consensus/iot/ReplicateTest.java | 27 +++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java b/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
index a36db6e3ea4..9e3f365673b 100644
--- a/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
+++ b/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
+import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -67,8 +68,8 @@ public class ReplicateTest {
@Before
public void setUp() throws Exception {
- for (int i = 0; i < 3; i++) {
- peersStorage.get(i).mkdirs();
+ for (File file : peersStorage) {
+ file.mkdirs();
stateMachines.add(new TestStateMachine());
}
initServer();
@@ -83,7 +84,10 @@ public class ReplicateTest {
}
private void initServer() throws IOException {
- for (int i = 0; i < 3; i++) {
+ for (Peer peer : peers) {
+ waitPortAvailable(peer.getEndpoint().port);
+ }
+ for (int i = 0; i < peers.size(); i++) {
int finalI = i;
servers.add(
(IoTConsensus)
@@ -244,4 +248,21 @@ public class ReplicateTest {
Assert.assertEquals(stateMachines.get(0).getData(), stateMachines.get(1).getData());
Assert.assertEquals(stateMachines.get(2).getData(), stateMachines.get(1).getData());
}
+
+ private static void waitPortAvailable(int port) {
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() - start < 60 * 1000) {
+ try (ServerSocket ignored = new ServerSocket(port)) {
+ return;
+ } catch (IOException e) {
+ // Port is already in use, wait and retry
+ try {
+ Thread.sleep(1000); // Wait for 1 second before retrying
+ } catch (InterruptedException ex) {
+ // Handle the interruption if needed
+ }
+ }
+ }
+ Assert.fail(String.format("can not bind port %d after 60s", port));
+ }
}