Browse Source
Now if refs are unreadable when serving an upload pack the handler will fail due to the actual underlying failure. Previously all wants would be rejected as invalid because Repository.getAllRefs() returned an empty map. Testing this required a new subclass of InMemoryRepository so that an IOException could be injected at the correct time. Signed-off-by: Michael Edgar <adgar@google.com> Change-Id: Iac708b1db9d0ccce08c4ef5ace599ea0b57afdc0stable-4.4
Mike Edgar
9 years ago
6 changed files with 150 additions and 24 deletions
@ -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(); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue