From 3b526f863aa154e76ac9d93547ac7a90f6e579e0 Mon Sep 17 00:00:00 2001 From: Mike Edgar Date: Tue, 12 Apr 2016 22:23:08 -0400 Subject: 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 Change-Id: Ie49492c2bbe5c1db96ceb0dc06fa7cb9f927431a --- .../test/RefsUnreadableInMemoryRepository.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java (limited to 'org.eclipse.jgit.http.test/src/org') 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. + *

+ * 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(); + } + } + } +} -- cgit v1.2.3