aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheConfigTest.java
blob: d5b8d559fb675f25227a0f9d19fa0d7e47dc2a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (C) 2016 Ericsson and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.lib;

import static org.eclipse.jgit.lib.RepositoryCacheConfig.AUTO_CLEANUP_DELAY;
import static org.eclipse.jgit.lib.RepositoryCacheConfig.NO_CLEANUP;
import static org.junit.Assert.assertEquals;

import java.util.concurrent.TimeUnit;

import org.eclipse.jgit.errors.ConfigInvalidException;
import org.junit.Before;
import org.junit.Test;

public class RepositoryCacheConfigTest {

	private RepositoryCacheConfig config;

	@Before
	public void setUp() {
		config = new RepositoryCacheConfig();
	}

	@Test
	public void testDefaultValues() {
		assertEquals(TimeUnit.HOURS.toMillis(1), config.getExpireAfter());
		assertEquals(config.getExpireAfter() / 10, config.getCleanupDelay());
	}

	@Test
	public void testCleanupDelay() {
		config.setCleanupDelay(TimeUnit.HOURS.toMillis(1));
		assertEquals(TimeUnit.HOURS.toMillis(1), config.getCleanupDelay());
	}

	@Test
	public void testAutoCleanupDelay() {
		config.setExpireAfter(TimeUnit.MINUTES.toMillis(20));
		config.setCleanupDelay(AUTO_CLEANUP_DELAY);
		assertEquals(TimeUnit.MINUTES.toMillis(20), config.getExpireAfter());
		assertEquals(config.getExpireAfter() / 10, config.getCleanupDelay());
	}

	@Test
	public void testAutoCleanupDelayShouldBeMax10minutes() {
		config.setExpireAfter(TimeUnit.HOURS.toMillis(10));
		assertEquals(TimeUnit.HOURS.toMillis(10), config.getExpireAfter());
		assertEquals(TimeUnit.MINUTES.toMillis(10), config.getCleanupDelay());
	}

	@Test
	public void testDisabledCleanupDelay() {
		config.setCleanupDelay(NO_CLEANUP);
		assertEquals(NO_CLEANUP, config.getCleanupDelay());
	}

	@Test
	public void testFromConfig() throws ConfigInvalidException {
		Config otherConfig = new Config();
		otherConfig.fromText("[core]\nrepositoryCacheExpireAfter=1000\n"
				+ "repositoryCacheCleanupDelay=500");
		config.fromConfig(otherConfig);
		assertEquals(1000, config.getExpireAfter());
		assertEquals(500, config.getCleanupDelay());
	}
}