Repository: nifi Updated Branches: refs/heads/master 273e69f2c -> 474df053d
NIFI-3276 - FileSystemRepository.getPath() only check exists if necessary This closes #1388. Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/474df053 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/474df053 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/474df053 Branch: refs/heads/master Commit: 474df053d64deb0783cf02830f9092ca9d24edb2 Parents: 273e69f Author: Bryan Rosander <[email protected]> Authored: Wed Jan 4 10:34:00 2017 -0500 Committer: Pierre Villard <[email protected]> Committed: Thu Jan 5 21:44:59 2017 +0100 ---------------------------------------------------------------------- .../repository/FileSystemRepository.java | 6 ++-- .../repository/TestFileSystemRepository.java | 33 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/474df053/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java index 5eb9c5a..7108cfe 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java @@ -498,10 +498,10 @@ public class FileSystemRepository implements ContentRepository { // If the data does not exist, create a Path that points to where the data would exist in the archive directory. if (!Files.exists(resolvedPath)) { resolvedPath = getArchivePath(claim.getResourceClaim()); - } - if (verifyExists && !Files.exists(resolvedPath)) { - throw new ContentNotFoundException(claim); + if (verifyExists && !Files.exists(resolvedPath)) { + throw new ContentNotFoundException(claim); + } } return resolvedPath; } http://git-wip-us.apache.org/repos/asf/nifi/blob/474df053/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java index af33ccb..7edb0e7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.controller.repository; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -401,6 +402,38 @@ public class TestFileSystemRepository { } @Test + public void testReadWithContentArchived() throws IOException { + final ContentClaim claim = repository.create(true); + final Path path = getPath(claim); + Files.deleteIfExists(path); + + Path archivePath = FileSystemRepository.getArchivePath(path); + + Files.createDirectories(archivePath.getParent()); + final byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(); + try (final OutputStream out = Files.newOutputStream(archivePath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { + out.write(data); + } + + try (final InputStream inStream = repository.read(claim)) { + assertNotNull(inStream); + final byte[] dataRead = readFully(inStream, data.length); + assertArrayEquals(data, dataRead); + } + } + + @Test(expected = ContentNotFoundException.class) + public void testReadWithNoContentArchived() throws IOException { + final ContentClaim claim = repository.create(true); + final Path path = getPath(claim); + Files.deleteIfExists(path); + + Path archivePath = FileSystemRepository.getArchivePath(path); + Files.deleteIfExists(archivePath); + repository.read(claim).close(); + } + + @Test public void testWrite() throws IOException { final ContentClaim claim = repository.create(true); final byte[] data = "The quick brown fox jumps over the lazy dog".getBytes();
