diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2024-11-20 12:36:42 +0000 |
---|---|---|
committer | Gerrit Code Review <support@gerrithub.io> | 2024-11-20 12:36:42 +0000 |
commit | 2c86ef2427ad3c65bfa4dee90311408255869638 (patch) | |
tree | e6856cc95ac3f21545101a3629a781ca90d57306 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | f6fd48bef948f0bae1afbe207ddf98b2af9565d5 (diff) | |
parent | 469928898db10d4b19bd34658d3b2f93f12952b3 (diff) | |
download | jgit-2c86ef2427ad3c65bfa4dee90311408255869638.tar.gz jgit-2c86ef2427ad3c65bfa4dee90311408255869638.zip |
Merge "Add numberOfObjectsSinceBitmap to RepoStatistics" into stable-6.10
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java) | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java index fa13bb57c8..3cd766c4e9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java @@ -14,17 +14,21 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.nio.file.Files; +import java.util.Collection; import java.util.stream.StreamSupport; +import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Test; -public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { +public class GcSinceBitmapStatisticsTest extends GcTestCase { @Test - public void testShouldReportZeroObjectsForInitializedRepo() + public void testShouldReportZeroPacksAndObjectsForInitializedRepo() throws IOException { - assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap); + RepoStatistics s = gc.getStatistics(); + assertEquals(0L, s.numberOfPackFilesSinceBitmap); + assertEquals(0L, s.numberOfObjectsSinceBitmap); } @Test @@ -37,7 +41,17 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception { + public void testShouldReportAllObjectsWhenNoGcWasPerformed() + throws Exception { + tr.packAndPrune(); + + assertEquals( + getNumberOfObjectsInPacks(repo.getObjectDatabase().getPacks()), + gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNoPacksDirectlyAfterGc() throws Exception { // given addCommit(null); gc.gc().get(); @@ -46,7 +60,17 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses() + public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception { + // given + addCommit(null); + assertEquals(2L, gc.getStatistics().numberOfObjectsSinceBitmap); + + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNewPacksSinceGcWhenRepositoryProgresses() throws Exception { // commit & gc RevCommit parent = addCommit(null); @@ -61,7 +85,23 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses() + public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses() + throws Exception { + // commit & gc + RevCommit parent = addCommit(null); + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + + // progress & pack + addCommit(parent); + assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap); + + tr.packAndPrune(); + assertEquals(3L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNewPacksFromTheLatestBitmapWhenRepositoryProgresses() throws Exception { // commit & gc RevCommit parent = addCommit(null); @@ -80,6 +120,26 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap); } + @Test + public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses() + throws Exception { + // commit & gc + RevCommit parent = addCommit(null); + gc.gc().get(); + + // progress & gc + parent = addCommit(parent); + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + + // progress & pack + addCommit(parent); + assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap); + + tr.packAndPrune(); + assertEquals(4L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + private RevCommit addCommit(RevCommit parent) throws Exception { return tr.branch("master").commit() .author(new PersonIdent("repo-metrics", "repo@metrics.com")) @@ -94,4 +154,14 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { .spliterator(), false) .count(); } + + private long getNumberOfObjectsInPacks(Collection<Pack> packs) { + return packs.stream().mapToLong(pack -> { + try { + return pack.getObjectCount(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }).sum(); + } } |