@ -51,21 +51,32 @@ import java.util.Iterator;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.junit.Test ;
import org.eclipse.jgit.storage.pack.PackConfig ;
import org.junit.experimental.theories.DataPoints ;
import org.junit.experimental.theories.Theories ;
import org.junit.experimental.theories.Theory ;
import org.junit.runner.RunWith ;
@RunWith ( Theories . class )
public class GcBasicPackingTest extends GcTestCase {
public class GcBasicPackingTest extends GcTestCase {
@Test
@DataPoints
public void repackEmptyRepo_noPackCreated ( ) throws IOException {
public static boolean [ ] aggressiveValues = { true , false } ;
@Theory
public void repackEmptyRepo_noPackCreated ( boolean aggressive )
throws IOException {
configureGc ( gc , aggressive ) ;
gc . repack ( ) ;
gc . repack ( ) ;
assertEquals ( 0 , repo . getObjectDatabase ( ) . getPacks ( ) . size ( ) ) ;
assertEquals ( 0 , repo . getObjectDatabase ( ) . getPacks ( ) . size ( ) ) ;
}
}
@Test
@Theory
public void testPackRepoWithNoRefs ( ) throws Exception {
public void testPackRepoWithNoRefs ( boolean aggressive ) throws Exception {
tr . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
tr . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
@ -73,8 +84,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 0 , stats . numberOfPackFiles ) ;
assertEquals ( 0 , stats . numberOfPackFiles ) ;
}
}
@Test
@Theory
public void testPack2Commits ( ) throws Exception {
public void testPack2Commits ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
@ -82,6 +93,7 @@ public class GcBasicPackingTest extends GcTestCase {
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -89,13 +101,15 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 1 , stats . numberOfPackFiles ) ;
assertEquals ( 1 , stats . numberOfPackFiles ) ;
}
}
@Test
@Theory
public void testPackAllObjectsInOnePack ( ) throws Exception {
public void testPackAllObjectsInOnePack ( boolean aggressive )
throws Exception {
tr . branch ( "refs/heads/master" ) . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" )
tr . branch ( "refs/heads/master" ) . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" )
. create ( ) ;
. create ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -110,8 +124,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 1 , stats . numberOfPackFiles ) ;
assertEquals ( 1 , stats . numberOfPackFiles ) ;
}
}
@Test
@Theory
public void testPackCommitsAndLooseOne ( ) throws Exception {
public void testPackCommitsAndLooseOne ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
RevCommit first = bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
RevCommit first = bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
@ -120,6 +134,7 @@ public class GcBasicPackingTest extends GcTestCase {
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -127,8 +142,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 2 , stats . numberOfPackFiles ) ;
assertEquals ( 2 , stats . numberOfPackFiles ) ;
}
}
@Test
@Theory
public void testNotPackTwice ( ) throws Exception {
public void testNotPackTwice ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
RevCommit first = bb . commit ( ) . message ( "M" ) . add ( "M" , "M" ) . create ( ) ;
RevCommit first = bb . commit ( ) . message ( "M" ) . add ( "M" , "M" ) . create ( ) ;
bb . commit ( ) . message ( "B" ) . add ( "B" , "Q" ) . create ( ) ;
bb . commit ( ) . message ( "B" ) . add ( "B" , "Q" ) . create ( ) ;
@ -146,6 +161,7 @@ public class GcBasicPackingTest extends GcTestCase {
gc . setExpireAgeMillis ( 0 ) ;
gc . setExpireAgeMillis ( 0 ) ;
fsTick ( ) ;
fsTick ( ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -159,4 +175,15 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 9 , pIt . next ( ) . getObjectCount ( ) ) ;
assertEquals ( 9 , pIt . next ( ) . getObjectCount ( ) ) ;
}
}
}
}
private void configureGc ( GC myGc , boolean aggressive ) {
PackConfig pconfig = new PackConfig ( repo ) ;
if ( aggressive ) {
pconfig . setDeltaSearchWindowSize ( 250 ) ;
pconfig . setMaxDeltaDepth ( 250 ) ;
pconfig . setReuseObjects ( false ) ;
} else
pconfig = new PackConfig ( repo ) ;
myGc . setPackConfig ( pconfig ) ;
}
}
}