Add ResourceHandler, FileUtils.map() returning ResourceHandler#51
Add ResourceHandler, FileUtils.map() returning ResourceHandler#51drcrallen merged 7 commits intometamx:masterfrom
Conversation
…ByteBuffer> and improve resource closing in FileSmoosher and SmooshedFileMapper
| * Closes the wrapped resource. | ||
| */ | ||
| @Override | ||
| void close(); |
There was a problem hiding this comment.
AutoCloseable.close() allows Exception, is there a need to erase that signature here?
There was a problem hiding this comment.
This interface is copied from Druid: io.druid.collections.ResourceHandler. It erases exception, apparently because no present application requires throwing exception, but having it in signature it more noisy on usage side
|
This might collide a bit with |
|
@leventov please add tests to show the functionality added here is accomplishing what it is intended to accomplish. |
|
Overall this is a very reasonable, appropriate, and well executed patch. I would like to see some way to limit the quantity of resource handling interfaces. One concern is that |
|
It intentionally shadows Druid's ResourceHandler, because 1) ResourceHandler finds it's usage in java-utils source itself 2) Best place for map() is FileUtils, there is no similar class or even package in Druid codebase. Druid's ResourceHandler is used only internally, so I don't see a big problem if they co-exist with java-utils, or Druid's could be deprecated, or removed. Another way is adding |
The direct reason for this is still ability to run some druid's benchmarks in windows. So it's impossible to write a sensible test for this to run in Linux. Also some Druid's |
I didn't mean |
|
Or, the added ResourceHolder could also be made to extend |
|
@leventov it's not about saving code, its about saving developer sanity. If someone sees there are two interfaces in place that do essentially the same thing, and have no logical reason they should be different, then that muddles the waters more than it should. I propose having ResourceHandler from java-util be the interface used in druid instead of ResourceHolder. |
|
@gianm could you please review and/or express your opinion as Druid commiter on replacing |
|
As per https://groups.google.com/d/msg/druid-development/SQK4FYxzeXw/i2jx_atBAAAJ looks like the interface is staying here |
|
@drcrallen as pulling generic |
| } | ||
| } | ||
| } | ||
| Throwables.propagateIfPossible(thrown); |
There was a problem hiding this comment.
This changes behavior as it will now completely swallow IOException instead of propagating it, or even logging it.
Is there a reason the exception should be swallowed now?
There was a problem hiding this comment.
IOException was not possible here, so I just removed unneeded throws IOException. Only RuntimeException or Error are possible. So Throwables.propagateIfPossible(thrown); is just a way to rethrow, without javac complaining.
| * Facilitates using try-with-resources with resources that don't implement {@link AutoCloseable}, e. g. | ||
| * {@link java.nio.ByteBuffer}s. | ||
| * | ||
| * <p>This interface replaces {@code io.druid.collections.ResourceHandler}. |
There was a problem hiding this comment.
don't forget to remove, you can say its modeled after, but not replaces as per discussion.
|
@cheddar @drcrallen could you please express your opinion on the current state of the PR using the new Github's review system? |
drcrallen
left a comment
There was a problem hiding this comment.
Code looks good. needs unit tests for new methods and for showing improved behavior in existing methods
| public void testSanity() throws Exception | ||
| { | ||
| File baseDir = Files.createTempDir(); | ||
| baseDir.deleteOnExit(); |
There was a problem hiding this comment.
Can you use the TemporaryFolder @Rule for junit for this?
…th-resources; Add FileUtilsTest
|
@drcrallen could you please review latest changes? |
| File[] files = baseDir.listFiles(); | ||
| Assert.assertEquals(1, files.length); | ||
| Assert.assertEquals(0, files[0].length()); | ||
| FileSmoosher smoosher = new FileSmoosher(baseDir, 21); |
There was a problem hiding this comment.
Should this one be handled in a try-with-resources?
And improve resource closing in FileSmoosher and SmooshedFileMapper
Better version of #50