summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2020-01-29 19:11:00 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-02-11 00:03:09 +0100
commit8c9f7656c3078a4d4a2986400a9700a9c13b416f (patch)
tree29580fb9462b3ed633a91452e84dc6513e7d86da /org.eclipse.jgit.test
parentdd203f03c2ac8444b6c4804653c829a986660973 (diff)
downloadjgit-8c9f7656c3078a4d4a2986400a9700a9c13b416f.tar.gz
jgit-8c9f7656c3078a4d4a2986400a9700a9c13b416f.zip
reftable: clear cache on full compaction
The merged table contains handles to open files. A full compaction causes those files to be closed, and so further lookups would fail with EBADF. Change-Id: I7bb74f7228ecc7fec9535b00e56a617a9c18e00e Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
index cdc64fa1b2..bca113fbfc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
@@ -59,6 +59,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
@@ -543,6 +544,43 @@ public class FileReftableTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void compactFully() throws Exception {
+ FileReftableDatabase refDb = (FileReftableDatabase) db.getRefDatabase();
+ PersonIdent person = new PersonIdent("jane", "jane@invalid");
+
+ ObjectId aId = db.exactRef("refs/heads/a").getObjectId();
+ ObjectId bId = db.exactRef("refs/heads/b").getObjectId();
+
+ SecureRandom random = new SecureRandom();
+ List<String> strs = new ArrayList<>();
+ for (int i = 0; i < 1024; i++) {
+ strs.add(String.format("%02x",
+ Integer.valueOf(random.nextInt(256))));
+ }
+
+ String randomStr = String.join("", strs);
+ String refName = "branch";
+ for (long i = 0; i < 2; i++) {
+ RefUpdate ru = refDb.newUpdate(refName, false);
+ ru.setNewObjectId(i % 2 == 0 ? aId : bId);
+ ru.setForceUpdate(true);
+ // Only write a large string in the first table, so it becomes much larger
+ // than the second, and the result is not autocompacted.
+ ru.setRefLogMessage(i == 0 ? randomStr : "short", false);
+ ru.setRefLogIdent(person);
+
+ RefUpdate.Result res = ru.update();
+ assertTrue(res == Result.NEW || res == FORCED);
+ }
+
+ assertEquals(refDb.exactRef(refName).getObjectId(), bId);
+ assertTrue(randomStr.equals(refDb.getReflogReader(refName).getReverseEntry(1).getComment()));
+ refDb.compactFully();
+ assertEquals(refDb.exactRef(refName).getObjectId(), bId);
+ assertTrue(randomStr.equals(refDb.getReflogReader(refName).getReverseEntry(1).getComment()));
+ }
+
+ @Test
public void reftableRefsStorageClass() throws IOException {
Ref b = db.exactRef("refs/heads/b");
assertEquals(Ref.Storage.PACKED, b.getStorage());