Browse Source

HugeFileTest: Open RandomAccessFile in try-with-resource

Change-Id: Iecb9a7348b40c91fa45c051c2a9c4eb47e4bdeca
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v4.11.0.201803080745-r
David Pursehouse 6 years ago
parent
commit
7b57ce5186
1 changed files with 23 additions and 23 deletions
  1. 23
    23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java

+ 23
- 23
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java View File

public void testAddHugeFile() throws Exception { public void testAddHugeFile() throws Exception {
measure("Commencing test"); measure("Commencing test");
File file = new File(db.getWorkTree(), "a.txt"); File file = new File(db.getWorkTree(), "a.txt");
RandomAccessFile rf = new RandomAccessFile(file, "rw");
rf.setLength(4429185024L);
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.setLength(4429185024L);
}
measure("Created file"); measure("Created file");


git.add().addFilepattern("a.txt").call(); git.add().addFilepattern("a.txt").call();
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Does not change anything, but modified timestamp // Does not change anything, but modified timestamp
rf = new RandomAccessFile(file, "rw");
rf.write(0);
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.write(0);
}


status = git.status().call(); status = git.status().call();
measure("Status after non-modifying update"); measure("Status after non-modifying update");
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Change something // Change something
rf = new RandomAccessFile(file, "rw");
rf.write('a');
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.write('a');
}


status = git.status().call(); status = git.status().call();
measure("Status after modifying update"); measure("Status after modifying update");
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Truncate mod 4G and re-establish equality // Truncate mod 4G and re-establish equality
rf = new RandomAccessFile(file, "rw");
rf.setLength(134217728L);
rf.write(0);
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.setLength(134217728L);
rf.write(0);
}


status = git.status().call(); status = git.status().call();
measure("Status after truncating update"); measure("Status after truncating update");
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Change something // Change something
rf = new RandomAccessFile(file, "rw");
rf.write('a');
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.write('a');
}


status = git.status().call(); status = git.status().call();
measure("Status after modifying and truncating update"); measure("Status after modifying and truncating update");
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Truncate to entry length becomes negative int // Truncate to entry length becomes negative int
rf = new RandomAccessFile(file, "rw");
rf.setLength(3429185024L);
rf.write(0);
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.setLength(3429185024L);
rf.write(0);
}


git.add().addFilepattern("a.txt").call(); git.add().addFilepattern("a.txt").call();
measure("Added truncated file"); measure("Added truncated file");
assertEquals(0, status.getUntracked().size()); assertEquals(0, status.getUntracked().size());


// Change something // Change something
rf = new RandomAccessFile(file, "rw");
rf.write('a');
rf.close();
try (RandomAccessFile rf = new RandomAccessFile(file, "rw")) {
rf.write('a');
}


status = git.status().call(); status = git.status().call();
measure("Status after modifying and truncating update"); measure("Status after modifying and truncating update");

Loading…
Cancel
Save