1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.cache;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.FileOutputStream;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.util.logging.Logger;
|
---|
10 |
|
---|
11 | import org.apache.commons.jcs.access.CacheAccess;
|
---|
12 | import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheAttributes;
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.JOSMFixture;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests for class {@link JCSCacheManager}.
|
---|
19 | */
|
---|
20 | public 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 | }
|
---|