@ -51,21 +51,32 @@ import java.util.Iterator;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
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 {
@Test
public void repackEmptyRepo_noPackCreated ( ) throws IOException {
@DataPoints
public static boolean [ ] aggressiveValues = { true , false } ;
@Theory
public void repackEmptyRepo_noPackCreated ( boolean aggressive )
throws IOException {
configureGc ( gc , aggressive ) ;
gc . repack ( ) ;
assertEquals ( 0 , repo . getObjectDatabase ( ) . getPacks ( ) . size ( ) ) ;
}
@Test
public void testPackRepoWithNoRefs ( ) throws Exception {
@Theory
public void testPackRepoWithNoRefs ( boolean aggressive ) throws Exception {
tr . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
@ -73,8 +84,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 0 , stats . numberOfPackFiles ) ;
}
@Test
public void testPack2Commits ( ) throws Exception {
@Theory
public void testPack2Commits ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
@ -82,6 +93,7 @@ public class GcBasicPackingTest extends GcTestCase {
stats = gc . getStatistics ( ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -89,13 +101,15 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 1 , stats . numberOfPackFiles ) ;
}
@Test
public void testPackAllObjectsInOnePack ( ) throws Exception {
@Theory
public void testPackAllObjectsInOnePack ( boolean aggressive )
throws Exception {
tr . branch ( "refs/heads/master" ) . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" )
. create ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 4 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -110,8 +124,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 1 , stats . numberOfPackFiles ) ;
}
@Test
public void testPackCommitsAndLooseOne ( ) throws Exception {
@Theory
public void testPackCommitsAndLooseOne ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
RevCommit first = bb . commit ( ) . add ( "A" , "A" ) . add ( "B" , "B" ) . create ( ) ;
bb . commit ( ) . add ( "A" , "A2" ) . add ( "B" , "B2" ) . create ( ) ;
@ -120,6 +134,7 @@ public class GcBasicPackingTest extends GcTestCase {
stats = gc . getStatistics ( ) ;
assertEquals ( 8 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfPackedObjects ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -127,8 +142,8 @@ public class GcBasicPackingTest extends GcTestCase {
assertEquals ( 2 , stats . numberOfPackFiles ) ;
}
@Test
public void testNotPackTwice ( ) throws Exception {
@Theory
public void testNotPackTwice ( boolean aggressive ) throws Exception {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
RevCommit first = bb . commit ( ) . message ( "M" ) . add ( "M" , "M" ) . create ( ) ;
bb . commit ( ) . message ( "B" ) . add ( "B" , "Q" ) . create ( ) ;
@ -146,6 +161,7 @@ public class GcBasicPackingTest extends GcTestCase {
gc . setExpireAgeMillis ( 0 ) ;
fsTick ( ) ;
configureGc ( gc , aggressive ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
@ -159,4 +175,15 @@ public class GcBasicPackingTest extends GcTestCase {
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 ) ;
}
}