Skip to content
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

Fix regression regarding pipeing #1124

Merged
merged 4 commits into from
May 22, 2018

Conversation

yfarjoun
Copy link
Contributor

Based on @tfenne 's branch #1118

includes:

  • Test that piping works for both File and Path (using mkfifo and a second thread)
  • Fixed .of(Path) to call .of(File) when the input is not a regular file.
  • Lots of whitespace changes (sorry)
  • Closed readers (in the tests) using try-with-resources

@yfarjoun yfarjoun requested review from droazen and tfenne May 22, 2018 12:49
@codecov-io
Copy link

codecov-io commented May 22, 2018

Codecov Report

Merging #1124 into master will decrease coverage by 0.004%.
The diff coverage is 33.333%.

@@               Coverage Diff               @@
##              master     #1124       +/-   ##
===============================================
- Coverage     65.982%   65.978%   -0.004%     
  Complexity      7653      7653               
===============================================
  Files            535       535               
  Lines          32489     32491        +2     
  Branches        5518      5518               
===============================================
  Hits           21437     21437               
  Misses          8909      8909               
- Partials        2143      2145        +2
Impacted Files Coverage Δ Complexity Δ
...rc/main/java/htsjdk/samtools/SamInputResource.java 67.153% <33.333%> (-0.254%) 16 <1> (+1)
src/main/java/htsjdk/samtools/BAMFileReader.java 63.429% <0%> (-0.286%) 38% <0%> (-1%)

Copy link
Member

@tfenne tfenne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yfarjoun This seems ok to me, but it seems like a temporary solution. With the move towards Path everywhere, we'll probably still need to come back through and fix the underlying problem with SeekablePathStream, and probably reverse this vectoring, to just send of(File) to of(file.toPath).

if (Files.isRegularFile(path) && Files.exists(path)) {
return new SamInputResource(new PathInputResource(path));
} else {
return of(path.toFile());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is funny

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally implemented it as

return of(new FileInputStream(path))

But that requires a try-catch block to guard against non-existant paths.
perhaps in the presence of the Files.exists(path) clause this is a non-issue and I can swallow the exception and return a null (which should never ever happen)?

happy to change it or not...as people prefer.

}

@Test(singleThreaded = true, groups="unix")
public void testWriteAndReadFromPipe() throws IOException, InterruptedException, ExecutionException, TimeoutException {
@DataProvider()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think turning this into a data provider is less clear that just having for x in Arrays.asList(true, false) in the test.


if (Files.isRegularFile(path) && Files.exists(path)) {
return new SamInputResource(new PathInputResource(path));
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment linking back to the discussion that spawned it. Otherwise it will cause much confusion in the future.

@yfarjoun
Copy link
Contributor Author

I added text, and fixed the indents. merging.

@yfarjoun yfarjoun merged commit c3ea109 into master May 22, 2018
@yfarjoun yfarjoun deleted the yf_add_test_broken_namedpipe_with_path branch May 22, 2018 20:42
@@ -91,7 +92,12 @@ public static SamInputResource of(final File file) {

/** Creates a {@link SamInputResource} reading from the provided resource, with no index. */
public static SamInputResource of(final Path path) {
return new SamInputResource(new PathInputResource(path));

if (Files.isRegularFile(path) && Files.exists(path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yfarjoun Could you open a separate PR to remove the Files.exists() check here? This operation is expensive over certain NIO filesystems (eg., takes on the order of seconds over GCS), so forcing it at reader creation time could potentially add hours to the wall-clock time of a task that needed to access many bams over GCS.

It's also not particularly logical to go to the else clause here if the file doesn't exist -- if it's a non-existent GCS file, PathInputResource is better equipped to produce a more relevant error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants