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 * Test to reproduce bug 974609.
26 * @author Frank Karlstrøm
27 *
28 */
29 public class Bug974609_1 extends TestCase {
30 /***
31 * Tests the maxObjects. Sets the maximum number of objects to 5,
32 * then tries to insert six.
33 * @throws Exception if any faults occurs.
34 */
35 final public void testSetMaxObjects() throws Exception {
36 CacheAttributes ca = CacheAttributes.getDefaultCacheAttributes();
37 ca.setMaxObjects(5);
38 ca.setLocal();
39 CacheAccessFactory factory = CacheAccessFactory.getInstance();
40 Cache cache = factory.getCache();
41 cache.close();
42 cache.init(ca);
43 Map map = factory.getMapAccess();
44 int max=5;
45 for(int i=0; i<max; i++) {
46 map.put(""+i, new Object());
47 }
48
49 try {
50 map.put("oi", new Object());
51 fail("MaxObjects was "+max+" but we managed to put "+(max+1)+".");
52 }catch(IllegalArgumentException e) {
53
54 }
55 }
56
57 }