Skip to content

Commit fd5d710

Browse files
authored
GH-34692: [Java] Expose Location.toSocketAddress (#34648)
### Rationale for this change ### What changes are included in this PR? Change `Location.toSocketAddress()` to a public method. This is useful for creating a `FlightClient` via `FlightGrpcUtils.createFlightClient`: https://github.com/apache/arrow/blob/08fb86107b001e2e1903ae0e416ff51386d4239e/java/flight/flight-grpc/src/main/java/org/apache/arrow/flight/FlightGrpcUtils.java#L148 ### Are these changes tested? ### Are there any user-facing changes? * Closes: #34692 Authored-by: Jie Zhang <[email protected]> Signed-off-by: David Li <[email protected]>
1 parent d526fd9 commit fd5d710

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎java/flight/flight-core/src/main/java/org/apache/arrow/flight/Location.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public URI getUri() {
6060
*
6161
* @return null if could not be converted
6262
*/
63-
SocketAddress toSocketAddress() {
63+
public SocketAddress toSocketAddress() {
6464
switch (uri.getScheme()) {
6565
case LocationSchemes.GRPC:
6666
case LocationSchemes.GRPC_TLS:

‎java/flight/flight-core/src/test/java/org/apache/arrow/flight/TestBasicOperation.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.ByteArrayOutputStream;
2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.net.InetSocketAddress;
2728
import java.net.URI;
2829
import java.net.URISyntaxException;
2930
import java.nio.charset.StandardCharsets;
@@ -413,6 +414,24 @@ public void testProtobufSchemaCompatibility() throws Exception {
413414
}
414415
}
415416

417+
@Test
418+
public void testGrpcInsecureLocation() throws Exception {
419+
Location location = Location.forGrpcInsecure(LOCALHOST, 9000);
420+
Assertions.assertEquals(
421+
new URI(LocationSchemes.GRPC_INSECURE, null, LOCALHOST, 9000, null, null, null),
422+
location.getUri());
423+
Assertions.assertEquals(new InetSocketAddress(LOCALHOST, 9000), location.toSocketAddress());
424+
}
425+
426+
@Test
427+
public void testGrpcTlsLocation() throws Exception {
428+
Location location = Location.forGrpcTls(LOCALHOST, 9000);
429+
Assertions.assertEquals(
430+
new URI(LocationSchemes.GRPC_TLS, null, LOCALHOST, 9000, null, null, null),
431+
location.getUri());
432+
Assertions.assertEquals(new InetSocketAddress(LOCALHOST, 9000), location.toSocketAddress());
433+
}
434+
416435
/**
417436
* An example FlightProducer for test purposes.
418437
*/

0 commit comments

Comments
 (0)