diff options
author | Sam Delmerico <delmerico@google.com> | 2024-03-06 13:24:16 -0800 |
---|---|---|
committer | Sam Delmerico <delmerico@google.com> | 2024-03-18 17:38:43 -0700 |
commit | 478a19cf7660a7122732d85d7c912d1cd568a2e8 (patch) | |
tree | 4b63deb76bdca859ea5d27840156d98400cf2491 /org.eclipse.jgit.test | |
parent | 3ffde6e0151db7ed0f49bbb388de41825282555b (diff) | |
download | jgit-478a19cf7660a7122732d85d7c912d1cd568a2e8.tar.gz jgit-478a19cf7660a7122732d85d7c912d1cd568a2e8.zip |
DfsGarbageCollectorTest: add test for bitmap index creation
Change-Id: Ibb9b2f8fc0f5180728904f243bf372f8a233383d
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java | 68 |
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 05360dc052..1bff27e26a 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; @@ -1178,6 +1179,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) |