View Javadoc
1   /*
2    * Copyright (C) 2009, Google Inc. 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  import static org.junit.Assert.fail;
15  
16  import org.eclipse.jgit.junit.RepositoryTestCase;
17  import org.eclipse.jgit.storage.file.WindowCacheConfig;
18  import org.junit.Test;
19  
20  public class WindowCacheReconfigureTest extends RepositoryTestCase {
21  	@Test
22  	public void testConfigureCache_PackedGitLimit_0() {
23  		try {
24  			final WindowCacheConfig cfg = new WindowCacheConfig();
25  			cfg.setPackedGitLimit(0);
26  			cfg.install();
27  			fail("incorrectly permitted PackedGitLimit = 0");
28  		} catch (IllegalArgumentException e) {
29  			//
30  		}
31  	}
32  
33  	@Test
34  	public void testConfigureCache_PackedGitWindowSize_0() {
35  		try {
36  			final WindowCacheConfig cfg = new WindowCacheConfig();
37  			cfg.setPackedGitWindowSize(0);
38  			cfg.install();
39  			fail("incorrectly permitted PackedGitWindowSize = 0");
40  		} catch (IllegalArgumentException e) {
41  			assertEquals("Invalid window size", e.getMessage());
42  		}
43  	}
44  
45  	@Test
46  	public void testConfigureCache_PackedGitWindowSize_512() {
47  		try {
48  			final WindowCacheConfig cfg = new WindowCacheConfig();
49  			cfg.setPackedGitWindowSize(512);
50  			cfg.install();
51  			fail("incorrectly permitted PackedGitWindowSize = 512");
52  		} catch (IllegalArgumentException e) {
53  			assertEquals("Invalid window size", e.getMessage());
54  		}
55  	}
56  
57  	@Test
58  	public void testConfigureCache_PackedGitWindowSize_4097() {
59  		try {
60  			final WindowCacheConfig cfg = new WindowCacheConfig();
61  			cfg.setPackedGitWindowSize(4097);
62  			cfg.install();
63  			fail("incorrectly permitted PackedGitWindowSize = 4097");
64  		} catch (IllegalArgumentException e) {
65  			assertEquals("Window size must be power of 2", e.getMessage());
66  		}
67  	}
68  
69  	@Test
70  	public void testConfigureCache_PackedGitOpenFiles_0() {
71  		try {
72  			final WindowCacheConfig cfg = new WindowCacheConfig();
73  			cfg.setPackedGitOpenFiles(0);
74  			cfg.install();
75  			fail("incorrectly permitted PackedGitOpenFiles = 0");
76  		} catch (IllegalArgumentException e) {
77  			assertEquals("Open files must be >= 1", e.getMessage());
78  		}
79  	}
80  
81  	@Test
82  	public void testConfigureCache_PackedGitWindowSizeAbovePackedGitLimit() {
83  		try {
84  			final WindowCacheConfig cfg = new WindowCacheConfig();
85  			cfg.setPackedGitLimit(1024);
86  			cfg.setPackedGitWindowSize(8192);
87  			cfg.install();
88  			fail("incorrectly permitted PackedGitWindowSize > PackedGitLimit");
89  		} catch (IllegalArgumentException e) {
90  			assertEquals("Window size must be < limit", e.getMessage());
91  		}
92  	}
93  
94  	@Test
95  	public void testConfigureCache_Limits1() {
96  		// This test is just to force coverage over some lower bounds for
97  		// the table. We don't want the table to wind up with too small
98  		// of a size. This is highly dependent upon the table allocation
99  		// algorithm actually implemented in WindowCache.
100 		//
101 		final WindowCacheConfig cfg = new WindowCacheConfig();
102 		cfg.setPackedGitLimit(6 * 4096 / 5);
103 		cfg.setPackedGitWindowSize(4096);
104 		cfg.install();
105 	}
106 }