1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.http.test;
11
12 import java.io.IOException;
13 import java.util.List;
14 import java.util.Map;
15 import java.util.Set;
16
17 import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
18 import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
19 import org.eclipse.jgit.lib.ObjectId;
20 import org.eclipse.jgit.lib.Ref;
21 import org.eclipse.jgit.lib.RefDatabase;
22
23
24
25
26
27 class RefsUnreadableInMemoryRepository extends InMemoryRepository {
28
29 private final RefsUnreadableRefDatabase refs;
30
31 private volatile boolean failing;
32
33 RefsUnreadableInMemoryRepository(DfsRepositoryDescription repoDesc) {
34 super(repoDesc);
35 refs = new RefsUnreadableRefDatabase();
36 failing = false;
37 }
38
39
40 @Override
41 public RefDatabase getRefDatabase() {
42 return refs;
43 }
44
45
46
47
48
49
50
51 void startFailing() {
52 failing = true;
53 }
54
55 private class RefsUnreadableRefDatabase extends MemRefDatabase {
56
57
58 @Override
59 public Ref exactRef(String name) throws IOException {
60 if (failing) {
61 throw new IOException("disk failed, no refs found");
62 }
63 return super.exactRef(name);
64 }
65
66
67 @Override
68 public Map<String, Ref> getRefs(String prefix) throws IOException {
69 if (failing) {
70 throw new IOException("disk failed, no refs found");
71 }
72
73 return super.getRefs(prefix);
74 }
75
76
77 @Override
78 public List<Ref> getRefsByPrefix(String prefix) throws IOException {
79 if (failing) {
80 throw new IOException("disk failed, no refs found");
81 }
82
83 return super.getRefsByPrefix(prefix);
84 }
85
86
87 @Override
88 public List<Ref> getRefsByPrefixWithExclusions(String include, Set<String> excludes)
89 throws IOException {
90 if (failing) {
91 throw new IOException("disk failed, no refs found");
92 }
93
94 return super.getRefsByPrefixWithExclusions(include, excludes);
95 }
96
97
98 @Override
99 public Set<Ref> getTipsWithSha1(ObjectId id) throws IOException {
100 if (failing) {
101 throw new IOException("disk failed, no refs found");
102 }
103 return super.getTipsWithSha1(id);
104 }
105 }
106 }