1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import java.io.IOException;
14
15 import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics;
16 import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
17 import org.eclipse.jgit.junit.RepositoryTestCase;
18 import org.eclipse.jgit.junit.TestRepository;
19 import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
20 import org.eclipse.jgit.lib.AnyObjectId;
21 import org.eclipse.jgit.revwalk.RevCommit;
22 import org.eclipse.jgit.revwalk.RevWalk;
23 import org.junit.After;
24 import org.junit.Before;
25
26 public abstract class GcTestCase extends LocalDiskRepositoryTestCase {
27 protected TestRepository<FileRepository> tr;
28 protected FileRepository repo;
29 protected GC gc;
30 protected RepoStatistics stats;
31
32 @Override
33 @Before
34 public void setUp() throws Exception {
35 super.setUp();
36 repo = createWorkRepository();
37 tr = new TestRepository<>(repo, new RevWalk(repo),
38 mockSystemReader);
39 gc = new GC(repo);
40 }
41
42 @Override
43 @After
44 public void tearDown() throws Exception {
45 tr.close();
46 super.tearDown();
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 protected RevCommit commitChain(int depth) throws Exception {
66 if (depth <= 0)
67 throw new IllegalArgumentException("Chain depth must be > 0");
68 CommitBuilder cb = tr.commit();
69 RevCommit tip;
70 do {
71 --depth;
72 tip = cb.add("a", "" + depth).message("" + depth).create();
73 cb = cb.child();
74 } while (depth > 0);
75 return tip;
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 protected RevCommit commitChain(int depth, int width) throws Exception {
98 if (depth <= 0) {
99 throw new IllegalArgumentException("Chain depth must be > 0");
100 }
101 if (width <= 0) {
102 throw new IllegalArgumentException("Number of files per commit must be > 0");
103 }
104 CommitBuilder cb = tr.commit();
105 RevCommit tip = null;
106 do {
107 --depth;
108 for (int i=0; i < width; i++) {
109 String id = depth + "-" + i;
110 cb.add("a" + id, id).message(id);
111 }
112 tip = cb.create();
113 cb = cb.child();
114 } while (depth > 0);
115 return tip;
116 }
117
118 protected long lastModified(AnyObjectId objectId) {
119 return repo.getFS()
120 .lastModifiedInstant(repo.getObjectDatabase().fileFor(objectId))
121 .toEpochMilli();
122 }
123
124 protected static void fsTick() throws InterruptedException, IOException {
125 RepositoryTestCase.fsTick(null);
126 }
127 }