You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2016/05/26 10:23:12 UTC
[2/2] lucene-solr:master: Fix TestHardLinkCopyDirectoryWrapper if an
assume is hit all directories must be closed
Fix TestHardLinkCopyDirectoryWrapper if an assume is hit all directories must be closed
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2aabed4a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2aabed4a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2aabed4a
Branch: refs/heads/master
Commit: 2aabed4ab630a65f514cd536fbf79bb5c0a342c5
Parents: 268da5b
Author: Simon Willnauer <si...@apache.org>
Authored: Thu May 26 12:20:49 2016 +0200
Committer: Simon Willnauer <si...@apache.org>
Committed: Thu May 26 12:21:03 2016 +0200
----------------------------------------------------------------------
.../store/TestHardLinkCopyDirectoryWrapper.java | 51 +++++++++++---------
1 file changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2aabed4a/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java
----------------------------------------------------------------------
diff --git a/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java b/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java
index b084c92..819511b 100644
--- a/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java
+++ b/lucene/misc/src/test/org/apache/lucene/store/TestHardLinkCopyDirectoryWrapper.java
@@ -45,32 +45,37 @@ public class TestHardLinkCopyDirectoryWrapper extends BaseDirectoryTestCase {
Directory luceneDir_1 = newFSDirectory(dir_1);
Directory luceneDir_2 = newFSDirectory(dir_2);
- try(IndexOutput output = luceneDir_1.createOutput("foo.bar", IOContext.DEFAULT)) {
- CodecUtil.writeHeader(output, "foo", 0);
- output.writeString("hey man, nice shot!");
- CodecUtil.writeFooter(output);
- }
try {
- Files.createLink(tempDir.resolve("test"), dir_1.resolve("foo.bar"));
- BasicFileAttributes destAttr = Files.readAttributes(tempDir.resolve("test"), BasicFileAttributes.class);
+ try (IndexOutput output = luceneDir_1.createOutput("foo.bar", IOContext.DEFAULT)) {
+ CodecUtil.writeHeader(output, "foo", 0);
+ output.writeString("hey man, nice shot!");
+ CodecUtil.writeFooter(output);
+ }
+ try {
+ Files.createLink(tempDir.resolve("test"), dir_1.resolve("foo.bar"));
+ BasicFileAttributes destAttr = Files.readAttributes(tempDir.resolve("test"), BasicFileAttributes.class);
+ BasicFileAttributes sourceAttr = Files.readAttributes(dir_1.resolve("foo.bar"), BasicFileAttributes.class);
+ assumeTrue("hardlinks are not supported", destAttr.fileKey() != null
+ && destAttr.fileKey().equals(sourceAttr.fileKey()));
+ } catch (UnsupportedOperationException ex) {
+ assumeFalse("hardlinks are not supported", true);
+ }
+
+ HardlinkCopyDirectoryWrapper wrapper = new HardlinkCopyDirectoryWrapper(luceneDir_2);
+ wrapper.copyFrom(luceneDir_1, "foo.bar", "bar.foo", IOContext.DEFAULT);
+ assertTrue(Files.exists(dir_2.resolve("bar.foo")));
+ BasicFileAttributes destAttr = Files.readAttributes(dir_2.resolve("bar.foo"), BasicFileAttributes.class);
BasicFileAttributes sourceAttr = Files.readAttributes(dir_1.resolve("foo.bar"), BasicFileAttributes.class);
- assumeTrue("hardlinks are not supported", destAttr.fileKey() != null
- && destAttr.fileKey().equals(sourceAttr.fileKey()));
- } catch (UnsupportedOperationException ex) {
- assumeFalse("hardlinks are not supported", false);
+ assertEquals(destAttr.fileKey(), sourceAttr.fileKey());
+ try (ChecksumIndexInput indexInput = wrapper.openChecksumInput("bar.foo", IOContext.DEFAULT)) {
+ CodecUtil.checkHeader(indexInput, "foo", 0, 0);
+ assertEquals("hey man, nice shot!", indexInput.readString());
+ CodecUtil.checkFooter(indexInput);
+ }
+ } finally {
+ // close them in a finally block we might run into an assume here
+ IOUtils.close(luceneDir_1, luceneDir_2);
}
- HardlinkCopyDirectoryWrapper wrapper = new HardlinkCopyDirectoryWrapper(luceneDir_2);
- wrapper.copyFrom(luceneDir_1, "foo.bar", "bar.foo", IOContext.DEFAULT);
- assertTrue(Files.exists(dir_2.resolve("bar.foo")));
- BasicFileAttributes destAttr = Files.readAttributes(dir_2.resolve("bar.foo"), BasicFileAttributes.class);
- BasicFileAttributes sourceAttr = Files.readAttributes(dir_1.resolve("foo.bar"), BasicFileAttributes.class);
- assertEquals(destAttr.fileKey(), sourceAttr.fileKey());
- try(ChecksumIndexInput indexInput = wrapper.openChecksumInput("bar.foo", IOContext.DEFAULT)) {
- CodecUtil.checkHeader(indexInput, "foo", 0, 0);
- assertEquals("hey man, nice shot!", indexInput.readString());
- CodecUtil.checkFooter(indexInput);
- }
- IOUtils.close(luceneDir_1, luceneDir_2);
}
}