1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Map;
20 import javax.util.jcache.Cache;
21 import javax.util.jcache.CacheAccessFactory;
22 import javax.util.jcache.CacheAttributes;
23 import junit.framework.TestCase;
24
25 public class Bug974609_2 extends TestCase {
26 /***
27 * Tests the diskSize. Sets the maxObjects to 1, inserts 3 elements,
28 * where all elements are one Mb in size. The first goes to memory,
29 * the second should be spooled to disk, while the third should not fit
30 * anywhere, and an {@link javax.util.jcache.CacheFullException} should be thrown.
31 * The diskCaching system has the ability to read the size of the objects,
32 * so there is no need to specify the exact size of each object.
33 * Since the diskCache has some sizeoverhead, each object is slightly smaller than 1Mb
34 * to avoid that the cache stops before at least one object is added..
35 * @throws Exception if any exceptions occur.
36 */
37 final public void testSetDiskSize() throws Exception {
38 CacheAttributes ca = CacheAttributes.getDefaultCacheAttributes();
39 ca.setDiskPath(System.getProperty("java.io.tmpdir"));
40 ca.setDiskCacheSize(1);
41 ca.setMaxObjects(1);
42 ca.setLocal();
43 CacheAccessFactory factory = CacheAccessFactory.getInstance();
44 Cache cache = factory.getCache();
45 cache.close();
46 cache.init(ca);
47 Map map = factory.getMapAccess();
48 map.put("one", new byte[1024*1024]);
49 map.put("two", new byte[1024*900]);
50 try {
51 map.put("three", new byte[1024*900]);
52 fail("Should throw CacheException, but did not.");
53 }catch(IllegalArgumentException e) {
54
55 }
56 }
57 }