View Javadoc
1   /*
2    * Copyright (C) 2012, Christian Halstrick <christian.halstrick@sap.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.internal.storage.file;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
16  import org.junit.Test;
17  
18  public class GcDirCacheSavesObjectsTest extends GcTestCase {
19  	@Test
20  	public void testDirCacheSavesObjects() throws Exception {
21  		BranchBuilder bb = tr.branch("refs/heads/master");
22  		bb.commit().add("A", "A").add("B", "B").create();
23  		bb.commit().add("A", "A2").add("B", "B2").create();
24  		bb.commit().add("A", "A3"); // this new content in index should survive
25  		stats = gc.getStatistics();
26  		assertEquals(9, stats.numberOfLooseObjects);
27  		assertEquals(0, stats.numberOfPackedObjects);
28  		gc.gc().get();
29  		stats = gc.getStatistics();
30  		assertEquals(1, stats.numberOfLooseObjects);
31  		assertEquals(8, stats.numberOfPackedObjects);
32  		assertEquals(1, stats.numberOfPackFiles);
33  	}
34  
35  	@Test
36  	public void testDirCacheSavesObjectsWithPruneNow() throws Exception {
37  		BranchBuilder bb = tr.branch("refs/heads/master");
38  		bb.commit().add("A", "A").add("B", "B").create();
39  		bb.commit().add("A", "A2").add("B", "B2").create();
40  		bb.commit().add("A", "A3"); // this new content in index should survive
41  		stats = gc.getStatistics();
42  		assertEquals(9, stats.numberOfLooseObjects);
43  		assertEquals(0, stats.numberOfPackedObjects);
44  		gc.setExpireAgeMillis(0);
45  		fsTick();
46  		gc.gc().get();
47  		stats = gc.getStatistics();
48  		assertEquals(0, stats.numberOfLooseObjects);
49  		assertEquals(8, stats.numberOfPackedObjects);
50  		assertEquals(1, stats.numberOfPackFiles);
51  	}
52  }