summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test/src
diff options
context:
space:
mode:
authorMike Edgar <adgar@google.com>2016-04-12 22:23:08 -0400
committerMike Edgar <adgar@google.com>2016-04-14 23:00:35 -0400
commit3b526f863aa154e76ac9d93547ac7a90f6e579e0 (patch)
treec1b2d9e0b0658e72ebcfe27772bfeead03e046ea /org.eclipse.jgit.http.test/src
parent4812fdab61c1ac61863247574be03425ba3bc674 (diff)
downloadjgit-3b526f863aa154e76ac9d93547ac7a90f6e579e0.tar.gz
jgit-3b526f863aa154e76ac9d93547ac7a90f6e579e0.zip
Fix Buck build broken by 4812fda.
Creates a source directory under org.eclipse.jgit.http.test for the new support class. Signed-off-by: Michael Edgar <adgar@google.com> Change-Id: Ie49492c2bbe5c1db96ceb0dc06fa7cb9f927431a
Diffstat (limited to 'org.eclipse.jgit.http.test/src')
-rw-r--r--org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java b/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java
new file mode 100644
index 0000000000..485cced778
--- /dev/null
+++ b/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java
@@ -0,0 +1,52 @@
+package org.eclipse.jgit.http.test;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
+import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
+import org.eclipse.jgit.lib.RefDatabase;
+
+/**
+ * An {@link InMemoryRepository} whose refs can be made unreadable for testing
+ * purposes.
+ */
+class RefsUnreadableInMemoryRepository extends InMemoryRepository {
+
+ private final RefsUnreadableRefDatabase refs;
+
+ private volatile boolean failing;
+
+ RefsUnreadableInMemoryRepository(DfsRepositoryDescription repoDesc) {
+ super(repoDesc);
+ refs = new RefsUnreadableRefDatabase();
+ failing = false;
+ }
+
+ @Override
+ public RefDatabase getRefDatabase() {
+ return refs;
+ }
+
+ /**
+ * Make the ref database unable to scan its refs.
+ * <p>
+ * It may be useful to follow a call to startFailing with a call to
+ * {@link RefDatabase#refresh()}, ensuring the next ref read fails.
+ */
+ void startFailing() {
+ failing = true;
+ }
+
+ private class RefsUnreadableRefDatabase extends MemRefDatabase {
+
+ @Override
+ protected RefCache scanAllRefs() throws IOException {
+ if (failing) {
+ throw new IOException("disk failed, no refs found");
+ } else {
+ return super.scanAllRefs();
+ }
+ }
+ }
+}