2 * Copyright (c) 2024 Jacek Centkowski <geminica.programs@gmail.com> and others.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
8 * SPDX-License-Identifier: BSD-3-Clause
11 package org.eclipse.jgit.internal.storage.file;
13 import static org.junit.Assert.assertEquals;
15 import java.io.IOException;
16 import java.nio.file.Files;
17 import java.util.stream.StreamSupport;
19 import org.eclipse.jgit.lib.PersonIdent;
20 import org.eclipse.jgit.revwalk.RevCommit;
21 import org.junit.Test;
23 public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase {
25 public void testShouldReportZeroObjectsForInitializedRepo()
27 assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap);
31 public void testShouldReportAllPackFilesWhenNoGcWasPerformed()
34 long result = gc.getStatistics().numberOfPackFilesSinceBitmap;
36 assertEquals(repo.getObjectDatabase().getPacks().size(), result);
40 public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception {
44 assertEquals(1L, repositoryBitmapFiles());
45 assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap);
49 public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses()
52 RevCommit parent = addCommit(null);
54 assertEquals(1L, repositoryBitmapFiles());
60 assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
64 public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses()
67 RevCommit parent = addCommit(null);
69 assertEquals(1L, repositoryBitmapFiles());
72 parent = addCommit(parent);
74 assertEquals(2L, repositoryBitmapFiles());
80 assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap);
83 private RevCommit addCommit(RevCommit parent) throws Exception {
84 return tr.branch("master").commit()
85 .author(new PersonIdent("repo-metrics", "repo@metrics.com"))
86 .parent(parent).create();
89 private long repositoryBitmapFiles() throws IOException {
92 .newDirectoryStream(repo.getObjectDatabase()
93 .getPackDirectory().toPath(), "pack-*.bitmap")
94 .spliterator(), false)