NIFI-3276 - FileSystemRepository.getPath() only check exists if necessary

This closes #1388.
This commit is contained in:
Bryan Rosander 2017-01-04 10:34:00 -05:00 committed by Pierre Villard
parent 273e69f2cb
commit 474df053d6
2 changed files with 36 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;
@ -400,6 +401,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);