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 super.tearDown();
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 protected RevCommit commitChain(int depth) throws Exception {
65 if (depth <= 0)
66 throw new IllegalArgumentException("Chain depth must be > 0");
67 CommitBuilder cb = tr.commit();
68 RevCommit tip;
69 do {
70 --depth;
71 tip = cb.add("a", "" + depth).message("" + depth).create();
72 cb = cb.child();
73 } while (depth > 0);
74 return tip;
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 protected RevCommit commitChain(int depth, int width) throws Exception {
97 if (depth <= 0) {
98 throw new IllegalArgumentException("Chain depth must be > 0");
99 }
100 if (width <= 0) {
101 throw new IllegalArgumentException("Number of files per commit must be > 0");
102 }
103 CommitBuilder cb = tr.commit();
104 RevCommit tip = null;
105 do {
106 --depth;
107 for (int i=0; i < width; i++) {
108 String id = depth + "-" + i;
109 cb.add("a" + id, id).message(id);
110 }
111 tip = cb.create();
112 cb = cb.child();
113 } while (depth > 0);
114 return tip;
115 }
116
117 protected long lastModified(AnyObjectId objectId) {
118 return repo.getFS()
119 .lastModifiedInstant(repo.getObjectDatabase().fileFor(objectId))
120 .toEpochMilli();
121 }
122
123 protected static void fsTick() throws InterruptedException, IOException {
124 RepositoryTestCase.fsTick(null);
125 }
126 }