Пример #1
0
  @Test
  public void testCollectionWithGarbage() throws Exception {
    RevCommit commit0 = commit().message("0").create();
    RevCommit commit1 = commit().message("1").parent(commit0).create();
    git.update("master", commit0);

    assertTrue("commit0 reachable", isReachable(repo, commit0));
    assertFalse("commit1 garbage", isReachable(repo, commit1));
    gcNoTtl();

    assertEquals(2, odb.getPacks().length);
    DfsPackFile gc = null;
    DfsPackFile garbage = null;
    for (DfsPackFile pack : odb.getPacks()) {
      DfsPackDescription d = pack.getPackDescription();
      if (d.getPackSource() == GC) {
        gc = pack;
      } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
        garbage = pack;
      } else {
        fail("unexpected " + d.getPackSource());
      }
    }

    assertNotNull("created GC pack", gc);
    assertTrue(isObjectInPack(commit0, gc));

    assertNotNull("created UNREACHABLE_GARBAGE pack", garbage);
    assertTrue(isObjectInPack(commit1, garbage));
  }
Пример #2
0
 private int countPacks(PackSource source) throws IOException {
   int cnt = 0;
   for (DfsPackFile pack : odb.getPacks()) {
     if (pack.getPackDescription().getPackSource() == source) {
       cnt++;
     }
   }
   return cnt;
 }
Пример #3
0
  @Test
  public void testCollectionWithGarbageAndGarbagePacksPurged() throws Exception {
    RevCommit commit0 = commit().message("0").create();
    RevCommit commit1 = commit().message("1").parent(commit0).create();
    git.update("master", commit0);

    gcNoTtl();
    gcWithTtl();

    // The repository has an UNREACHABLE_GARBAGE pack that could have
    // expired, but since we never purge the most recent UNREACHABLE_GARBAGE
    // pack, it must have survived the GC.
    boolean commit1Found = false;
    for (DfsPackFile pack : odb.getPacks()) {
      DfsPackDescription d = pack.getPackDescription();
      if (d.getPackSource() == GC) {
        assertTrue("has commit0", isObjectInPack(commit0, pack));
        assertFalse("no commit1", isObjectInPack(commit1, pack));
      } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
        commit1Found |= isObjectInPack(commit1, pack);
      } else {
        fail("unexpected " + d.getPackSource());
      }
    }
    assertTrue("garbage commit1 still readable", commit1Found);

    // Find oldest UNREACHABLE_GARBAGE; it will be pruned by next GC.
    DfsPackDescription oldestGarbagePack = null;
    for (DfsPackFile pack : odb.getPacks()) {
      DfsPackDescription d = pack.getPackDescription();
      if (d.getPackSource() == UNREACHABLE_GARBAGE) {
        oldestGarbagePack = oldestPack(oldestGarbagePack, d);
      }
    }
    assertNotNull("has UNREACHABLE_GARBAGE", oldestGarbagePack);

    gcWithTtl();
    assertTrue("has packs", odb.getPacks().length > 0);
    for (DfsPackFile pack : odb.getPacks()) {
      assertNotEquals(oldestGarbagePack, pack.getPackDescription());
    }
  }
Пример #4
0
  @Test
  public void testCollectionWithNoGarbage() throws Exception {
    RevCommit commit0 = commit().message("0").create();
    RevCommit commit1 = commit().message("1").parent(commit0).create();
    git.update("master", commit1);

    assertTrue("commit0 reachable", isReachable(repo, commit0));
    assertTrue("commit1 reachable", isReachable(repo, commit1));

    // Packs start out as INSERT.
    assertEquals(2, odb.getPacks().length);
    for (DfsPackFile pack : odb.getPacks()) {
      assertEquals(INSERT, pack.getPackDescription().getPackSource());
    }

    gcNoTtl();

    // Single GC pack present with all objects.
    assertEquals(1, odb.getPacks().length);
    DfsPackFile pack = odb.getPacks()[0];
    assertEquals(GC, pack.getPackDescription().getPackSource());
    assertTrue("commit0 in pack", isObjectInPack(commit0, pack));
    assertTrue("commit1 in pack", isObjectInPack(commit1, pack));
  }
Пример #5
0
 private void run(DfsGarbageCollector gc) throws IOException {
   assertTrue("gc repacked", gc.pack(null));
   odb.clearCache();
 }