You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowCacheReconfigureTest.java 3.1KB

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