1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.api;
44
45 import static org.junit.Assert.assertEquals;
46
47 import java.io.File;
48 import java.io.RandomAccessFile;
49 import java.util.Arrays;
50 import java.util.Collection;
51
52 import org.eclipse.jgit.api.ResetCommand.ResetType;
53 import org.eclipse.jgit.junit.RepositoryTestCase;
54 import org.junit.After;
55 import org.junit.Before;
56 import org.junit.Ignore;
57 import org.junit.Test;
58
59 public class HugeFileTest extends RepositoryTestCase {
60
61 private long t = System.currentTimeMillis();
62
63 private long lastt = t;
64
65 private Git git;
66
67 private void measure(String name) {
68 long c = System.currentTimeMillis();
69 System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
70 lastt = c;
71 }
72
73 @Before
74 public void before() {
75 git = new Git(db);
76 }
77
78 @After
79 public void after() {
80 if (git != null) {
81 git.close();
82 }
83 }
84
85 @Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
86 @Test
87 public void testAddHugeFile() throws Exception {
88 measure("Commencing test");
89 File file = new File(db.getWorkTree(), "a.txt");
90 RandomAccessFile rf = new RandomAccessFile(file, "rw");
91 rf.setLength(4429185024L);
92 rf.close();
93 measure("Created file");
94
95 git.add().addFilepattern("a.txt").call();
96 measure("Added file");
97 assertEquals(
98 "[a.txt, mode:100644, length:134217728, sha1:b8cfba97c2b962a44f080b3ca4e03b3204b6a350]",
99 indexState(LENGTH | CONTENT_ID));
100
101 Status status = git.status().call();
102 measure("Status after add");
103 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
104 assertEquals(0, status.getChanged().size());
105 assertEquals(0, status.getConflicting().size());
106 assertEquals(0, status.getMissing().size());
107 assertEquals(0, status.getModified().size());
108 assertEquals(0, status.getRemoved().size());
109 assertEquals(0, status.getUntracked().size());
110
111
112 rf = new RandomAccessFile(file, "rw");
113 rf.write(0);
114 rf.close();
115
116 status = git.status().call();
117 measure("Status after non-modifying update");
118
119 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
120 assertEquals(0, status.getChanged().size());
121 assertEquals(0, status.getConflicting().size());
122 assertEquals(0, status.getMissing().size());
123 assertEquals(0, status.getModified().size());
124 assertEquals(0, status.getRemoved().size());
125 assertEquals(0, status.getUntracked().size());
126
127
128 rf = new RandomAccessFile(file, "rw");
129 rf.write('a');
130 rf.close();
131
132 status = git.status().call();
133 measure("Status after modifying update");
134
135 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
136 assertEquals(0, status.getChanged().size());
137 assertEquals(0, status.getConflicting().size());
138 assertEquals(0, status.getMissing().size());
139 assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
140 assertEquals(0, status.getRemoved().size());
141 assertEquals(0, status.getUntracked().size());
142
143
144 rf = new RandomAccessFile(file, "rw");
145 rf.setLength(134217728L);
146 rf.write(0);
147 rf.close();
148
149 status = git.status().call();
150 measure("Status after truncating update");
151
152 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
153 assertEquals(0, status.getChanged().size());
154 assertEquals(0, status.getConflicting().size());
155 assertEquals(0, status.getMissing().size());
156 assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
157 assertEquals(0, status.getRemoved().size());
158 assertEquals(0, status.getUntracked().size());
159
160
161 rf = new RandomAccessFile(file, "rw");
162 rf.write('a');
163 rf.close();
164
165 status = git.status().call();
166 measure("Status after modifying and truncating update");
167
168 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
169 assertEquals(0, status.getChanged().size());
170 assertEquals(0, status.getConflicting().size());
171 assertEquals(0, status.getMissing().size());
172 assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
173 assertEquals(0, status.getRemoved().size());
174 assertEquals(0, status.getUntracked().size());
175
176
177 rf = new RandomAccessFile(file, "rw");
178 rf.setLength(3429185024L);
179 rf.write(0);
180 rf.close();
181
182 git.add().addFilepattern("a.txt").call();
183 measure("Added truncated file");
184 assertEquals(
185 "[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]",
186 indexState(LENGTH | CONTENT_ID));
187
188 status = git.status().call();
189 measure("Status after status on truncated file");
190
191 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
192 assertEquals(0, status.getChanged().size());
193 assertEquals(0, status.getConflicting().size());
194 assertEquals(0, status.getMissing().size());
195 assertEquals(0, status.getModified().size());
196 assertEquals(0, status.getRemoved().size());
197 assertEquals(0, status.getUntracked().size());
198
199
200 rf = new RandomAccessFile(file, "rw");
201 rf.write('a');
202 rf.close();
203
204 status = git.status().call();
205 measure("Status after modifying and truncating update");
206
207 assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
208 assertEquals(0, status.getChanged().size());
209 assertEquals(0, status.getConflicting().size());
210 assertEquals(0, status.getMissing().size());
211 assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
212 assertEquals(0, status.getRemoved().size());
213 assertEquals(0, status.getUntracked().size());
214
215 git.commit().setMessage("make a commit").call();
216 measure("After commit");
217 status = git.status().call();
218 measure("After status after commit");
219
220 assertEquals(0, status.getAdded().size());
221 assertEquals(0, status.getChanged().size());
222 assertEquals(0, status.getConflicting().size());
223 assertEquals(0, status.getMissing().size());
224 assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
225 assertEquals(0, status.getRemoved().size());
226 assertEquals(0, status.getUntracked().size());
227
228 git.reset().setMode(ResetType.HARD).call();
229 measure("After reset --hard");
230 assertEquals(
231 "[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]",
232 indexState(LENGTH | CONTENT_ID));
233
234 status = git.status().call();
235 measure("Status after hard reset");
236
237 assertEquals(0, status.getAdded().size());
238 assertEquals(0, status.getChanged().size());
239 assertEquals(0, status.getConflicting().size());
240 assertEquals(0, status.getMissing().size());
241 assertEquals(0, status.getModified().size());
242 assertEquals(0, status.getRemoved().size());
243 assertEquals(0, status.getUntracked().size());
244 }
245
246 private static void assertCollectionEquals(Collection<?> asList,
247 Collection<?> added) {
248 assertEquals(asList.toString(), added.toString());
249 }
250
251 }