aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-02-21 15:06:38 -0800
committerIvan Frade <ifrade@google.com>2024-02-26 09:56:17 -0800
commit049749558e340e1c34abd9b7bf08696c6fd99880 (patch)
tree6ebb4ea1131aad2ac3be0ec580b1896a052065fa /org.eclipse.jgit.test
parentd132050c2bfd13463482cb6f69b0e0e4de9556d7 (diff)
downloadjgit-049749558e340e1c34abd9b7bf08696c6fd99880.tar.gz
jgit-049749558e340e1c34abd9b7bf08696c6fd99880.zip
DfsPackFile: Abstract the bitmap loading to support other backends
Current code reads the bitmap index from the pack extension and loads all bitmaps into memory, with its IO and memory cost. We could consider to store the bitmaps on e.g. a database and load them on demand. Abstract the loading of the PackBitmapIndex in an interface that can be implemented with other backends. Change-Id: Ib5f64d05954708ea5325feea7088a8df229b36a5
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
index 77e5b7cb14..44694acc8d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
@@ -14,6 +14,8 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
@@ -24,14 +26,18 @@ import java.util.zip.Deflater;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
import org.eclipse.jgit.internal.storage.dfs.DfsReader.PackLoadListener;
+import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
import org.eclipse.jgit.internal.storage.pack.PackWriter;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.TestRng;
+import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.transport.ReceiveCommand;
import org.junit.Before;
import org.junit.Test;
@@ -123,6 +129,41 @@ public class DfsPackFileTest {
}
@Test
+ public void testGetBitmapIndex() throws IOException {
+ bypassCache = false;
+ clearCache = true;
+ ObjectId objectId = setupPack(512, 800);
+
+ // Add a ref for GC
+ BatchRefUpdate batchRefUpdate = db.getRefDatabase().newBatchUpdate();
+ batchRefUpdate.addCommand(new ReceiveCommand(ObjectId.zeroId(),
+ objectId, "refs/heads/master"));
+ try (RevWalk rw = new RevWalk(db)) {
+ batchRefUpdate.execute(rw, NullProgressMonitor.INSTANCE);
+ }
+ DfsGarbageCollector gc = new DfsGarbageCollector(db);
+ gc.pack(NullProgressMonitor.INSTANCE);
+
+ DfsReader reader = db.getObjectDatabase().newReader();
+ PackBitmapIndex bitmapIndex = db.getObjectDatabase().getPacks()[0]
+ .getBitmapIndex(reader);
+ assertNotNull(bitmapIndex);
+ assertEquals(1, bitmapIndex.getObjectCount());
+ }
+
+ @Test
+ public void testGetBitmapIndex_noBitmaps() throws IOException {
+ bypassCache = false;
+ clearCache = true;
+ setupPack(512, 800);
+
+ DfsReader reader = db.getObjectDatabase().newReader();
+ PackBitmapIndex bitmapIndex = db.getObjectDatabase().getPacks()[0]
+ .getBitmapIndex(reader);
+ assertNull(bitmapIndex);
+ }
+
+ @Test
public void testLoadObjectSizeIndex_noIndex() throws IOException {
bypassCache = false;
clearCache = true;