summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThirumala Reddy Mutchukota <thirumala@google.com>2017-02-06 14:08:27 -0800
committerThirumala Reddy Mutchukota <thirumala@google.com>2017-02-07 20:34:31 -0800
commit006f4d4d29eecc3d357b442cc76b76fdeff51de0 (patch)
tree4c7fac77e68025f8bb219e585bdc7b0c179a3d41 /org.eclipse.jgit.test
parentd4bd09b78daa733933a15733bc6ebbaa0a0485f1 (diff)
downloadjgit-006f4d4d29eecc3d357b442cc76b76fdeff51de0.tar.gz
jgit-006f4d4d29eecc3d357b442cc76b76fdeff51de0.zip
Reintroduce garbage pack coalescing when ttl > 0.
Disabling the garbage pack coalescing when garbageTtl > 0 can result in lot of garbage packs if they are created within the garbageTtl time. To avoid a large number of garbage packs, re-introducing garbage pack coalescing for the packs that are created within a single calendar day when the garbageTtl is more than one day or one third of the garbageTtl. Change-Id: If969716aeb55fb4fd0ff71d75f41a07638cd5a69 Signed-off-by: Thirumala Reddy Mutchukota <thirumala@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java78
1 files changed, 69 insertions, 9 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 188b723e6e..771aadc841 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
@@ -16,12 +16,15 @@ import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.SystemReader;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -29,6 +32,7 @@ public class DfsGarbageCollectorTest {
private TestRepository<InMemoryRepository> git;
private InMemoryRepository repo;
private DfsObjDatabase odb;
+ private MockSystemReader mockSystemReader;
@Before
public void setUp() throws IOException {
@@ -36,6 +40,13 @@ public class DfsGarbageCollectorTest {
git = new TestRepository<>(new InMemoryRepository(desc));
repo = git.getRepository();
odb = repo.getObjectDatabase();
+ mockSystemReader = new MockSystemReader();
+ SystemReader.setInstance(mockSystemReader);
+ }
+
+ @After
+ public void tearDown() {
+ SystemReader.setInstance(null);
}
@Test
@@ -172,6 +183,58 @@ public class DfsGarbageCollectorTest {
}
@Test
+ public void testCollectionWithGarbageCoalescenceWithShortTtl()
+ throws Exception {
+ RevCommit commit0 = commit().message("0").create();
+ RevCommit commit1 = commit().message("1").parent(commit0).create();
+ git.update("master", commit0);
+
+ // Create commits at 1 minute intervals with 1 hour ttl.
+ for (int i = 0; i < 100; i++) {
+ mockSystemReader.tick(60);
+ commit1 = commit().message("g" + i).parent(commit1).create();
+
+ DfsGarbageCollector gc = new DfsGarbageCollector(repo);
+ gc.setGarbageTtl(1, TimeUnit.HOURS);
+ run(gc);
+
+ // Make sure we don't have more than 4 UNREACHABLE_GARBAGE packs
+ // because all the packs that are created in a 20 minutes interval
+ // should be coalesced and the packs older than 60 minutes should be
+ // removed due to ttl.
+ int count = countPacks(UNREACHABLE_GARBAGE);
+ assertTrue("Garbage pack count should not exceed 4, but found "
+ + count, count <= 4);
+ }
+ }
+
+ @Test
+ public void testCollectionWithGarbageCoalescenceWithLongTtl()
+ throws Exception {
+ RevCommit commit0 = commit().message("0").create();
+ RevCommit commit1 = commit().message("1").parent(commit0).create();
+ git.update("master", commit0);
+
+ // Create commits at 1 hour intervals with 2 days ttl.
+ for (int i = 0; i < 100; i++) {
+ mockSystemReader.tick(3600);
+ commit1 = commit().message("g" + i).parent(commit1).create();
+
+ DfsGarbageCollector gc = new DfsGarbageCollector(repo);
+ gc.setGarbageTtl(2, TimeUnit.DAYS);
+ run(gc);
+
+ // Make sure we don't have more than 3 UNREACHABLE_GARBAGE packs
+ // because all the packs that are created in a single day should
+ // be coalesced and the packs older than 2 days should be
+ // removed due to ttl.
+ int count = countPacks(UNREACHABLE_GARBAGE);
+ assertTrue("Garbage pack count should not exceed 3, but found "
+ + count, count <= 3);
+ }
+ }
+
+ @Test
public void testEstimateGcPackSizeInNewRepo() throws Exception {
RevCommit commit0 = commit().message("0").create();
RevCommit commit1 = commit().message("1").parent(commit0).create();
@@ -420,20 +483,17 @@ public class DfsGarbageCollectorTest {
run(gc);
}
- private void gcWithTtl() throws InterruptedException, IOException {
- // Wait for the system clock to move by at least 1 millisecond.
- // This allows the DfsGarbageCollector to recognize the boundary.
- long start = System.currentTimeMillis();
- do {
- Thread.sleep(10);
- } while (System.currentTimeMillis() <= start);
-
+ private void gcWithTtl() throws IOException {
+ // Move the clock forward by 1 minute and use the same as ttl.
+ mockSystemReader.tick(60);
DfsGarbageCollector gc = new DfsGarbageCollector(repo);
- gc.setGarbageTtl(1, TimeUnit.MILLISECONDS);
+ gc.setGarbageTtl(1, TimeUnit.MINUTES);
run(gc);
}
private void run(DfsGarbageCollector gc) throws IOException {
+ // adjust the current time that will be used by the gc operation.
+ mockSystemReader.tick(1);
assertTrue("gc repacked", gc.pack(null));
odb.clearCache();
}