aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2019-03-06 14:13:35 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2019-03-06 14:13:48 +0900
commitae5ea80363efd3b4071e88e04dcf2ca1f3218c93 (patch)
tree8f03595b3d04d443bc2dd5cb150222dde40919d8 /org.eclipse.jgit.test
parent60a606a2615ac4340c3eb4d288bcd8d887cd1f0c (diff)
parent7b3ee6f62e0cd0d3437abb12f9488dedd8af5125 (diff)
downloadjgit-ae5ea80363efd3b4071e88e04dcf2ca1f3218c93.tar.gz
jgit-ae5ea80363efd3b4071e88e04dcf2ca1f3218c93.zip
Merge branch 'stable-4.9' into stable-4.10
* stable-4.9: Fix error log message in ObjectDirectory.handlePackError() Properly format pack checksums in PackFile.idx() Cancel gc if thread was interrupted PackFile: report correct message for checksum mismatch ObjectDirectory: Clean up logging Bazel: Stop using native.git_repository ObjectDirectory: extra logging on packfile exceptions Change-Id: I0847251eb010616a705e0b91df4bdebc225fa95d Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java52
1 files changed, 52 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 643bb49461..c60c357da3 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
@@ -47,27 +47,35 @@ 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 static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
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.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jgit.errors.CancelledException;
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.ConfigConstants;
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.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.junit.Test;
public class GcConcurrentTest extends GcTestCase {
@@ -221,4 +229,48 @@ public class GcConcurrentTest extends GcTestCase {
assertEquals(getSinglePack(repository).getPackName(), newPackName);
assertNotNull(getSinglePack(repository).getBitmapIndex());
}
+
+ @Test
+ public void testInterruptGc() throws Exception {
+ FileBasedConfig c = repo.getConfig();
+ c.setInt(ConfigConstants.CONFIG_GC_SECTION, null,
+ ConfigConstants.CONFIG_KEY_AUTOPACKLIMIT, 1);
+ c.save();
+ SampleDataRepositoryTestCase.copyCGitTestPacks(repo);
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ final CountDownLatch latch = new CountDownLatch(1);
+ Future<Collection<PackFile>> result = executor
+ .submit(new Callable<Collection<PackFile>>() {
+
+ @Override
+ public Collection<PackFile> call() throws Exception {
+ long start = System.currentTimeMillis();
+ System.out.println("starting gc");
+ latch.countDown();
+ Collection<PackFile> r = gc.gc();
+ System.out.println("gc took "
+ + (System.currentTimeMillis() - start) + " ms");
+ return r;
+ }
+ });
+ try {
+ latch.await();
+ Thread.sleep(5);
+ executor.shutdownNow();
+ result.get();
+ fail("thread wasn't interrupted");
+ } catch (ExecutionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof CancelledException) {
+ assertEquals(JGitText.get().operationCanceled,
+ cause.getMessage());
+ } else if (cause instanceof IOException) {
+ Throwable cause2 = cause.getCause();
+ assertTrue(cause2 instanceof InterruptedException
+ || cause2 instanceof ExecutionException);
+ } else {
+ fail("unexpected exception " + e);
+ }
+ }
+ }
}