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.

GcBasicPackingTest.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (C) 2012, Christian Halstrick <christian.halstrick@sap.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.internal.storage.file;
  44. import static org.junit.Assert.assertEquals;
  45. import java.io.IOException;
  46. import java.util.Collection;
  47. import java.util.Iterator;
  48. import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
  49. import org.eclipse.jgit.revwalk.RevCommit;
  50. import org.junit.Test;
  51. public class GcBasicPackingTest extends GcTestCase {
  52. @Test
  53. public void repackEmptyRepo_noPackCreated() throws IOException {
  54. gc.repack();
  55. assertEquals(0, repo.getObjectDatabase().getPacks().size());
  56. }
  57. @Test
  58. public void testPackRepoWithNoRefs() throws Exception {
  59. tr.commit().add("A", "A").add("B", "B").create();
  60. stats = gc.getStatistics();
  61. assertEquals(4, stats.numberOfLooseObjects);
  62. assertEquals(0, stats.numberOfPackedObjects);
  63. gc.gc();
  64. stats = gc.getStatistics();
  65. assertEquals(4, stats.numberOfLooseObjects);
  66. assertEquals(0, stats.numberOfPackedObjects);
  67. assertEquals(0, stats.numberOfPackFiles);
  68. }
  69. @Test
  70. public void testPack2Commits() throws Exception {
  71. BranchBuilder bb = tr.branch("refs/heads/master");
  72. bb.commit().add("A", "A").add("B", "B").create();
  73. bb.commit().add("A", "A2").add("B", "B2").create();
  74. stats = gc.getStatistics();
  75. assertEquals(8, stats.numberOfLooseObjects);
  76. assertEquals(0, stats.numberOfPackedObjects);
  77. gc.gc();
  78. stats = gc.getStatistics();
  79. assertEquals(0, stats.numberOfLooseObjects);
  80. assertEquals(8, stats.numberOfPackedObjects);
  81. assertEquals(1, stats.numberOfPackFiles);
  82. }
  83. @Test
  84. public void testPackAllObjectsInOnePack() throws Exception {
  85. tr.branch("refs/heads/master").commit().add("A", "A").add("B", "B")
  86. .create();
  87. stats = gc.getStatistics();
  88. assertEquals(4, stats.numberOfLooseObjects);
  89. assertEquals(0, stats.numberOfPackedObjects);
  90. gc.gc();
  91. stats = gc.getStatistics();
  92. assertEquals(0, stats.numberOfLooseObjects);
  93. assertEquals(4, stats.numberOfPackedObjects);
  94. assertEquals(1, stats.numberOfPackFiles);
  95. // Do the gc again and check that it hasn't changed anything
  96. gc.gc();
  97. stats = gc.getStatistics();
  98. assertEquals(0, stats.numberOfLooseObjects);
  99. assertEquals(4, stats.numberOfPackedObjects);
  100. assertEquals(1, stats.numberOfPackFiles);
  101. }
  102. @Test
  103. public void testPackCommitsAndLooseOne() throws Exception {
  104. BranchBuilder bb = tr.branch("refs/heads/master");
  105. RevCommit first = bb.commit().add("A", "A").add("B", "B").create();
  106. bb.commit().add("A", "A2").add("B", "B2").create();
  107. tr.update("refs/heads/master", first);
  108. stats = gc.getStatistics();
  109. assertEquals(8, stats.numberOfLooseObjects);
  110. assertEquals(0, stats.numberOfPackedObjects);
  111. gc.gc();
  112. stats = gc.getStatistics();
  113. assertEquals(0, stats.numberOfLooseObjects);
  114. assertEquals(8, stats.numberOfPackedObjects);
  115. assertEquals(2, stats.numberOfPackFiles);
  116. }
  117. @Test
  118. public void testNotPackTwice() throws Exception {
  119. BranchBuilder bb = tr.branch("refs/heads/master");
  120. RevCommit first = bb.commit().message("M").add("M", "M").create();
  121. bb.commit().message("B").add("B", "Q").create();
  122. bb.commit().message("A").add("A", "A").create();
  123. RevCommit second = tr.commit().parent(first).message("R").add("R", "Q")
  124. .create();
  125. tr.update("refs/tags/t1", second);
  126. Collection<PackFile> oldPacks = tr.getRepository().getObjectDatabase()
  127. .getPacks();
  128. assertEquals(0, oldPacks.size());
  129. stats = gc.getStatistics();
  130. assertEquals(11, stats.numberOfLooseObjects);
  131. assertEquals(0, stats.numberOfPackedObjects);
  132. gc.setExpireAgeMillis(0);
  133. fsTick();
  134. gc.gc();
  135. stats = gc.getStatistics();
  136. assertEquals(0, stats.numberOfLooseObjects);
  137. Iterator<PackFile> pIt = repo.getObjectDatabase().getPacks().iterator();
  138. long c = pIt.next().getObjectCount();
  139. if (c == 9)
  140. assertEquals(2, pIt.next().getObjectCount());
  141. else {
  142. assertEquals(2, c);
  143. assertEquals(9, pIt.next().getObjectCount());
  144. }
  145. }
  146. }