source: josm/trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java@ 10654

Last change on this file since 10654 was 10654, checked in by Don-vip, 9 years ago

see #13128 - checkstyle

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.cache;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.File;
7import java.io.FileOutputStream;
8import java.io.IOException;
9import java.util.logging.Logger;
10
11import org.apache.commons.jcs.access.CacheAccess;
12import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheAttributes;
13import org.junit.BeforeClass;
14import org.junit.Test;
15import org.openstreetmap.josm.JOSMFixture;
16
17/**
18 * Unit tests for class {@link JCSCacheManager}.
19 */
20public class JCSCacheManagerTest {
21
22 /**
23 * Setup test.
24 */
25 @BeforeClass
26 public static void setUp() {
27 JOSMFixture.createUnitTestFixture().init();
28 }
29
30 /**
31 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12054">Bug #12054</a>.
32 * @throws IOException if any I/O error occurs
33 */
34 @Test
35 public void testLoggingAdaptor12054() throws IOException {
36 JCSCacheManager.getCache("foobar", 1, 0, "foobar"); // cause logging adaptor to be initialized
37 Logger.getLogger("org.apache.commons.jcs").warning("{switch:0}");
38 }
39
40 @Test
41 public void testUseBigDiskFile() throws IOException {
42 if (JCSCacheManager.USE_BLOCK_CACHE.get()) {
43 // test only when using block cache
44 File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data");
45 if (!cacheFile.exists()) {
46 cacheFile.createNewFile();
47 }
48 try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false)) {
49 fileOutputStream.getChannel().truncate(0);
50 fileOutputStream.write(new byte[1024*1024*10]); // create 10MB empty file
51 }
52
53 CacheAccess<Object, Object> cache = JCSCacheManager.getCache("testUseBigDiskFile", 1, 100, "foobar");
54 assertEquals("BlockDiskCache use file size to calculate its size", 10*1024,
55 ((BlockDiskCacheAttributes) cache.getCacheControl().getAuxCaches()[0].getAuxiliaryCacheAttributes()).getMaxKeySize());
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.