Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PackWriterBitmapPreparerTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package org.eclipse.jgit.internal.storage.pack;
  2. import static org.eclipse.jgit.storage.pack.PackConfig.DEFAULT_BITMAP_DISTANT_COMMIT_SPAN;
  3. import static org.eclipse.jgit.storage.pack.PackConfig.DEFAULT_BITMAP_RECENT_COMMIT_COUNT;
  4. import static org.eclipse.jgit.storage.pack.PackConfig.DEFAULT_BITMAP_RECENT_COMMIT_SPAN;
  5. import static org.junit.Assert.assertEquals;
  6. import java.io.IOException;
  7. import java.util.Collection;
  8. import java.util.Collections;
  9. import java.util.List;
  10. import java.util.Set;
  11. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  12. import org.eclipse.jgit.errors.MissingObjectException;
  13. import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
  14. import org.eclipse.jgit.lib.AbbreviatedObjectId;
  15. import org.eclipse.jgit.lib.AnyObjectId;
  16. import org.eclipse.jgit.lib.ObjectId;
  17. import org.eclipse.jgit.lib.ObjectLoader;
  18. import org.eclipse.jgit.lib.ObjectReader;
  19. import org.eclipse.jgit.storage.pack.PackConfig;
  20. import org.junit.Test;
  21. /** Tests for the {@link PackWriterBitmapPreparer}. */
  22. public class PackWriterBitmapPreparerTest {
  23. private static class StubObjectReader extends ObjectReader {
  24. @Override
  25. public ObjectReader newReader() {
  26. return null;
  27. }
  28. @Override
  29. public Collection<ObjectId> resolve(AbbreviatedObjectId id)
  30. throws IOException {
  31. return null;
  32. }
  33. @Override
  34. public ObjectLoader open(AnyObjectId objectId, int typeHint)
  35. throws MissingObjectException, IncorrectObjectTypeException,
  36. IOException {
  37. return null;
  38. }
  39. @Override
  40. public Set<ObjectId> getShallowCommits() throws IOException {
  41. return null;
  42. }
  43. @Override
  44. public void close() {
  45. // stub
  46. }
  47. }
  48. @Test
  49. public void testNextSelectionDistanceForActiveBranch() throws Exception {
  50. PackWriterBitmapPreparer preparer = newPeparer(
  51. DEFAULT_BITMAP_RECENT_COMMIT_COUNT, // 20000
  52. DEFAULT_BITMAP_RECENT_COMMIT_SPAN, // 100
  53. DEFAULT_BITMAP_DISTANT_COMMIT_SPAN); // 5000
  54. int[][] distancesAndSpans = { { 0, 100 }, { 100, 100 }, { 10000, 100 },
  55. { 20000, 100 }, { 20100, 100 }, { 20102, 102 }, { 20200, 200 },
  56. { 22200, 2200 }, { 24999, 4999 }, { 25000, 5000 },
  57. { 50000, 5000 }, { 1000000, 5000 }, };
  58. for (int[] pair : distancesAndSpans) {
  59. assertEquals(pair[1], preparer.nextSpan(pair[0]));
  60. }
  61. }
  62. @Test
  63. public void testNextSelectionDistanceWithFewerRecentCommits()
  64. throws Exception {
  65. PackWriterBitmapPreparer preparer = newPeparer(1000,
  66. DEFAULT_BITMAP_RECENT_COMMIT_SPAN, // 100
  67. DEFAULT_BITMAP_DISTANT_COMMIT_SPAN); // 5000
  68. int[][] distancesAndSpans = { { 0, 100 }, { 100, 100 }, { 1000, 100 },
  69. { 1100, 100 }, { 1111, 111 }, { 2000, 1000 }, { 5999, 4999 },
  70. { 6000, 5000 }, { 10000, 5000 }, { 50000, 5000 },
  71. { 1000000, 5000 } };
  72. for (int[] pair : distancesAndSpans) {
  73. assertEquals(pair[1], preparer.nextSpan(pair[0]));
  74. }
  75. }
  76. @Test
  77. public void testNextSelectionDistanceWithSmallerRecentSpan()
  78. throws Exception {
  79. PackWriterBitmapPreparer preparer = newPeparer(
  80. DEFAULT_BITMAP_RECENT_COMMIT_COUNT, // 20000
  81. 10, // recent span
  82. DEFAULT_BITMAP_DISTANT_COMMIT_SPAN); // 5000
  83. int[][] distancesAndSpans = { { 0, 10 }, { 100, 10 }, { 10000, 10 },
  84. { 20000, 10 }, { 20010, 10 }, { 20012, 12 }, { 20050, 50 },
  85. { 20200, 200 }, { 22200, 2200 }, { 24999, 4999 },
  86. { 25000, 5000 }, { 50000, 5000 }, { 1000000, 5000 } };
  87. for (int[] pair : distancesAndSpans) {
  88. assertEquals(pair[1], preparer.nextSpan(pair[0]));
  89. }
  90. }
  91. @Test
  92. public void testNextSelectionDistanceWithSmallerDistantSpan()
  93. throws Exception {
  94. PackWriterBitmapPreparer preparer = newPeparer(
  95. DEFAULT_BITMAP_RECENT_COMMIT_COUNT, // 20000
  96. DEFAULT_BITMAP_RECENT_COMMIT_SPAN, // 100
  97. 1000);
  98. int[][] distancesAndSpans = { { 0, 100 }, { 100, 100 }, { 10000, 100 },
  99. { 20000, 100 }, { 20100, 100 }, { 20102, 102 }, { 20200, 200 },
  100. { 20999, 999 }, { 21000, 1000 }, { 22000, 1000 },
  101. { 25000, 1000 }, { 50000, 1000 }, { 1000000, 1000 } };
  102. for (int[] pair : distancesAndSpans) {
  103. assertEquals(pair[1], preparer.nextSpan(pair[0]));
  104. }
  105. }
  106. private PackWriterBitmapPreparer newPeparer(int recentCount, int recentSpan,
  107. int distantSpan) throws IOException {
  108. List<ObjectToPack> objects = Collections.emptyList();
  109. Set<ObjectId> wants = Collections.emptySet();
  110. PackConfig config = new PackConfig();
  111. config.setBitmapRecentCommitCount(recentCount);
  112. config.setBitmapRecentCommitSpan(recentSpan);
  113. config.setBitmapDistantCommitSpan(distantSpan);
  114. PackBitmapIndexBuilder indexBuilder = new PackBitmapIndexBuilder(
  115. objects);
  116. return new PackWriterBitmapPreparer(new StubObjectReader(),
  117. indexBuilder, null, wants, config);
  118. }
  119. }