@Test public void testArchiveControllerStateWithOutputStream() throws IOException, InterruptedException { assertArchiveControllerStateWithResource( new Factory<OutputStream, String, IOException>() { @Override public OutputStream create(String entry) throws IOException { return new TFileOutputStream(entry); } }); }
@Test public final void testCopyContainingOrSameFiles() throws IOException { assert !archive.exists(); final TFile dir = archive.getParentFile(); assertNotNull(dir); final TFile entry = new TFile(archive, "entry"); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); entry.input(new ByteArrayInputStream(getData())); assertCopyContainingOrSameFiles0(dir, archive); assertCopyContainingOrSameFiles0(archive, entry); TFile.rm_r(archive); }
private void assertCopyContainingOrSameFiles0(final TFile a, final TFile b) throws IOException { assertCopyContainingOrSameFiles1(a, b); assertCopyContainingOrSameFiles1(a.getCanOrAbsFile(), b); assertCopyContainingOrSameFiles1(a, b.getCanOrAbsFile()); assertCopyContainingOrSameFiles1(a.getCanOrAbsFile(), b.getCanOrAbsFile()); }
@Test public final void testCreateNewFile() throws IOException{ assertCreateNewPlainFile(); assertCreateNewEnhancedFile(); }
private void assertCopyDelete(final TFile parent, final TFile dir) throws IOException { final TFile parentFile = new TFile(parent, "file"); final TFile parentArchive = new TFile(parent, "archive" + getSuffix()); final TFile dirFile = new TFile(dir, "file"); final TFile dirArchive = new TFile(dir, "archive" + getSuffix()); assertCopyDelete0(dirFile, dirArchive); assertCopyDelete0(dirFile, parentFile); assertCopyDelete0(dirFile, parentArchive); assertCopyDelete0(parentFile, dirFile); assertCopyDelete0(parentFile, dirArchive); assertCopyDelete0(parentArchive, dirFile); assertCopyDelete0(parentArchive, dirArchive); assertCopyDelete0(dirArchive, dirFile); assertCopyDelete0(dirArchive, parentFile); assertCopyDelete0(dirArchive, parentArchive); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private void assertCreateNewPlainFile() throws IOException { final File archive = createTempFile(); TFile.rm(archive); final File file1 = new File(archive, "test.txt"); final File file2 = new File(file1, "test.txt"); try { file1.createNewFile(); fail("Creating a file in a non-existent directory should throw an IOException!"); } catch (IOException expected) { } assertCreateNewFile(archive, file1, file2); }
createTestFile(a); assertTrue(a.setLastModified(time - granularity)); almd == blmd || almu == blmu); verifyTestFile(a);
private void assertDirectoryTree(TFile basePath, TFile reversePath) throws IOException { if (reversePath == null) { // We're at the leaf of the directory tree. final TFile test = new TFile(basePath, "test.txt"); //testCreateNewFile(basePath, test); assertFileOutputStream(test); return; } final TFile member = new TFile(basePath, reversePath.getName()); final boolean created = member.mkdir(); final TFile children = reversePath.getParentFile(); assertDirectoryTree(member, children); assertListFiles(basePath, member.getName()); assertTrue(member.exists()); assertTrue(member.isDirectory()); assertFalse(member.isFile()); if (member.isArchive()) assertEquals(0, member.length()); if (created) { member.rm(); assertFalse(member.exists()); assertFalse(member.isDirectory()); assertFalse(member.isFile()); assertEquals(0, member.length()); } }
@Test public final void testDirectoryTree() throws IOException { assertDirectoryTree( new TFile(System.getProperty("java.io.tmpdir")), // base directory new TFile("dir/inner" + getSuffix() + "/dir/outer" + getSuffix() + "/" + archive.getName())); // this path is reversed!!! }
@Test public final void testCopyDelete() throws IOException { final String[] names = { "0" + getSuffix(), "1" + getSuffix(), //"2" + getSuffix(), }; assertTrue(archive.mkdir()); // create valid archive file assertCopyDelete(archive, names, 0); archive.rm(); assertTrue(archive.toNonArchiveFile().mkdir()); // create false positive archive file assertCopyDelete(archive, names, 0); archive.rm(); }
private void assertCopyDelete(final TFile parent, String[] names, int off) throws IOException { if (off >= names.length) return; final TFile dir = new TFile(parent, names[off]); assertTrue(dir.mkdir()); // create valid archive file assertCopyDelete(parent, dir); assertCopyDelete(dir, names, off + 1); // continue recursion dir.rm(); assertTrue(dir.toNonArchiveFile().mkdir()); // create false positive archive file assertCopyDelete(parent, dir); assertCopyDelete(dir, names, off + 1); // continue recursion dir.rm(); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private void assertCreateNewEnhancedFile() throws IOException { final File file1 = new TFile(archive, "test.txt"); final File file2 = new TFile(file1, "test.txt"); TConfig config = TConfig.push(); try { config.setLenient(false); try { file1.createNewFile(); fail("Creating a file in a non-existent directory should throw an IOException!"); } catch (IOException expected) { } assertCreateNewFile(archive, file1, file2); } finally { config.close(); } assertCreateNewFile(archive, file1, file2); }
runConcurrent(NUM_IO_THREADS, new WriteFactory()).join(); } finally { assertArchiveEntries(archive, NUM_IO_THREADS); TFile.rm_r(archive);
@Test public void testArchiveControllerStateWithInputStream() throws IOException, InterruptedException { assertArchiveControllerStateWithResource( new Factory<InputStream, String, IOException>() { @Override public InputStream create(String entry) throws IOException { return new TFileInputStream(entry); } }); }