2 * Copyright (C) 2009, Google Inc.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.lib
;
40 public class WindowCacheReconfigureTest
extends RepositoryTestCase
{
41 public void testConfigureCache_PackedGitLimit_0() {
43 final WindowCacheConfig cfg
= new WindowCacheConfig();
44 cfg
.setPackedGitLimit(0);
45 WindowCache
.reconfigure(cfg
);
46 fail("incorrectly permitted PackedGitLimit = 0");
47 } catch (IllegalArgumentException e
) {
52 public void testConfigureCache_PackedGitWindowSize_0() {
54 final WindowCacheConfig cfg
= new WindowCacheConfig();
55 cfg
.setPackedGitWindowSize(0);
56 WindowCache
.reconfigure(cfg
);
57 fail("incorrectly permitted PackedGitWindowSize = 0");
58 } catch (IllegalArgumentException e
) {
59 assertEquals("Invalid window size", e
.getMessage());
63 public void testConfigureCache_PackedGitWindowSize_512() {
65 final WindowCacheConfig cfg
= new WindowCacheConfig();
66 cfg
.setPackedGitWindowSize(512);
67 WindowCache
.reconfigure(cfg
);
68 fail("incorrectly permitted PackedGitWindowSize = 512");
69 } catch (IllegalArgumentException e
) {
70 assertEquals("Invalid window size", e
.getMessage());
74 public void testConfigureCache_PackedGitWindowSize_4097() {
76 final WindowCacheConfig cfg
= new WindowCacheConfig();
77 cfg
.setPackedGitWindowSize(4097);
78 WindowCache
.reconfigure(cfg
);
79 fail("incorrectly permitted PackedGitWindowSize = 4097");
80 } catch (IllegalArgumentException e
) {
81 assertEquals("Window size must be power of 2", e
.getMessage());
85 public void testConfigureCache_PackedGitOpenFiles_0() {
87 final WindowCacheConfig cfg
= new WindowCacheConfig();
88 cfg
.setPackedGitOpenFiles(0);
89 WindowCache
.reconfigure(cfg
);
90 fail("incorrectly permitted PackedGitOpenFiles = 0");
91 } catch (IllegalArgumentException e
) {
92 assertEquals("Open files must be >= 1", e
.getMessage());
96 public void testConfigureCache_PackedGitWindowSizeAbovePackedGitLimit() {
98 final WindowCacheConfig cfg
= new WindowCacheConfig();
99 cfg
.setPackedGitLimit(1024);
100 cfg
.setPackedGitWindowSize(8192);
101 WindowCache
.reconfigure(cfg
);
102 fail("incorrectly permitted PackedGitWindowSize > PackedGitLimit");
103 } catch (IllegalArgumentException e
) {
104 assertEquals("Window size must be < limit", e
.getMessage());
108 public void testConfigureCache_Limits1() {
109 // This test is just to force coverage over some lower bounds for
110 // the table. We don't want the table to wind up with too small
111 // of a size. This is highly dependent upon the table allocation
112 // algorithm actually implemented in WindowCache.
114 final WindowCacheConfig cfg
= new WindowCacheConfig();
115 cfg
.setPackedGitLimit(6 * 4096 / 5);
116 cfg
.setPackedGitWindowSize(4096);
117 WindowCache
.reconfigure(cfg
);