aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2017-08-15 00:25:41 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2017-08-15 00:48:44 +0200
commit81d020aba9d48825a70d17a5fefc4b5472795e2e (patch)
tree4db8197b82b9ab17f860b40e7d9a86cbf1e9ddbc /org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage
parent37908321c03d92c73c2a6df264e10da3e5517ae2 (diff)
parent758a181b8209e9daf19105a87a46cbfc93bc15d7 (diff)
downloadjgit-81d020aba9d48825a70d17a5fefc4b5472795e2e.tar.gz
jgit-81d020aba9d48825a70d17a5fefc4b5472795e2e.zip
Merge branch 'stable-4.8'
* stable-4.8: Update Oxygen Orbit p2 repository to R20170516192513 Fix exception handling for opening bitmap index files Change-Id: Ica20f5aa0d8a365fe3317765b93520b3abd5d342 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
index ebb5a4f124..643bb49461 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
@@ -45,8 +45,12 @@ package org.eclipse.jgit.internal.storage.file;
import static java.lang.Integer.valueOf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.Callable;
import java.util.concurrent.CyclicBarrier;
@@ -56,8 +60,14 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.internal.storage.pack.PackWriter;
+import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.EmptyProgressMonitor;
+import org.eclipse.jgit.lib.NullProgressMonitor;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.revwalk.RevBlob;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
public class GcConcurrentTest extends GcTestCase {
@@ -118,4 +128,97 @@ public class GcConcurrentTest extends GcTestCase {
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
}
}
+
+ @Test
+ public void repackAndGetStats() throws Exception {
+ TestRepository<FileRepository>.BranchBuilder test = tr.branch("test");
+ test.commit().add("a", "a").create();
+ GC gc1 = new GC(tr.getRepository());
+ gc1.setPackExpireAgeMillis(0);
+ gc1.gc();
+ test.commit().add("b", "b").create();
+
+ // Create a new Repository instance and trigger a gc
+ // from that instance. Reusing the existing repo instance
+ // tr.getRepository() would not show the problem.
+ FileRepository r2 = new FileRepository(
+ tr.getRepository().getDirectory());
+ GC gc2 = new GC(r2);
+ gc2.setPackExpireAgeMillis(0);
+ gc2.gc();
+
+ new GC(tr.getRepository()).getStatistics();
+ }
+
+ @Test
+ public void repackAndUploadPack() throws Exception {
+ TestRepository<FileRepository>.BranchBuilder test = tr.branch("test");
+ // RevCommit a = test.commit().add("a", "a").create();
+ test.commit().add("a", "a").create();
+
+ GC gc1 = new GC(tr.getRepository());
+ gc1.setPackExpireAgeMillis(0);
+ gc1.gc();
+
+ RevCommit b = test.commit().add("b", "b").create();
+
+ FileRepository r2 = new FileRepository(
+ tr.getRepository().getDirectory());
+ GC gc2 = new GC(r2);
+ gc2.setPackExpireAgeMillis(0);
+ gc2.gc();
+
+ // Simulate parts of an UploadPack. This is the situation on
+ // server side (e.g. gerrit) when when clients are
+ // cloning/fetching while the server side repo's
+ // are gc'ed by an external process (e.g. scheduled
+ // native git gc)
+ try (PackWriter pw = new PackWriter(tr.getRepository())) {
+ pw.setUseBitmaps(true);
+ pw.preparePack(NullProgressMonitor.INSTANCE, Sets.of(b),
+ Collections.<ObjectId> emptySet());
+ new GC(tr.getRepository()).getStatistics();
+ }
+ }
+
+ PackFile getSinglePack(FileRepository r) {
+ Collection<PackFile> packs = r.getObjectDatabase().getPacks();
+ assertEquals(1, packs.size());
+ return packs.iterator().next();
+ }
+
+ @Test
+ public void repackAndCheckBitmapUsage() throws Exception {
+ // create a test repository with one commit and pack all objects. After
+ // packing create loose objects to trigger creation of a new packfile on
+ // the next gc
+ TestRepository<FileRepository>.BranchBuilder test = tr.branch("test");
+ test.commit().add("a", "a").create();
+ FileRepository repository = tr.getRepository();
+ GC gc1 = new GC(repository);
+ gc1.setPackExpireAgeMillis(0);
+ gc1.gc();
+ String oldPackName = getSinglePack(repository).getPackName();
+ RevCommit b = test.commit().add("b", "b").create();
+
+ // start the garbage collection on a new repository instance,
+ FileRepository repository2 = new FileRepository(repository.getDirectory());
+ GC gc2 = new GC(repository2);
+ gc2.setPackExpireAgeMillis(0);
+ gc2.gc();
+ String newPackName = getSinglePack(repository2).getPackName();
+ // make sure gc() has caused creation of a new packfile
+ assertNotEquals(oldPackName, newPackName);
+
+ // Even when asking again for the set of packfiles outdated data
+ // will be returned. As long as the repository can work on cached data
+ // it will do so and not detect that a new packfile exists.
+ assertNotEquals(getSinglePack(repository).getPackName(), newPackName);
+
+ // Only when accessing object content it is required to rescan the pack
+ // directory and the new packfile will be detected.
+ repository.getObjectDatabase().open(b).getSize();
+ assertEquals(getSinglePack(repository).getPackName(), newPackName);
+ assertNotNull(getSinglePack(repository).getBitmapIndex());
+ }
}