This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 06f28d206e GH-32954: [Java][FlightRPC] Remove
FlightTestUtil#getStartedServer and bind to port 0 directly (#34357)
06f28d206e is described below
commit 06f28d206ed5ec60750e353d99062f83e47cd0a7
Author: rtadepalli <[email protected]>
AuthorDate: Mon Feb 27 08:34:37 2023 -0500
GH-32954: [Java][FlightRPC] Remove FlightTestUtil#getStartedServer and bind
to port 0 directly (#34357)
### Rationale for this change
Today, the `FlightServer` is created in `FlightTestUtil#getStartedServer`.
All tests that need a server go through this function, but this is unnecessary
since the server could directly be started on port 0 (the OS will assign a
random port later).
### What changes are included in this PR?
All invocations of `FlightTestUtil#getStartedServer` have been removed, and
the burden of generating a `Location` object for the server has been placed on
the caller.
### Are these changes tested?
Existing tests impacted were run locally to make sure that there no
regressions.
### Are there any user-facing changes?
There are no user facing changes. There are no breaking changes to the
public API as well.
@ lidavidm
* Closes: #32954
Authored-by: Ramasai <[email protected]>
Signed-off-by: David Li <[email protected]>
---
.../org/apache/arrow/flight/FlightTestUtil.java | 43 --------------------
.../arrow/flight/TestApplicationMetadata.java | 16 ++++----
.../java/org/apache/arrow/flight/TestAuth.java | 17 ++++----
.../org/apache/arrow/flight/TestBackPressure.java | 11 +++---
.../apache/arrow/flight/TestBasicOperation.java | 10 ++---
.../org/apache/arrow/flight/TestCallOptions.java | 9 +++--
.../apache/arrow/flight/TestClientMiddleware.java | 24 +++++------
.../org/apache/arrow/flight/TestErrorMetadata.java | 15 ++++---
.../org/apache/arrow/flight/TestFlightClient.java | 46 ++++++++++------------
.../org/apache/arrow/flight/TestLargeMessage.java | 11 +++---
.../java/org/apache/arrow/flight/TestLeak.java | 21 +++++-----
.../apache/arrow/flight/TestServerMiddleware.java | 12 +++---
.../org/apache/arrow/flight/TestServerOptions.java | 34 +++++++---------
.../test/java/org/apache/arrow/flight/TestTls.java | 17 +++-----
.../apache/arrow/flight/auth/TestBasicAuth.java | 10 +++--
.../apache/arrow/flight/auth2/TestBasicAuth2.java | 10 +++--
.../arrow/flight/client/TestCookieHandling.java | 12 +++---
.../arrow/flight/perf/PerformanceTestServer.java | 5 ++-
.../org/apache/arrow/flight/perf/TestPerf.java | 7 ++--
19 files changed, 142 insertions(+), 188 deletions(-)
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
index b50613311b..cbb714a967 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/FlightTestUtil.java
@@ -18,18 +18,14 @@
package org.apache.arrow.flight;
import java.io.File;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.net.ServerSocket;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Random;
-import java.util.function.Function;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;
@@ -44,45 +40,6 @@ public class FlightTestUtil {
public static final String TEST_DATA_ENV_VAR = "ARROW_TEST_DATA";
public static final String TEST_DATA_PROPERTY = "arrow.test.dataRoot";
- /**
- * Returns a a FlightServer (actually anything that is startable)
- * that has been started bound to a random port.
- */
- public static <T> T getStartedServer(Function<Location, T>
newServerFromLocation) throws IOException {
- IOException lastThrown = null;
- T server = null;
- for (int x = 0; x < 3; x++) {
- int port;
- try (final ServerSocket dynamicPortSocket = new ServerSocket(0)) {
- port = dynamicPortSocket.getLocalPort();
- } catch (SecurityException | IOException e) {
- throw new RuntimeException("Unable to create a ServerSocket instance.
", e);
- }
-
- final Location location = Location.forGrpcInsecure(LOCALHOST, port);
- lastThrown = null;
- try {
- server = newServerFromLocation.apply(location);
- try {
- server.getClass().getMethod("start").invoke(server);
- } catch (NoSuchMethodException | IllegalAccessException e) {
- throw new IllegalArgumentException("Couldn't call start method on
object.", e);
- }
- break;
- } catch (InvocationTargetException e) {
- if (e.getTargetException() instanceof IOException) {
- lastThrown = (IOException) e.getTargetException();
- } else {
- throw (RuntimeException) e.getTargetException();
- }
- }
- }
- if (lastThrown != null) {
- throw lastThrown;
- }
- return server;
- }
-
static Path getTestDataRoot() {
String path = System.getenv(TEST_DATA_ENV_VAR);
if (path == null) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java
index fb0345b134..07db301309 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestApplicationMetadata.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
@@ -204,10 +207,8 @@ public class TestApplicationMetadata {
public void testMetadataEndianness() throws Exception {
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Long.MAX_VALUE);
- final FlightServer server = FlightTestUtil.getStartedServer(
- (location) -> FlightServer
- .builder(serverAllocator, location, new
EndianFlightProducer(serverAllocator))
- .build());
+ final FlightServer server = FlightServer.builder(serverAllocator,
forGrpcInsecure(LOCALHOST, 0),
+ new EndianFlightProducer(serverAllocator)).build().start();
final FlightClient client = FlightClient.builder(allocator,
server.getLocation()).build()) {
final Schema schema = new Schema(Collections.emptyList());
final FlightDescriptor descriptor = FlightDescriptor.command(new
byte[0]);
@@ -228,10 +229,9 @@ public class TestApplicationMetadata {
private void test(BiConsumer<BufferAllocator, FlightClient> fun) {
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
- final FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(allocator, location, new
MetadataFlightProducer(allocator)).build());
- final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new MetadataFlightProducer(allocator)).build().start();
+ final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
fun.accept(allocator, client);
} catch (Exception e) {
throw new RuntimeException(e);
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestAuth.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestAuth.java
index 0da49c906f..1a38922010 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestAuth.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestAuth.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.Iterator;
import java.util.Optional;
@@ -34,10 +37,9 @@ public class TestAuth {
public void noMessages() throws Exception {
Assertions.assertThrows(RuntimeException.class, () -> {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final FlightServer s = FlightTestUtil
- .getStartedServer(
- location -> FlightServer.builder(allocator, location, new
NoOpFlightProducer()).authHandler(
- new OneshotAuthHandler()).build());
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new NoOpFlightProducer()).authHandler(
+ new OneshotAuthHandler()).build().start();
final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
client.authenticate(new ClientAuthHandler() {
@Override
@@ -58,10 +60,9 @@ public class TestAuth {
public void clientError() throws Exception {
Assertions.assertThrows(RuntimeException.class, () -> {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final FlightServer s = FlightTestUtil
- .getStartedServer(
- location -> FlightServer.builder(allocator, location, new
NoOpFlightProducer()).authHandler(
- new OneshotAuthHandler()).build());
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new NoOpFlightProducer()).authHandler(
+ new OneshotAuthHandler()).build().start();
final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
client.authenticate(new ClientAuthHandler() {
@Override
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java
index ae691f3ef9..7586d50c8e 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBackPressure.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
@@ -85,8 +88,7 @@ public class TestBackPressure {
serverConstructor) throws
Exception {
try (
final BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
- final PerformanceTestServer server = FlightTestUtil.getStartedServer(
- (location) -> (serverConstructor.apply(a).apply(location)));
+ final PerformanceTestServer server =
serverConstructor.apply(a).apply(forGrpcInsecure(LOCALHOST, 0)).start();
final FlightClient client = FlightClient.builder(a,
server.getLocation()).build()
) {
try (FlightStream fs1 = client.getStream(client.getInfo(
@@ -160,9 +162,8 @@ public class TestBackPressure {
try (
BufferAllocator serverAllocator =
allocator.newChildAllocator("server", 0, Long.MAX_VALUE);
- FlightServer server =
- FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(serverAllocator, location, producer)
- .build());
+ FlightServer server = FlightServer.builder(serverAllocator,
forGrpcInsecure(LOCALHOST, 0), producer)
+ .build().start();
BufferAllocator clientAllocator =
allocator.newChildAllocator("client", 0, Long.MAX_VALUE);
FlightClient client =
FlightClient
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java
index 0a1d7f8a3f..619f7d0d1b 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -113,7 +116,7 @@ public class TestBasicOperation {
new Ticket(new byte[10]),
Location.forGrpcDomainSocket("/tmp/test.sock")),
new FlightEndpoint(
new Ticket(new byte[10]),
Location.forGrpcDomainSocket("/tmp/test.sock"),
- Location.forGrpcInsecure("localhost", 50051))
+ forGrpcInsecure("localhost", 50051))
), 200, 500);
Assertions.assertEquals(info1, FlightInfo.deserialize(info1.serialize()));
@@ -318,10 +321,7 @@ public class TestBasicOperation {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
Producer producer = new Producer(a);
- FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(a, location,
producer).build()
- )) {
+ FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST,
0), producer).build().start()) {
try (
FlightClient c = FlightClient.builder(a, s.getLocation()).build()
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java
index adfa44ef9c..8b1a897467 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestCallOptions.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
@@ -101,8 +104,7 @@ public class TestCallOptions {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
HeaderProducer producer = new HeaderProducer();
- FlightServer s =
- FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(a, location, producer).build());
+ FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST,
0), producer).build().start();
FlightClient client = FlightClient.builder(a,
s.getLocation()).build()) {
Assertions.assertFalse(client.doAction(new Action(""), new
HeaderCallOption(headers)).hasNext());
final CallHeaders incomingHeaders = producer.headers();
@@ -122,8 +124,7 @@ public class TestCallOptions {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
Producer producer = new Producer();
- FlightServer s =
- FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(a, location, producer).build());
+ FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST,
0), producer).build().start();
FlightClient client = FlightClient.builder(a,
s.getLocation()).build()) {
testFn.accept(client);
} catch (InterruptedException | IOException e) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestClientMiddleware.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestClientMiddleware.java
index a191a597f4..bcff54bd7f 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestClientMiddleware.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestClientMiddleware.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -106,18 +109,17 @@ public class TestClientMiddleware {
List<FlightClientMiddleware.Factory> clientMiddleware,
BiConsumer<BufferAllocator, FlightClient> body) {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE)) {
- final FlightServer server = FlightTestUtil
- .getStartedServer(location -> {
- final FlightServer.Builder builder =
FlightServer.builder(allocator, location, producer);
- if (serverMiddleware != null) {
- builder.middleware(serverMiddleware.key,
serverMiddleware.factory);
- }
- return builder.build();
- });
- FlightClient.Builder builder = FlightClient.builder(allocator,
server.getLocation());
- clientMiddleware.forEach(builder::intercept);
+ final FlightServer.Builder serverBuilder =
+ FlightServer.builder(allocator, forGrpcInsecure(LOCALHOST, 0),
producer);
+ if (serverMiddleware != null) {
+ serverBuilder.middleware(serverMiddleware.key,
serverMiddleware.factory);
+ }
+ final FlightServer server = serverBuilder.build().start();
+
+ FlightClient.Builder clientBuilder = FlightClient.builder(allocator,
server.getLocation());
+ clientMiddleware.forEach(clientBuilder::intercept);
try (final FlightServer ignored = server;
- final FlightClient client = builder.build()
+ final FlightClient client = clientBuilder.build()
) {
body.accept(allocator, client);
}
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java
index 1f1bbbe50f..1987d98196 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestErrorMetadata.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import org.apache.arrow.flight.perf.impl.PerfOuterClass;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
@@ -46,11 +49,8 @@ public class TestErrorMetadata {
.build();
StatusRuntimeExceptionProducer producer = new
StatusRuntimeExceptionProducer(perf);
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
- final FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> {
- return FlightServer.builder(allocator, location,
producer).build();
- });
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0), producer).build()
+ .start();
final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
final CallStatus flightStatus =
FlightTestUtil.assertCode(FlightStatusCode.CANCELLED, () -> {
FlightStream stream = client.getStream(new Ticket("abs".getBytes()));
@@ -80,9 +80,8 @@ public class TestErrorMetadata {
@Test
public void testFlightMetadata() throws Exception {
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
- final FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(allocator, location, new
CallStatusProducer()).build());
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0), new CallStatusProducer())
+ .build().start();
final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
CallStatus flightStatus =
FlightTestUtil.assertCode(FlightStatusCode.INVALID_ARGUMENT, () -> {
FlightStream stream = client.getStream(new Ticket(new byte[0]));
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightClient.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightClient.java
index d6cc175b99..db05592ab3 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightClient.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestFlightClient.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
@@ -51,17 +54,15 @@ public class TestFlightClient {
@Test
public void independentShutdown() throws Exception {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final FlightServer server = FlightTestUtil.getStartedServer(
- location -> FlightServer.builder(allocator, location,
- new Producer(allocator)).build())) {
- final Location location =
Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, server.getPort());
+ final FlightServer server = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new Producer(allocator)).build().start()) {
final Schema schema = new
Schema(Collections.singletonList(Field.nullable("a", new ArrowType.Int(32,
true))));
- try (final FlightClient client1 = FlightClient.builder(allocator,
location).build();
- final VectorSchemaRoot root = VectorSchemaRoot.create(schema,
allocator)) {
+ try (final FlightClient client1 = FlightClient.builder(allocator,
server.getLocation()).build();
+ final VectorSchemaRoot root = VectorSchemaRoot.create(schema,
allocator)) {
// Use startPut as this ensures the RPC won't finish until we want it
to
final ClientStreamListener listener =
client1.startPut(FlightDescriptor.path("test"), root,
new AsyncPutListener());
- try (final FlightClient client2 = FlightClient.builder(allocator,
location).build()) {
+ try (final FlightClient client2 = FlightClient.builder(allocator,
server.getLocation()).build()) {
client2.listActions().forEach(actionType ->
Assertions.assertNotNull(actionType.getType()));
}
listener.completed();
@@ -80,12 +81,10 @@ public class TestFlightClient {
.singletonList(new Field("encoded",
new FieldType(true, new ArrowType.Int(32, true), new
DictionaryEncoding(1L, false, null)), null)));
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
- final FlightServer server = FlightTestUtil.getStartedServer(
- location -> FlightServer.builder(serverAllocator, location,
- new DictionaryProducer(serverAllocator)).build())) {
- final Location location =
Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, server.getPort());
- try (final FlightClient client = FlightClient.builder(allocator,
location).build()) {
+ final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
+ final FlightServer server = FlightServer.builder(serverAllocator,
forGrpcInsecure(LOCALHOST, 0),
+ new DictionaryProducer(serverAllocator)).build().start()) {
+ try (final FlightClient client = FlightClient.builder(allocator,
server.getLocation()).build()) {
try (final FlightStream stream = client.getStream(new Ticket(new
byte[0]))) {
Assertions.assertTrue(stream.next());
Assertions.assertNotNull(stream.getDictionaryProvider().lookup(1));
@@ -113,12 +112,10 @@ public class TestFlightClient {
@Test
public void ownDictionaries() throws Exception {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
- final FlightServer server = FlightTestUtil.getStartedServer(
- location -> FlightServer.builder(serverAllocator, location,
- new DictionaryProducer(serverAllocator)).build())) {
- final Location location =
Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, server.getPort());
- try (final FlightClient client = FlightClient.builder(allocator,
location).build()) {
+ final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
+ final FlightServer server = FlightServer.builder(serverAllocator,
forGrpcInsecure(LOCALHOST, 0),
+ new DictionaryProducer(serverAllocator)).build().start()) {
+ try (final FlightClient client = FlightClient.builder(allocator,
server.getLocation()).build()) {
try (final FlightStream stream = client.getStream(new Ticket(new
byte[0]))) {
Assertions.assertTrue(stream.next());
Assertions.assertFalse(stream.next());
@@ -138,12 +135,11 @@ public class TestFlightClient {
@Test
public void useDictionariesAfterClose() throws Exception {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE);
- final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
- final FlightServer server = FlightTestUtil.getStartedServer(
- location -> FlightServer.builder(serverAllocator, location, new
DictionaryProducer(serverAllocator))
- .build())) {
- final Location location =
Location.forGrpcInsecure(FlightTestUtil.LOCALHOST, server.getPort());
- try (final FlightClient client = FlightClient.builder(allocator,
location).build()) {
+ final BufferAllocator serverAllocator =
allocator.newChildAllocator("flight-server", 0, Integer.MAX_VALUE);
+ final FlightServer server = FlightServer.builder(serverAllocator,
forGrpcInsecure(LOCALHOST, 0),
+ new DictionaryProducer(serverAllocator))
+ .build().start()) {
+ try (final FlightClient client = FlightClient.builder(allocator,
server.getLocation()).build()) {
final VectorSchemaRoot root;
final DictionaryProvider provider;
try (final FlightStream stream = client.getStream(new Ticket(new
byte[0]))) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java
index 7c7011a8cd..1feb6afcf8 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLargeMessage.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
@@ -40,8 +43,7 @@ public class TestLargeMessage {
public void getLargeMessage() throws Exception {
try (final BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
final Producer producer = new Producer(a);
- final FlightServer s =
- FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(a, location, producer).build())) {
+ final FlightServer s = FlightServer.builder(a,
forGrpcInsecure(LOCALHOST, 0), producer).build().start()) {
try (FlightClient client = FlightClient.builder(a,
s.getLocation()).build()) {
try (FlightStream stream = client.getStream(new Ticket(new byte[]{}));
@@ -68,10 +70,7 @@ public class TestLargeMessage {
public void putLargeMessage() throws Exception {
try (final BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
final Producer producer = new Producer(a);
- final FlightServer s =
- FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(a, location, producer).build()
- )) {
-
+ final FlightServer s = FlightServer.builder(a,
forGrpcInsecure(LOCALHOST, 0), producer).build().start()) {
try (FlightClient client = FlightClient.builder(a,
s.getLocation()).build();
BufferAllocator testAllocator = a.newChildAllocator("testcase", 0,
Long.MAX_VALUE);
VectorSchemaRoot root = generateData(testAllocator)) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLeak.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLeak.java
index 9c9da1249a..1e4d2470c6 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLeak.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestLeak.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -65,11 +68,10 @@ public class TestLeak {
public void testCancelingDoGetDoesNotLeak() throws Exception {
final CountDownLatch callFinished = new CountDownLatch(1);
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
- final FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(allocator, location, new
LeakFlightProducer(allocator, callFinished))
- .build());
- final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new LeakFlightProducer(allocator, callFinished))
+ .build().start();
+ final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
final FlightStream stream = client.getStream(new Ticket(new byte[0]));
stream.getRoot();
@@ -87,11 +89,10 @@ public class TestLeak {
public void testCancelingDoPutDoesNotBlock() throws Exception {
final CountDownLatch callFinished = new CountDownLatch(1);
try (final BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
- final FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(allocator, location, new
LeakFlightProducer(allocator, callFinished))
- .build());
- final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
+ final FlightServer s = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0),
+ new LeakFlightProducer(allocator, callFinished))
+ .build().start();
+ final FlightClient client = FlightClient.builder(allocator,
s.getLocation()).build()) {
try (final VectorSchemaRoot root = VectorSchemaRoot.create(getSchema(),
allocator)) {
final FlightDescriptor descriptor = FlightDescriptor.command(new
byte[0]);
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java
index 79c5811c49..0e19468d2b 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerMiddleware.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import java.util.Collections;
import java.util.List;
@@ -319,12 +322,9 @@ public class TestServerMiddleware {
static <T extends FlightServerMiddleware> void test(FlightProducer producer,
List<ServerMiddlewarePair<T>> middleware,
BiConsumer<BufferAllocator, FlightClient> body) {
try (final BufferAllocator allocator = new
RootAllocator(Integer.MAX_VALUE)) {
- final FlightServer server = FlightTestUtil
- .getStartedServer(location -> {
- final FlightServer.Builder builder =
FlightServer.builder(allocator, location, producer);
- middleware.forEach(pair -> builder.middleware(pair.key,
pair.factory));
- return builder.build();
- });
+ final FlightServer.Builder builder = FlightServer.builder(allocator,
forGrpcInsecure(LOCALHOST, 0), producer);
+ middleware.forEach(pair -> builder.middleware(pair.key, pair.factory));
+ final FlightServer server = builder.build().start();
try (final FlightServer ignored = server;
final FlightClient client = FlightClient.builder(allocator,
server.getLocation()).build()
) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerOptions.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerOptions.java
index 03f11cec10..9a2c9b53e8 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerOptions.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestServerOptions.java
@@ -17,6 +17,8 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -53,11 +55,9 @@ public class TestServerOptions {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
Producer producer = new Producer(a);
- FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(a, location, producer)
- .transportHint("grpc.builderConsumer", consumer).build()
- )) {
+ FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST,
0), producer)
+ .transportHint("grpc.builderConsumer", consumer).build().start()
+ ) {
Assertions.assertTrue(consumerCalled.get());
}
}
@@ -70,11 +70,9 @@ public class TestServerOptions {
final ExecutorService executor;
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
- FlightServer server =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(a, location, new
NoOpFlightProducer())
- .build()
- )) {
+ FlightServer server = FlightServer.builder(a,
forGrpcInsecure(LOCALHOST, 0), new NoOpFlightProducer())
+ .build().start()
+ ) {
assertNotNull(server.grpcExecutor);
executor = server.grpcExecutor;
}
@@ -90,12 +88,10 @@ public class TestServerOptions {
try {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
- FlightServer server =
- FlightTestUtil.getStartedServer(
- (location) -> FlightServer.builder(a, location, new
NoOpFlightProducer())
- .executor(executor)
- .build()
- )) {
+ FlightServer server = FlightServer.builder(a,
forGrpcInsecure(LOCALHOST, 0), new NoOpFlightProducer())
+ .executor(executor)
+ .build().start()
+ ) {
Assertions.assertNull(server.grpcExecutor);
}
Assertions.assertFalse(executor.isShutdown());
@@ -116,10 +112,8 @@ public class TestServerOptions {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
Producer producer = new Producer(a);
- FlightServer s =
- FlightTestUtil.getStartedServer(
- (port) -> FlightServer.builder(a, location, producer).build()
- )) {
+ FlightServer s = FlightServer.builder(a, location,
producer).build().start();
+ ) {
try (FlightClient c = FlightClient.builder(a, location).build()) {
try (FlightStream stream = c.getStream(new Ticket(new byte[0]))) {
VectorSchemaRoot root = stream.getRoot();
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java
index a552f635b9..0f6697a8e5 100644
--- a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java
+++ b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestTls.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -107,17 +110,9 @@ public class TestTls {
try (
BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
Producer producer = new Producer();
- FlightServer s =
- FlightTestUtil.getStartedServer(
- (location) -> {
- try {
- return FlightServer.builder(a, location, producer)
- .useTls(certKey.cert, certKey.key)
- .build();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- })) {
+ FlightServer s = FlightServer.builder(a, forGrpcInsecure(LOCALHOST,
0), producer)
+ .useTls(certKey.cert, certKey.key)
+ .build().start()) {
final Builder builder = FlightClient.builder(a,
Location.forGrpcTls(FlightTestUtil.LOCALHOST, s.getPort()));
testFn.accept(builder);
} catch (InterruptedException | IOException e) {
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth/TestBasicAuth.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth/TestBasicAuth.java
index 6ec507b590..6544b23dab 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth/TestBasicAuth.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth/TestBasicAuth.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight.auth;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -116,9 +119,8 @@ public class TestBasicAuth {
}
};
- server = FlightTestUtil.getStartedServer((location) ->
FlightServer.builder(
- allocator,
- location,
+ server = FlightServer.builder(
+ allocator, forGrpcInsecure(LOCALHOST, 0),
new NoOpFlightProducer() {
@Override
public void listFlights(CallContext context, Criteria criteria,
@@ -146,7 +148,7 @@ public class TestBasicAuth {
listener.completed();
}
}
- }).authHandler(new BasicServerAuthHandler(validator)).build());
+ }).authHandler(new BasicServerAuthHandler(validator)).build().start();
client = FlightClient.builder(allocator, server.getLocation()).build();
}
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth2/TestBasicAuth2.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth2/TestBasicAuth2.java
index 310971ba95..4ccc73fcac 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth2/TestBasicAuth2.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/auth2/TestBasicAuth2.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight.auth2;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import org.apache.arrow.flight.CallStatus;
@@ -98,12 +101,11 @@ public class TestBasicAuth2 {
private void startServerAndClient() throws IOException {
final FlightProducer flightProducer = getFlightProducer();
- this.server = FlightTestUtil.getStartedServer((location) -> FlightServer
- .builder(allocator, location, flightProducer)
+ this.server = FlightServer
+ .builder(allocator, forGrpcInsecure(LOCALHOST, 0), flightProducer)
.headerAuthenticator(new GeneratedBearerTokenAuthenticator(
new BasicCallHeaderAuthenticator(this::validate)))
- .build());
-
+ .build().start();
this.client = FlightClient.builder(allocator, server.getLocation())
.build();
}
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java
index 235bcbadb3..4b8a11870d 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/client/TestCookieHandling.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight.client;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.io.IOException;
import org.apache.arrow.flight.CallHeaders;
@@ -30,7 +33,6 @@ import org.apache.arrow.flight.FlightMethod;
import org.apache.arrow.flight.FlightProducer;
import org.apache.arrow.flight.FlightServer;
import org.apache.arrow.flight.FlightServerMiddleware;
-import org.apache.arrow.flight.FlightTestUtil;
import org.apache.arrow.flight.NoOpFlightProducer;
import org.apache.arrow.flight.RequestContext;
import org.apache.arrow.memory.BufferAllocator;
@@ -255,10 +257,10 @@ public class TestCookieHandling {
}
};
- this.server = FlightTestUtil.getStartedServer((location) -> FlightServer
- .builder(allocator, location, flightProducer)
- .middleware(FlightServerMiddleware.Key.of("test"), new
SetCookieHeaderInjector.Factory())
- .build());
+ this.server = FlightServer
+ .builder(allocator, forGrpcInsecure(LOCALHOST, 0), flightProducer)
+ .middleware(FlightServerMiddleware.Key.of("test"), new
SetCookieHeaderInjector.Factory())
+ .build().start();
this.client = FlightClient.builder(allocator, server.getLocation())
.intercept(testFactory)
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java
index 7794ed7484..319aee445d 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/PerformanceTestServer.java
@@ -86,11 +86,12 @@ public class PerformanceTestServer implements AutoCloseable
{
}
public Location getLocation() {
- return location;
+ return flightServer.getLocation();
}
- public void start() throws IOException {
+ public PerformanceTestServer start() throws IOException {
flightServer.start();
+ return this;
}
@Override
diff --git
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java
index bc9f9cba30..a7af8b7130 100644
---
a/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java
+++
b/java/flight/flight-core/src/test/java/org/apache/arrow/flight/perf/TestPerf.java
@@ -17,6 +17,9 @@
package org.apache.arrow.flight.perf;
+import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
+import static org.apache.arrow.flight.Location.forGrpcInsecure;
+
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
@@ -28,7 +31,6 @@ import org.apache.arrow.flight.FlightClient;
import org.apache.arrow.flight.FlightDescriptor;
import org.apache.arrow.flight.FlightInfo;
import org.apache.arrow.flight.FlightStream;
-import org.apache.arrow.flight.FlightTestUtil;
import org.apache.arrow.flight.Ticket;
import org.apache.arrow.flight.perf.impl.PerfOuterClass.Perf;
import org.apache.arrow.memory.BufferAllocator;
@@ -87,8 +89,7 @@ public class TestPerf {
for (int i = 0; i < numRuns; i++) {
try (
final BufferAllocator a = new RootAllocator(Long.MAX_VALUE);
- final PerformanceTestServer server =
- FlightTestUtil.getStartedServer((location) -> new
PerformanceTestServer(a, location));
+ final PerformanceTestServer server = new PerformanceTestServer(a,
forGrpcInsecure(LOCALHOST, 0)).start();
final FlightClient client = FlightClient.builder(a,
server.getLocation()).build();
) {
final FlightInfo info =
client.getInfo(getPerfFlightDescriptor(50_000_000L, 4095, 2));