Skip to content

Commit 9d7c7b6

Browse files
committed
fix
1 parent 798e656 commit 9d7c7b6

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

integration-test/src/test/java/org/apache/iotdb/pipe/it/single/IoTDBPipeOPCUAIT.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.junit.Test;
4949
import org.junit.experimental.categories.Category;
5050
import org.junit.runner.RunWith;
51+
import org.slf4j.Logger;
52+
import org.slf4j.LoggerFactory;
5153

5254
import java.io.File;
5355
import java.net.ConnectException;
@@ -63,8 +65,11 @@
6365
@RunWith(IoTDBTestRunner.class)
6466
@Category({MultiClusterIT1.class})
6567
public class IoTDBPipeOPCUAIT extends AbstractPipeSingleIT {
68+
private static final Logger logger = LoggerFactory.getLogger(IoTDBPipeOPCUAIT.class);
69+
6670
@Test
6771
public void testOPCUAServerSink() throws Exception {
72+
int tcpPort = -1;
6873
try (final SyncConfigNodeIServiceClient client =
6974
(SyncConfigNodeIServiceClient) env.getLeaderConfigNodeConnection()) {
7075

@@ -80,7 +85,7 @@ public void testOPCUAServerSink() throws Exception {
8085
DataValue value;
8186
while (true) {
8287
final int[] ports = EnvUtils.searchAvailablePorts();
83-
final int tcpPort = ports[0];
88+
tcpPort = ports[0];
8489
final int httpsPort = ports[1];
8590
sinkAttributes.put("tcp.port", Integer.toString(tcpPort));
8691
sinkAttributes.put("https.port", Integer.toString(httpsPort));
@@ -102,6 +107,10 @@ public void testOPCUAServerSink() throws Exception {
102107
if (e.getCause() instanceof ConnectException) {
103108
continue;
104109
} else {
110+
final String lockPath = EnvUtils.getLockFilePath(tcpPort);
111+
if (!new File(lockPath).delete()) {
112+
logger.error("Delete lock file {} failed", lockPath);
113+
}
105114
throw e;
106115
}
107116
}
@@ -115,7 +124,7 @@ public void testOPCUAServerSink() throws Exception {
115124

116125
while (true) {
117126
final int[] ports = EnvUtils.searchAvailablePorts();
118-
final int tcpPort = ports[0];
127+
tcpPort = ports[0];
119128
final int httpsPort = ports[1];
120129
sinkAttributes.put("tcp.port", Integer.toString(tcpPort));
121130
sinkAttributes.put("https.port", Integer.toString(httpsPort));
@@ -204,11 +213,12 @@ public void testOPCUAServerSink() throws Exception {
204213
.getCode());
205214

206215
// Banned none, only allows basic256sha256
216+
final int finalTcpPort = tcpPort;
207217
Assert.assertThrows(
208218
PipeException.class,
209219
() ->
210220
getOpcUaClient(
211-
"opc.tcp://127.0.0.1:" + tcpPort + "/iotdb",
221+
"opc.tcp://127.0.0.1:" + finalTcpPort + "/iotdb",
212222
SecurityPolicy.None,
213223
"root",
214224
"root"));
@@ -224,6 +234,13 @@ public void testOPCUAServerSink() throws Exception {
224234
"org.apache.iotdb.jdbc.IoTDBSQLException: 1107: The existing server with tcp port 12686 and https port 8443's password **** conflicts to the new password ****, reject reusing.",
225235
e.getMessage());
226236
}
237+
} finally {
238+
if (tcpPort >= 0) {
239+
final String lockPath = EnvUtils.getLockFilePath(tcpPort);
240+
if (!new File(lockPath).delete()) {
241+
logger.error("Delete lock file {} failed", lockPath);
242+
}
243+
}
227244
}
228245
}
229246

0 commit comments

Comments
 (0)