-
Notifications
You must be signed in to change notification settings - Fork 4.2k
ARROW-6867: [FlightRPC][Java] clean up default executor #5634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| package org.apache.arrow.flight; | ||
|
|
||
| import java.io.File; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.function.Consumer; | ||
|
|
||
|
|
@@ -54,6 +56,48 @@ public void builderConsumer() throws Exception { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Make sure that if Flight supplies a default executor to gRPC, then it is closed along with the server. | ||
| */ | ||
| @Test | ||
| public void defaultExecutorClosed() throws Exception { | ||
| final ExecutorService executor; | ||
| try ( | ||
| BufferAllocator a = new RootAllocator(Long.MAX_VALUE); | ||
| FlightServer server = | ||
| FlightTestUtil.getStartedServer( | ||
| (location) -> FlightServer.builder(a, location, new NoOpFlightProducer()) | ||
| .build() | ||
| )) { | ||
| Assert.assertNotNull(server.grpcExecutor); | ||
| executor = server.grpcExecutor; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't you try shutting down here and verify it does shutdown?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, there's no accessible reference to the actual executor to confirm it afterwards.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could plumb one through, but it'd be adding references specifically for testing. (Sorry for the delay again, October was quite the busy month.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about making resources less generic and take the reference to ExecutorService in the class instead of list of AutoCloseable? Then make awaitTermination rely on both the server and the executor (if its not null). That way you don't need anything specifically visible for testing.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I've updated the PR. |
||
| Assert.assertTrue(executor.isShutdown()); | ||
| } | ||
|
|
||
| /** | ||
| * Make sure that if the user provides an executor to gRPC, then Flight does not close it. | ||
| */ | ||
| @Test | ||
| public void suppliedExecutorNotClosed() throws Exception { | ||
| final ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
| try { | ||
| try ( | ||
| BufferAllocator a = new RootAllocator(Long.MAX_VALUE); | ||
| FlightServer server = | ||
| FlightTestUtil.getStartedServer( | ||
| (location) -> FlightServer.builder(a, location, new NoOpFlightProducer()) | ||
| .executor(executor) | ||
| .build() | ||
| )) { | ||
| Assert.assertNull(server.grpcExecutor); | ||
| } | ||
| Assert.assertFalse(executor.isShutdown()); | ||
| } finally { | ||
| executor.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void domainSocket() throws Exception { | ||
| Assume.assumeTrue("We have a native transport available", FlightTestUtil.isNativeTransportAvailable()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could avoid exposing this if you added this to awaitTermination as well (but that is a little tricky to do correctly). I'm OK if you don't want to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, how would that work in the test? We'd shut down the executor in awaitTermination and wait?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought we shutdown the executorservice in shutdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, right. I can do that, but I still don't see how that'd let us avoid exposing it in test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it tests the behavior implicitly vs explicitly as the way you have it now. Like I said I'm fine with either approach.