You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HugeFileTest.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (C) 2012, Robin Rosenberg <robin.rosenberg@dewire.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.api;
  44. import static org.junit.Assert.assertEquals;
  45. import java.io.File;
  46. import java.io.RandomAccessFile;
  47. import java.util.Arrays;
  48. import java.util.Collection;
  49. import org.eclipse.jgit.api.ResetCommand.ResetType;
  50. import org.eclipse.jgit.lib.RepositoryTestCase;
  51. import org.junit.Ignore;
  52. import org.junit.Test;
  53. public class HugeFileTest extends RepositoryTestCase {
  54. private long t = System.currentTimeMillis();
  55. private long lastt = t;
  56. private void measure(String name) {
  57. long c = System.currentTimeMillis();
  58. System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
  59. lastt = c;
  60. }
  61. @Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
  62. @Test
  63. public void testAddHugeFile() throws Exception {
  64. measure("Commencing test");
  65. File file = new File(db.getWorkTree(), "a.txt");
  66. RandomAccessFile rf = new RandomAccessFile(file, "rw");
  67. rf.setLength(4429185024L);
  68. rf.close();
  69. measure("Created file");
  70. Git git = new Git(db);
  71. git.add().addFilepattern("a.txt").call();
  72. measure("Added file");
  73. assertEquals(
  74. "[a.txt, mode:100644, length:134217728, sha1:b8cfba97c2b962a44f080b3ca4e03b3204b6a350]",
  75. indexState(LENGTH | CONTENT_ID));
  76. Status status = git.status().call();
  77. measure("Status after add");
  78. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  79. assertEquals(0, status.getChanged().size());
  80. assertEquals(0, status.getConflicting().size());
  81. assertEquals(0, status.getMissing().size());
  82. assertEquals(0, status.getModified().size());
  83. assertEquals(0, status.getRemoved().size());
  84. assertEquals(0, status.getUntracked().size());
  85. // Does not change anything, but modified timestamp
  86. rf = new RandomAccessFile(file, "rw");
  87. rf.write(0);
  88. rf.close();
  89. status = git.status().call();
  90. measure("Status after non-modifying update");
  91. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  92. assertEquals(0, status.getChanged().size());
  93. assertEquals(0, status.getConflicting().size());
  94. assertEquals(0, status.getMissing().size());
  95. assertEquals(0, status.getModified().size());
  96. assertEquals(0, status.getRemoved().size());
  97. assertEquals(0, status.getUntracked().size());
  98. // Change something
  99. rf = new RandomAccessFile(file, "rw");
  100. rf.write('a');
  101. rf.close();
  102. status = git.status().call();
  103. measure("Status after modifying update");
  104. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  105. assertEquals(0, status.getChanged().size());
  106. assertEquals(0, status.getConflicting().size());
  107. assertEquals(0, status.getMissing().size());
  108. assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
  109. assertEquals(0, status.getRemoved().size());
  110. assertEquals(0, status.getUntracked().size());
  111. // Truncate mod 4G and re-establish equality
  112. rf = new RandomAccessFile(file, "rw");
  113. rf.setLength(134217728L);
  114. rf.write(0);
  115. rf.close();
  116. status = git.status().call();
  117. measure("Status after truncating update");
  118. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  119. assertEquals(0, status.getChanged().size());
  120. assertEquals(0, status.getConflicting().size());
  121. assertEquals(0, status.getMissing().size());
  122. assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
  123. assertEquals(0, status.getRemoved().size());
  124. assertEquals(0, status.getUntracked().size());
  125. // Change something
  126. rf = new RandomAccessFile(file, "rw");
  127. rf.write('a');
  128. rf.close();
  129. status = git.status().call();
  130. measure("Status after modifying and truncating update");
  131. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  132. assertEquals(0, status.getChanged().size());
  133. assertEquals(0, status.getConflicting().size());
  134. assertEquals(0, status.getMissing().size());
  135. assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
  136. assertEquals(0, status.getRemoved().size());
  137. assertEquals(0, status.getUntracked().size());
  138. // Truncate to entry length becomes negative int
  139. rf = new RandomAccessFile(file, "rw");
  140. rf.setLength(3429185024L);
  141. rf.write(0);
  142. rf.close();
  143. git.add().addFilepattern("a.txt").call();
  144. measure("Added truncated file");
  145. assertEquals(
  146. "[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]",
  147. indexState(LENGTH | CONTENT_ID));
  148. status = git.status().call();
  149. measure("Status after status on truncated file");
  150. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  151. assertEquals(0, status.getChanged().size());
  152. assertEquals(0, status.getConflicting().size());
  153. assertEquals(0, status.getMissing().size());
  154. assertEquals(0, status.getModified().size());
  155. assertEquals(0, status.getRemoved().size());
  156. assertEquals(0, status.getUntracked().size());
  157. // Change something
  158. rf = new RandomAccessFile(file, "rw");
  159. rf.write('a');
  160. rf.close();
  161. status = git.status().call();
  162. measure("Status after modifying and truncating update");
  163. assertCollectionEquals(Arrays.asList("a.txt"), status.getAdded());
  164. assertEquals(0, status.getChanged().size());
  165. assertEquals(0, status.getConflicting().size());
  166. assertEquals(0, status.getMissing().size());
  167. assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
  168. assertEquals(0, status.getRemoved().size());
  169. assertEquals(0, status.getUntracked().size());
  170. git.commit().setMessage("make a commit").call();
  171. measure("After commit");
  172. status = git.status().call();
  173. measure("After status after commit");
  174. assertEquals(0, status.getAdded().size());
  175. assertEquals(0, status.getChanged().size());
  176. assertEquals(0, status.getConflicting().size());
  177. assertEquals(0, status.getMissing().size());
  178. assertCollectionEquals(Arrays.asList("a.txt"), status.getModified());
  179. assertEquals(0, status.getRemoved().size());
  180. assertEquals(0, status.getUntracked().size());
  181. git.reset().setMode(ResetType.HARD).call();
  182. measure("After reset --hard");
  183. assertEquals(
  184. "[a.txt, mode:100644, length:-865782272, sha1:59b3282f8f59f22d953df956ad3511bf2dc660fd]",
  185. indexState(LENGTH | CONTENT_ID));
  186. status = git.status().call();
  187. measure("Status after hard reset");
  188. assertEquals(0, status.getAdded().size());
  189. assertEquals(0, status.getChanged().size());
  190. assertEquals(0, status.getConflicting().size());
  191. assertEquals(0, status.getMissing().size());
  192. assertEquals(0, status.getModified().size());
  193. assertEquals(0, status.getRemoved().size());
  194. assertEquals(0, status.getUntracked().size());
  195. }
  196. private void assertCollectionEquals(Collection<?> asList,
  197. Collection<?> added) {
  198. assertEquals(asList.toString(), added.toString());
  199. }
  200. }