Skip to content

Commit 5561e0a

Browse files
elbinpallimalilibmtdcmeehan
authored andcommitted
Initialize server port when initializing the test class instead of constructor
1 parent 48bd9f8 commit 5561e0a

File tree

6 files changed

+14
-39
lines changed

6 files changed

+14
-39
lines changed

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/ArrowFlightQueryRunner.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.io.File;
2929
import java.io.IOException;
30+
import java.net.InetSocketAddress;
3031
import java.net.ServerSocket;
3132
import java.net.URI;
3233
import java.util.Map;
@@ -49,7 +50,9 @@ private ArrowFlightQueryRunner()
4950
public static int findUnusedPort()
5051
throws IOException
5152
{
52-
try (ServerSocket socket = new ServerSocket(0)) {
53+
try (ServerSocket socket = new ServerSocket()) {
54+
socket.setReuseAddress(false);
55+
socket.bind(new InetSocketAddress(0));
5356
return socket.getLocalPort();
5457
}
5558
}

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightEchoQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,13 @@ public class TestArrowFlightEchoQueries
113113
{
114114
private static final Logger logger = Logger.get(TestArrowFlightEchoQueries.class);
115115
private static final CallOption CALL_OPTIONS = CallOptions.timeout(300, TimeUnit.SECONDS);
116-
private final int serverPort;
116+
private int serverPort;
117117
private RootAllocator allocator;
118118
private FlightServer server;
119119
private DistributedQueryRunner arrowFlightQueryRunner;
120120
private JsonCodec<TestingArrowFlightRequest> requestCodec;
121121
private JsonCodec<TestingArrowFlightResponse> responseCodec;
122122

123-
public TestArrowFlightEchoQueries()
124-
throws IOException
125-
{
126-
this.serverPort = ArrowFlightQueryRunner.findUnusedPort();
127-
}
128-
129123
@BeforeClass
130124
public void setup()
131125
throws Exception
@@ -161,6 +155,7 @@ public void close()
161155
protected QueryRunner createQueryRunner()
162156
throws Exception
163157
{
158+
serverPort = ArrowFlightQueryRunner.findUnusedPort();
164159
return ArrowFlightQueryRunner.createQueryRunner(serverPort);
165160
}
166161

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightIntegrationSmokeTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,16 @@
2626
import org.testng.annotations.BeforeClass;
2727

2828
import java.io.File;
29-
import java.io.IOException;
3029

3130
public class TestArrowFlightIntegrationSmokeTest
3231
extends AbstractTestIntegrationSmokeTest
3332
{
3433
private static final Logger logger = Logger.get(TestArrowFlightIntegrationSmokeTest.class);
35-
private final int serverPort;
34+
private int serverPort;
3635
private RootAllocator allocator;
3736
private FlightServer server;
3837
private DistributedQueryRunner arrowFlightQueryRunner;
3938

40-
public TestArrowFlightIntegrationSmokeTest()
41-
throws IOException
42-
{
43-
this.serverPort = ArrowFlightQueryRunner.findUnusedPort();
44-
}
45-
4639
@BeforeClass
4740
public void setup()
4841
throws Exception
@@ -65,6 +58,7 @@ public void setup()
6558
protected QueryRunner createQueryRunner()
6659
throws Exception
6760
{
61+
serverPort = ArrowFlightQueryRunner.findUnusedPort();
6862
return ArrowFlightQueryRunner.createQueryRunner(serverPort);
6963
}
7064

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightMtls.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.testng.annotations.Test;
2828

2929
import java.io.File;
30-
import java.io.IOException;
3130
import java.util.Map;
3231
import java.util.Optional;
3332

@@ -37,20 +36,14 @@ public class TestArrowFlightMtls
3736
extends AbstractTestQueryFramework
3837
{
3938
private static final Logger logger = Logger.get(TestArrowFlightMtls.class);
40-
private final int serverPort;
39+
private int serverPort;
4140
private RootAllocator allocator;
4241
private FlightServer server;
4342
private DistributedQueryRunner arrowFlightQueryRunner;
4443
private static final String ARROW_FLIGHT_CATALOG_WITH_INVALID_CERT = "arrow_catalog_with_invalid_cert";
4544
private static final String ARROW_FLIGHT_CATALOG_WITH_NO_MTLS_CERTS = "arrow_catalog_with_no_mtls_certs";
4645
private static final String ARROW_FLIGHT_CATALOG_WITH_MTLS_CERTS = "arrow_catalog_with_mtls_certs";
4746

48-
public TestArrowFlightMtls()
49-
throws IOException
50-
{
51-
this.serverPort = ArrowFlightQueryRunner.findUnusedPort();
52-
}
53-
5447
@BeforeClass
5548
private void setup()
5649
throws Exception
@@ -89,6 +82,7 @@ private void tearDown()
8982
protected QueryRunner createQueryRunner()
9083
throws Exception
9184
{
85+
serverPort = ArrowFlightQueryRunner.findUnusedPort();
9286
return ArrowFlightQueryRunner.createQueryRunner(serverPort, ImmutableMap.of(), ImmutableMap.of(), Optional.empty(), Optional.empty());
9387
}
9488

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightNativeQueries.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@ public class TestArrowFlightNativeQueries
4949
extends AbstractTestQueryFramework
5050
{
5151
private static final Logger log = Logger.get(TestArrowFlightNativeQueries.class);
52-
private final int serverPort;
52+
private int serverPort;
5353
private RootAllocator allocator;
5454
private FlightServer server;
5555
private DistributedQueryRunner arrowFlightQueryRunner;
5656

57-
public TestArrowFlightNativeQueries()
58-
throws IOException
59-
{
60-
this.serverPort = ArrowFlightQueryRunner.findUnusedPort();
61-
}
62-
6357
protected boolean ismTLSEnabled()
6458
{
6559
return false;
@@ -109,6 +103,7 @@ protected QueryRunner createQueryRunner()
109103

110104
ImmutableMap<String, String> coordinatorProperties = ImmutableMap.of("native-execution-enabled", "true");
111105

106+
serverPort = ArrowFlightQueryRunner.findUnusedPort();
112107
return ArrowFlightQueryRunner.createQueryRunner(
113108
serverPort,
114109
getNativeWorkerSystemProperties(),

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightQueries.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.testng.annotations.Test;
3030

3131
import java.io.File;
32-
import java.io.IOException;
3332
import java.time.LocalDate;
3433
import java.time.LocalDateTime;
3534
import java.time.LocalTime;
@@ -54,17 +53,11 @@ public class TestArrowFlightQueries
5453
extends AbstractTestQueries
5554
{
5655
private static final Logger logger = Logger.get(TestArrowFlightQueries.class);
57-
private final int serverPort;
56+
private int serverPort;
5857
private RootAllocator allocator;
5958
private FlightServer server;
6059
private DistributedQueryRunner arrowFlightQueryRunner;
6160

62-
public TestArrowFlightQueries()
63-
throws IOException
64-
{
65-
this.serverPort = ArrowFlightQueryRunner.findUnusedPort();
66-
}
67-
6861
@BeforeClass
6962
public void setup()
7063
throws Exception
@@ -96,6 +89,7 @@ public void close()
9689
protected QueryRunner createQueryRunner()
9790
throws Exception
9891
{
92+
serverPort = ArrowFlightQueryRunner.findUnusedPort();
9993
return ArrowFlightQueryRunner.createQueryRunner(serverPort);
10094
}
10195

0 commit comments

Comments
 (0)