Skip to content

Commit

Permalink
apacheGH-34692: [Java] Expose Location.toSocketAddress (apache#34648)
Browse files Browse the repository at this point in the history
### 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: apache#34692

Authored-by: Jie Zhang <zhangjie@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
jiezhang authored and rtpsw committed Mar 27, 2023
1 parent a14a6b2 commit 6af38ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public URI getUri() {
*
* @return null if could not be converted
*/
SocketAddress toSocketAddress() {
public SocketAddress toSocketAddress() {
switch (uri.getScheme()) {
case LocationSchemes.GRPC:
case LocationSchemes.GRPC_TLS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -413,6 +414,24 @@ public void testProtobufSchemaCompatibility() throws Exception {
}
}

@Test
public void testGrpcInsecureLocation() throws Exception {
Location location = Location.forGrpcInsecure(LOCALHOST, 9000);
Assertions.assertEquals(
new URI(LocationSchemes.GRPC_INSECURE, null, LOCALHOST, 9000, null, null, null),
location.getUri());
Assertions.assertEquals(new InetSocketAddress(LOCALHOST, 9000), location.toSocketAddress());
}

@Test
public void testGrpcTlsLocation() throws Exception {
Location location = Location.forGrpcTls(LOCALHOST, 9000);
Assertions.assertEquals(
new URI(LocationSchemes.GRPC_TLS, null, LOCALHOST, 9000, null, null, null),
location.getUri());
Assertions.assertEquals(new InetSocketAddress(LOCALHOST, 9000), location.toSocketAddress());
}

/**
* An example FlightProducer for test purposes.
*/
Expand Down

0 comments on commit 6af38ba

Please sign in to comment.