1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.lib;
12
13 import static org.eclipse.jgit.lib.RepositoryCacheConfig.AUTO_CLEANUP_DELAY;
14 import static org.eclipse.jgit.lib.RepositoryCacheConfig.NO_CLEANUP;
15 import static org.junit.Assert.assertEquals;
16
17 import java.util.concurrent.TimeUnit;
18
19 import org.eclipse.jgit.errors.ConfigInvalidException;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 public class RepositoryCacheConfigTest {
24
25 private RepositoryCacheConfig config;
26
27 @Before
28 public void setUp() {
29 config = new RepositoryCacheConfig();
30 }
31
32 @Test
33 public void testDefaultValues() {
34 assertEquals(TimeUnit.HOURS.toMillis(1), config.getExpireAfter());
35 assertEquals(config.getExpireAfter() / 10, config.getCleanupDelay());
36 }
37
38 @Test
39 public void testCleanupDelay() {
40 config.setCleanupDelay(TimeUnit.HOURS.toMillis(1));
41 assertEquals(TimeUnit.HOURS.toMillis(1), config.getCleanupDelay());
42 }
43
44 @Test
45 public void testAutoCleanupDelay() {
46 config.setExpireAfter(TimeUnit.MINUTES.toMillis(20));
47 config.setCleanupDelay(AUTO_CLEANUP_DELAY);
48 assertEquals(TimeUnit.MINUTES.toMillis(20), config.getExpireAfter());
49 assertEquals(config.getExpireAfter() / 10, config.getCleanupDelay());
50 }
51
52 @Test
53 public void testAutoCleanupDelayShouldBeMax10minutes() {
54 config.setExpireAfter(TimeUnit.HOURS.toMillis(10));
55 assertEquals(TimeUnit.HOURS.toMillis(10), config.getExpireAfter());
56 assertEquals(TimeUnit.MINUTES.toMillis(10), config.getCleanupDelay());
57 }
58
59 @Test
60 public void testDisabledCleanupDelay() {
61 config.setCleanupDelay(NO_CLEANUP);
62 assertEquals(NO_CLEANUP, config.getCleanupDelay());
63 }
64
65 @Test
66 public void testFromConfig() throws ConfigInvalidException {
67 Config otherConfig = new Config();
68 otherConfig.fromText("[core]\nrepositoryCacheExpireAfter=1000\n"
69 + "repositoryCacheCleanupDelay=500");
70 config.fromConfig(otherConfig);
71 assertEquals(1000, config.getExpireAfter());
72 assertEquals(500, config.getCleanupDelay());
73 }
74 }