aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-03-20 22:53:31 +0000
committerGerrit Code Review <support@gerrithub.io>2024-03-20 22:53:31 +0000
commitebdfd064c4c9ae1b7cb04e51244113f229cb45d0 (patch)
treeb42fbc499dd3268665747c2787935eee870377bf /org.eclipse.jgit.test
parent7edbe8844f617bccda437b11b9d52138fd9e9684 (diff)
parent478a19cf7660a7122732d85d7c912d1cd568a2e8 (diff)
downloadjgit-ebdfd064c4c9ae1b7cb04e51244113f229cb45d0.tar.gz
jgit-ebdfd064c4c9ae1b7cb04e51244113f229cb45d0.zip
Merge "DfsGarbageCollectorTest: add test for bitmap index creation"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java68
1 files changed, 67 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
index dfd273e401..e193de9764 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
@@ -18,10 +18,11 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
-
import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph;
import org.eclipse.jgit.internal.storage.commitgraph.CommitGraphWriter;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
+import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
+import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.internal.storage.reftable.RefCursor;
import org.eclipse.jgit.internal.storage.reftable.ReftableConfig;
import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
@@ -1214,6 +1215,71 @@ public class DfsGarbageCollectorTest {
assertFalse(gcRestPack.hasObjectSizeIndex(reader));
}
+ @Test
+ public void bitmapIndexWrittenDuringGc() throws Exception {
+ int numBranches = 2;
+ int commitsPerBranch = 50;
+
+ RevCommit commit0 = commit().message("0").create();
+ git.update("branch0", commit0);
+ RevCommit branch1 = commitChain(commit0, commitsPerBranch);
+ git.update("branch1", branch1);
+ RevCommit branch2 = commitChain(commit0, commitsPerBranch);
+ git.update("branch2", branch2);
+
+ int contiguousCommitCount = 5;
+ int recentCommitSpan = 2;
+ int recentCommitCount = 10;
+ int distantCommitSpan = 5;
+
+ PackConfig packConfig = new PackConfig();
+ packConfig.setBitmapContiguousCommitCount(contiguousCommitCount);
+ packConfig.setBitmapRecentCommitSpan(recentCommitSpan);
+ packConfig.setBitmapRecentCommitCount(recentCommitCount);
+ packConfig.setBitmapDistantCommitSpan(distantCommitSpan);
+
+ DfsGarbageCollector gc = new DfsGarbageCollector(repo);
+ gc.setPackConfig(packConfig);
+ run(gc);
+
+ DfsPackFile pack = odb.getPacks()[0];
+ PackBitmapIndex bitmapIndex = pack.getBitmapIndex(odb.newReader());
+ assertTrue("pack file has bitmap index extension",
+ pack.getPackDescription().hasFileExt(PackExt.BITMAP_INDEX));
+
+ int recentCommitsPerBranch = (recentCommitCount - contiguousCommitCount
+ - 1) / recentCommitSpan;
+ assertEquals("expected recent commits", 2, recentCommitsPerBranch);
+
+ int distantCommitsPerBranch = (commitsPerBranch - 1 - recentCommitCount)
+ / distantCommitSpan;
+ assertEquals("expected distant commits", 7, distantCommitsPerBranch);
+
+ int branchBitmapsCount = contiguousCommitCount
+ + numBranches
+ * (recentCommitsPerBranch
+ + distantCommitsPerBranch);
+ assertEquals("expected bitmaps count", 23, branchBitmapsCount);
+ assertEquals("bitmap index has expected number of bitmaps",
+ branchBitmapsCount,
+ bitmapIndex.getBitmapCount());
+
+ // The count is just a function of whether any bitmaps happen to
+ // compress efficiently against the others in the index. We expect for
+ // this test that this there will be at least one like this, but the
+ // actual count is situation-specific
+ assertTrue("bitmap index has xor-compressed bitmaps",
+ bitmapIndex.getXorBitmapCount() > 0);
+ }
+
+ private RevCommit commitChain(RevCommit parent, int length)
+ throws Exception {
+ for (int i = 0; i < length; i++) {
+ parent = commit().message("" + i).parent(parent).create();
+ }
+ return parent;
+ }
+
private static DfsPackFile findFirstBySource(DfsPackFile[] packs, PackSource source) {
return Arrays.stream(packs)
.filter(p -> p.getPackDescription().getPackSource() == source)