Changeset 10652 in josm for trunk/test


Ignore:
Timestamp:
2016-07-26T22:06:52+02:00 (8 years ago)
Author:
wiktorn
Message:

Fix not using the calculated disk cache size.

Add unit tests for #13128 - using existing file size if greater than desired cache size.

Closes #13128

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java

    r10559 r10652  
    22package org.openstreetmap.josm.data.cache;
    33
     4import static org.junit.Assert.assertEquals;
     5
     6import java.io.File;
     7import java.io.FileOutputStream;
    48import java.io.IOException;
    59import java.util.logging.Logger;
    610
     11import org.apache.commons.jcs.access.CacheAccess;
     12import org.apache.commons.jcs.auxiliary.disk.block.BlockDiskCacheAttributes;
    713import org.junit.BeforeClass;
    814import org.junit.Test;
     
    3137        Logger.getLogger("org.apache.commons.jcs").warning("{switch:0}");
    3238    }
     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
    3359}
Note: See TracChangeset for help on using the changeset viewer.