1   /**
2    *  Copyright 2003-2007 Greg Luck
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.jcache;
18  
19  import edu.emory.mathcs.backport.java.util.concurrent.ExecutionException;
20  import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
21  import edu.emory.mathcs.backport.java.util.concurrent.Future;
22  import net.sf.ehcache.AbstractCacheTest;
23  import net.sf.ehcache.Ehcache;
24  import net.sf.ehcache.StopWatch;
25  import net.sf.ehcache.ThreadKiller;
26  import net.sf.jsr107cache.Cache;
27  import net.sf.jsr107cache.CacheEntry;
28  import net.sf.jsr107cache.CacheException;
29  import net.sf.jsr107cache.CacheManager;
30  import net.sf.jsr107cache.CacheStatistics;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  import java.io.Serializable;
35  import java.util.ArrayList;
36  import java.util.HashMap;
37  import java.util.List;
38  import java.util.Map;
39  import java.util.Random;
40  import java.util.Set;
41  import java.util.Date;
42  import java.util.Collection;
43  
44  /**
45   * Tests for a Cache
46   * @author Greg Luck
47   * @version $Id:JCacheTest.java 318 2007-01-25 01:48:35Z gregluck $
48   */
49  public class JCacheTest extends AbstractCacheTest {
50      private static final Log LOG = LogFactory.getLog(JCacheTest.class.getName());
51  
52      /**
53       * setup test
54       */
55      protected void setUp() throws Exception {
56          super.setUp();
57          System.gc();
58          Thread.sleep(100);
59          System.gc();
60      }
61  
62  
63      /**
64       * teardown
65       * limits to what we can do here under jsr107
66       */
67      protected void tearDown() throws Exception {
68          getTest1Cache().clear();
69          getTest2Cache().clear();
70          getTest4Cache().clear();
71          manager.getCache("sampleCache1").removeAll();
72      }
73  
74      /**
75       * Gets the sample cache 1
76       * <cache name="sampleCache1"
77       * maxElementsInMemory="10000"
78       * maxElementsOnDisk="1000"
79       * eternal="false"
80       * timeToIdleSeconds="360"
81       * timeToLiveSeconds="1000"
82       * overflowToDisk="true"
83       * memoryStoreEvictionPolicy="LRU">
84       * <cacheEventListenerFactory class="net.sf.ehcache.event.NullCacheEventListenerFactory"/>
85       * </cache>
86       */
87      protected Cache getTest1Cache() throws CacheException {
88          Cache cache = CacheManager.getInstance().getCache("test1");
89          if (cache == null) {
90              //sampleCache1
91              Map env = new HashMap();
92              env.put("name", "test1");
93              env.put("maxElementsInMemory", "10000");
94              env.put("maxElementsOnDisk", "1000");
95              env.put("memoryStoreEvictionPolicy", "LRU");
96              env.put("overflowToDisk", "true");
97              env.put("eternal", "false");
98              env.put("timeToLiveSeconds", "1000");
99              env.put("timeToIdleSeconds", "1000");
100             env.put("diskPersistent", "false");
101             env.put("diskExpiryThreadIntervalSeconds", "120");
102             env.put("cacheLoaderFactoryClassName", "net.sf.ehcache.jcache.CountingCacheLoaderFactory");
103             cache = CacheManager.getInstance().getCacheFactory().createCache(env);
104             CacheManager.getInstance().registerCache("test1", cache);
105         }
106         return CacheManager.getInstance().getCache("test1");
107     }
108 
109     private Cache getTest2Cache() throws CacheException {
110         Cache cache = CacheManager.getInstance().getCache("test2");
111         if (cache == null) {
112             Map env = new HashMap();
113             env.put("name", "test2");
114             env.put("maxElementsInMemory", "1");
115             env.put("overflowToDisk", "true");
116             env.put("eternal", "false");
117             env.put("timeToLiveSeconds", "1");
118             env.put("timeToIdleSeconds", "0");
119             cache = CacheManager.getInstance().getCacheFactory().createCache(env);
120             CacheManager.getInstance().registerCache("test2", cache);
121         }
122         return CacheManager.getInstance().getCache("test2");
123     }
124 
125     private Cache getTest4Cache() throws CacheException {
126         Cache cache = CacheManager.getInstance().getCache("test4");
127         if (cache == null) {
128             Map env = new HashMap();
129             env.put("name", "test4");
130             env.put("maxElementsInMemory", "1000");
131             env.put("overflowToDisk", "true");
132             env.put("eternal", "true");
133             env.put("timeToLiveSeconds", "0");
134             env.put("timeToIdleSeconds", "0");
135             cache = CacheManager.getInstance().getCacheFactory().createCache(env);
136             CacheManager.getInstance().registerCache("test4", cache);
137         }
138         return CacheManager.getInstance().getCache("test4");
139     }
140 
141     /**
142      * Checks we cannot use a cache after shutdown
143      * test cannot be implemented due to lack of lifecycle support in jsr107
144      */
145 //    public void testUseCacheAfterManagerShutdown() throws CacheException {
146 
147     /**
148      * Checks we cannot use a cache outside the manager
149      * Is the jsr107 silent on whether you can do this?
150      */
151 //    public void testUseCacheOutsideManager() throws CacheException {
152 
153     /**
154      * Checks when and how we can set the cache name.
155      * This is not allowed in jsr107
156      */
157     //public void testSetCacheName() throws CacheException {
158 
159     /**
160      * Test using a cache which has been removed and replaced.
161      * Is the jsr107 silent on whether you can do this?
162      */
163 //    public void testStaleCacheReference() throws CacheException {
164 
165     /**
166      * Tests getting the cache name
167      * there is no getName method in jsr107
168      *
169      * @throws Exception
170      */
171 //    public void testCacheWithNoIdle() throws Exception {
172 
173     /**
174      * Test expiry based on time to live
175      * <cache name="sampleCacheNoIdle"
176      * maxElementsInMemory="1000"
177      * eternal="false"
178      * timeToLiveSeconds="5"
179      * overflowToDisk="false"
180      * />
181      */
182     public void testExpiryBasedOnTimeToLiveWhenNoIdle() throws Exception {
183         Cache cache = new JCache(manager.getCache("sampleCacheNoIdle"), null);
184         cache.put("key1", "value1");
185         cache.put("key2", "value1");
186         assertNotNull(cache.get("key1"));
187         assertNotNull(cache.get("key2"));
188 
189         //Test time to idle. Should not idle out because not specified
190         Thread.sleep(2000);
191         assertNotNull(cache.get("key1"));
192         assertNotNull(cache.get("key2"));
193 
194         //Test time to live.
195         Thread.sleep(5020);
196         assertNull(cache.get("key1"));
197         assertNull(cache.get("key2"));
198     }
199 
200     /**
201      * Test expiry based on time to live where an Eelment override is set on TTL
202      * jsr107 does not support TTL overrides per put.
203      */
204 //    public void testExpiryBasedOnTimeToLiveWhenNoIdleElementOverride() throws Exception {
205 
206     /**
207      * Test overflow to disk = false
208      */
209     public void testNoOverflowToDisk() throws Exception {
210         Ehcache ehcache = new net.sf.ehcache.Cache("testNoOverflowToDisk", 1, false, true, 500, 200);
211         manager.addCache(ehcache);
212         Cache cache = new JCache(ehcache, null);
213         cache.put("key1", "value1");
214         cache.put("key2", "value1");
215         assertNull(cache.get("key1"));
216         assertNotNull(cache.get("key2"));
217     }
218 
219 
220     /**
221      * Test isEmpty
222      */
223     public void testIsEmpty() throws Exception {
224         Ehcache ehcache = new net.sf.ehcache.Cache("testIsEmpty", 1, true, true, 500, 200);
225         manager.addCache(ehcache);
226         Cache cache = new JCache(ehcache, null);
227         assertTrue(cache.isEmpty());
228 
229         cache.put("key1", "value1");
230         assertFalse(cache.isEmpty());
231         cache.put("key2", "value1");
232         assertFalse(cache.isEmpty());
233 
234 
235         assertNotNull(cache.get("key1"));
236         assertNotNull(cache.get("key2"));
237     }
238 
239     /**
240      * Test isEmpty
241      */
242     public void testEvict() throws Exception {
243         Ehcache ehcache = new net.sf.ehcache.Cache("testEvict", 1, true, false, 1, 200);
244         manager.addCache(ehcache);
245         Cache cache = new JCache(ehcache, null);
246         assertTrue(cache.isEmpty());
247 
248         cache.put("key1", "value1");
249         cache.put("key2", "value1");
250         //no invalid
251         cache.evict();
252         assertFalse(cache.isEmpty());
253 
254         Thread.sleep(1020);
255         cache.evict();
256         assertNull(cache.get("key1"));
257         assertNull(cache.get("key2"));
258 
259         cache.put("key1", "value1");
260         cache.put("key2", "value1");
261         Thread.sleep(1020);
262         assertNull(cache.get("key1"));
263         assertNull(cache.get("key2"));
264 
265     }
266 
267     /**
268      * Test containsKey
269      */
270     public void testContainsKey() throws Exception {
271         Ehcache ehcache = new net.sf.ehcache.Cache("testContainsKey", 1, true, true, 500, 200);
272         manager.addCache(ehcache);
273         Cache cache = new JCache(ehcache, null);
274         assertFalse(cache.containsKey("key1"));
275         assertFalse(cache.containsKey("key2"));
276 
277         cache.put("key1", "value1");
278         assertTrue(cache.containsKey("key1"));
279         assertFalse(cache.containsKey("key2"));
280 
281         cache.put("key2", "value1");
282         assertTrue(cache.containsKey("key1"));
283         assertTrue(cache.containsKey("key2"));
284 
285         assertNotNull(cache.get("key1"));
286         assertNotNull(cache.get("key2"));
287     }
288 
289 
290     /**
291      * Test containsValue
292      */
293     public void testContainsValue() throws Exception {
294         Ehcache ehcache = new net.sf.ehcache.Cache("testContainsValue", 2, true, true, 500, 200);
295         manager.addCache(ehcache);
296         Cache cache = new JCache(ehcache, null);
297         assertFalse(cache.containsValue("value1"));
298         assertFalse(cache.containsValue(null));
299 
300         cache.put("key1", null);
301         assertFalse(cache.containsValue("value1"));
302         assertTrue(cache.containsValue(null));
303 
304         cache.put("key2", "value1");
305         assertTrue(cache.containsValue("value1"));
306         assertTrue(cache.containsValue(null));
307 
308         assertNull(cache.get("key1"));
309         assertNotNull(cache.get("key2"));
310     }
311 
312 
313     /**
314      * Test the get method.
315      */
316     public void testGet() throws Exception {
317         Ehcache ehcache = new net.sf.ehcache.Cache("testGet", 10, true, true, 500, 200);
318         manager.addCache(ehcache);
319         JCache jcache = new JCache(manager.getCache("sampleCache1"), null);
320 
321         //existing entry with null value, no loader
322         jcache.put("key", null);
323         Object value = jcache.get("key");
324         assertNull(value);
325 
326         //existing entry with null value, with loader
327         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
328         jcache.setCacheLoader(countingCacheLoader);
329         value = jcache.get("key");
330         assertNull(value);
331 
332         //no entry with matching key in cache, no loader
333         jcache.remove("key");
334         jcache.setCacheLoader(null);
335         jcache.put("key", null);
336         value = jcache.get("key");
337         assertNull(value);
338 
339         //no entry with matching key in cache, with loader
340         jcache.remove("key");
341         jcache.setCacheLoader(countingCacheLoader);
342         value = jcache.get("key");
343         assertEquals(new Integer(0), value);
344 
345         //cache hit
346         jcache.put("key2", "value");
347         value = jcache.get("key2");
348         assertEquals("value", value);
349 
350     }
351 
352 
353     /**
354      * Test the get values method.
355      */
356     public void testGetValues() throws Exception {
357         Ehcache ehcache = new net.sf.ehcache.Cache("testGetValue", 2, true, true, 500, 200);
358         manager.addCache(ehcache);
359                                                                                       
360         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
361         JCache jcache = new JCache(manager.getCache("sampleCache1"), countingCacheLoader);
362 
363         /** A class which is not Serializable */
364         class NonSerializable { }
365 
366         List keys = new ArrayList();
367         for (int i = 0; i < 1000; i++) {
368             keys.add(new Integer(i));
369         }
370         jcache.loadAll(keys);
371         jcache.put(new Integer(1), new Date());
372         jcache.put(new Integer(2), new NonSerializable());
373         Thread.sleep((long) (3000 * StopWatch.getSpeedAdjustmentFactor()));
374         assertEquals(1000, jcache.size());
375 
376         Collection values = jcache.values();
377         assertEquals(1000, values.size());
378 
379     }
380 
381     /**
382      * Tests putAll
383      */
384     public void testPutAll() {
385         Ehcache ehcache = new net.sf.ehcache.Cache("testPutAll", 2, true, true, 500, 200);
386         manager.addCache(ehcache);
387         Cache cache = new JCache(ehcache, null);
388         assertTrue(cache.isEmpty());
389 
390         cache.putAll(null);
391         assertTrue(cache.isEmpty());
392 
393         cache.putAll(new HashMap());
394         assertTrue(cache.isEmpty());
395 
396         Map map = new HashMap();
397         for (int i = 0; i < 10; i++) {
398             map.put(i + "", new Date());
399         }
400 
401         cache.putAll(map);
402         assertEquals(10, cache.size());
403     }
404 
405     /**
406      * Tests clear()
407      */
408     public void testClear() {
409         Ehcache ehcache = new net.sf.ehcache.Cache("testClear", 2, true, true, 500, 200);
410         manager.addCache(ehcache);
411         Cache cache = new JCache(ehcache, null);
412 
413         assertTrue(cache.isEmpty());
414         cache.clear();
415         assertTrue(cache.isEmpty());
416 
417         cache.put("1", new Date());
418         cache.clear();
419         assertTrue(cache.isEmpty());
420     }
421 
422 
423     /**
424      * Test the keyset method
425      */
426     public void testKeySet() {
427         Ehcache ehcache = new net.sf.ehcache.Cache("testKeySet", 2, true, true, 500, 200);
428         manager.addCache(ehcache);
429         Cache cache = new JCache(ehcache, null);
430 
431         for (int i = 0; i < 10; i++) {
432             cache.put(i + "", new Date());
433         }
434         //duplicate
435         cache.put(0 + "", new Date());
436         Set set = cache.keySet();
437         assertEquals(10, set.size());
438     }
439 
440 
441     /**
442      * Performance tests for a range of Memory Store - Disk Store combinations.
443      * <p/>
444      * This demonstrates that a memory only store is approximately an order of magnitude
445      * faster than a disk only store.
446      * <p/>
447      * It also shows that double the performance of a Disk Only store can be obtained
448      * with a maximum memory size of only 1. Accordingly a Cache created without a
449      * maximum memory size of less than 1 will issue a warning.
450      * <p/>
451      * Threading changes were made in v1.41 of DiskStore. The before and after numbers are shown.
452      */
453     public void testProportionMemoryAndDiskPerformance() throws Exception {
454         StopWatch stopWatch = new StopWatch();
455         long time = 0;
456 
457         //Memory only Typical 192ms
458         Ehcache ehcache = new net.sf.ehcache.Cache("testMemoryOnly", 5000, false, false, 5, 2);
459         manager.addCache(ehcache);
460         Cache memoryOnlyCache = new JCache(ehcache, null);
461 
462         time = stopWatch.getElapsedTime();
463         for (int i = 0; i < 5000; i++) {
464             Integer key = new Integer(i);
465             memoryOnlyCache.put(new Integer(i), "value");
466             memoryOnlyCache.get(key);
467         }
468         time = stopWatch.getElapsedTime();
469         LOG.info("Time for MemoryStore: " + time);
470         assertTrue("Time to put and get 5000 entries into MemoryStore", time < 300);
471 
472         //Set size so that all elements overflow to disk.
473         // 1245 ms v1.38 DiskStore
474         // 273 ms v1.42 DiskStore
475         Ehcache diskOnlyEhcache = new net.sf.ehcache.Cache("testDiskOnly", 0, true, false, 5, 2);
476         manager.addCache(diskOnlyEhcache);
477         Cache diskOnlyCache = new JCache(ehcache, null);
478         time = stopWatch.getElapsedTime();
479         for (int i = 0; i < 5000; i++) {
480             Integer key = new Integer(i);
481             diskOnlyCache.put(key, "value");
482             diskOnlyCache.get(key);
483         }
484         time = stopWatch.getElapsedTime();
485         LOG.info("Time for DiskStore: " + time);
486         assertTrue("Time to put and get 5000 entries into DiskStore was less than 2 sec", time < 2000);
487 
488         // 1 Memory, 999 Disk
489         // 591 ms v1.38 DiskStore
490         // 56 ms v1.42 DiskStore
491         Ehcache m1d999Ehcache = new net.sf.ehcache.Cache("m1d999Cache", 1, true, false, 5, 2);
492         manager.addCache(m1d999Ehcache);
493         Cache m1d999Cache = new JCache(m1d999Ehcache, null);
494         time = stopWatch.getElapsedTime();
495         for (int i = 0; i < 5000; i++) {
496             Integer key = new Integer(i);
497             m1d999Cache.put(key, "value");
498             m1d999Cache.get(key);
499         }
500         time = stopWatch.getElapsedTime();
501         LOG.info("Time for m1d999Cache: " + time);
502         assertTrue("Time to put and get 5000 entries into m1d999Cache", time < 2000);
503 
504         // 500 Memory, 500 Disk
505         // 669 ms v1.38 DiskStore
506         // 47 ms v1.42 DiskStore
507         Ehcache m500d500Ehcache = new net.sf.ehcache.Cache("m500d500Cache", 500, true, false, 5, 2);
508         manager.addCache(m500d500Ehcache);
509         Cache m500d500Cache = new JCache(m1d999Ehcache, null);
510 
511         time = stopWatch.getElapsedTime();
512         for (int i = 0; i < 5000; i++) {
513             Integer key = new Integer(i);
514             m500d500Cache.put(key, "value");
515             m500d500Cache.get(key);
516         }
517         time = stopWatch.getElapsedTime();
518         LOG.info("Time for m500d500Cache: " + time);
519         assertTrue("Time to put and get 5000 entries into m500d500Cache", time < 2000);
520 
521     }
522 
523     /**
524      * Test Caches with persistent stores dispose properly. Tests:
525      * <ol>
526      * <li>No exceptions are thrown on dispose
527      * <li>You cannot re add a cache after it has been disposed and removed
528      * <li>You can create a new cache with the same name
529      * </ol>
530      * jsr107 does not support lifecycles.
531      */
532 //    public void testCreateAddDisposeAdd() throws CacheException {
533 
534     /**
535      * Test expiry based on time to live
536      */
537     public void testExpiryBasedOnTimeToLive() throws Exception {
538         //Set size so the second element overflows to disk.
539         Ehcache ehcache = new net.sf.ehcache.Cache("testExpiryBasedOnTimeToLive", 1, true, false, 3, 0);
540         manager.addCache(ehcache);
541         Cache cache = new JCache(ehcache, null);
542 
543         cache.put("key1", "value1");
544         cache.put("key2", "value1");
545 
546         //Test time to live
547         assertNotNull(cache.get("key1"));
548         assertNotNull(cache.get("key2"));
549         Thread.sleep(1020);
550         //Test time to live
551         assertNotNull(cache.get("key1"));
552         assertNotNull(cache.get("key2"));
553         Thread.sleep(1020);
554         //Test time to live
555         assertNotNull(cache.get("key1"));
556         assertNotNull(cache.get("key2"));
557         Thread.sleep(1020);
558         assertNull(cache.get("key1"));
559         assertNull(cache.get("key2"));
560     }
561 
562 
563     /**
564      * Test expiry based on time to live.
565      * This test uses peek, which behaves the same as get
566      */
567     public void testExpiryBasedOnTimeToLiveUsingPeek() throws Exception {
568         //Set size so the second element overflows to disk.
569         Ehcache ehcache = new net.sf.ehcache.Cache("testExpiryBasedOnTimeToLiveUsingPeek", 1, true, false, 3, 0);
570         manager.addCache(ehcache);
571         Cache cache = new JCache(ehcache, null);
572 
573         cache.put("key1", "value1");
574         cache.put("key2", "value1");
575 
576         //Test time to live
577         assertNotNull(cache.peek("key1"));
578         assertNotNull(cache.peek("key2"));
579         Thread.sleep(1020);
580         //Test time to live
581         assertNotNull(cache.peek("key1"));
582         assertNotNull(cache.peek("key2"));
583         Thread.sleep(1020);
584         //Test time to live
585         assertNotNull(cache.peek("key1"));
586         assertNotNull(cache.peek("key2"));
587         Thread.sleep(1020);
588         assertNull(cache.peek("key1"));
589         assertNull(cache.peek("key2"));
590     }
591 
592 //    /**
593 //     * Tests that a cache created from defaults will expire as per
594 //     * the default expiry policy.
595 //     * Caches cannot be created from default in jsr107
596 //     */
597 //    public void testExpiryBasedOnTimeToLiveForDefault() throws Exception {
598 
599     /**
600      * Test expiry based on time to live.
601      * <p/>
602      * Elements are put quietly back into the cache after being cloned.
603      * The elements should expire as if the putQuiet had not happened.
604      * jsr107
605      */
606 //    public void testExpiryBasedOnTimeToLiveAfterPutQuiet() throws Exception {
607 
608 
609     /**
610      * Test expiry based on time to live
611      */
612     public void testNoIdleOrExpiryBasedOnTimeToLiveForEternal() throws Exception {
613         //Set size so the second element overflows to disk.
614         Ehcache ehcache = new net.sf.ehcache.Cache("testNoIdleOrExpiryBasedOnTimeToLiveForEternal", 1, true, true, 5, 2);
615         manager.addCache(ehcache);
616         Cache cache = new JCache(ehcache, null);
617 
618         cache.put("key1", "value1");
619         cache.put("key2", "value1");
620 
621         //Test time to live
622         assertNotNull(cache.get("key1"));
623         assertNotNull(cache.get("key2"));
624 
625         //Check that we did not idle out
626         Thread.sleep(2020);
627         assertNotNull(cache.get("key1"));
628         assertNotNull(cache.get("key2"));
629 
630         //Check that we did not expire out
631         Thread.sleep(3020);
632         assertNotNull(cache.get("key1"));
633         assertNotNull(cache.get("key2"));
634     }
635 
636     /**
637      * Test expiry based on time to idle.
638      */
639     public void testExpiryBasedOnTimeToIdle() throws Exception {
640         //Set size so the second element overflows to disk.
641         Ehcache ehcache = new net.sf.ehcache.Cache("testExpiryBasedOnTimeToIdle", 1, true, false, 6, 2);
642         manager.addCache(ehcache);
643         Cache cache = new JCache(ehcache, null);
644 
645         cache.put("key1", "value1");
646         cache.put("key2", "value1");
647 
648         //Test time to idle
649         assertNotNull(cache.get("key1"));
650         assertNotNull(cache.get("key2"));
651         Thread.sleep(2020);
652         assertNull(cache.get("key1"));
653         assertNull(cache.get("key2"));
654 
655         //Test effect of get
656         cache.put("key1", "value1");
657         cache.put("key2", "value1");
658         Thread.sleep(1020);
659         assertNotNull(cache.get("key1"));
660         assertNotNull(cache.get("key2"));
661 
662         Thread.sleep(2020);
663         assertNull(cache.get("key1"));
664         assertNull(cache.get("key2"));
665     }
666 
667     /**
668      * Test expiry based on time to idle.
669      * jsr107 has no put quiet
670      */
671 //    public void testExpiryBasedOnTimeToIdleAfterPutQuiet() throws Exception {
672 
673     /**
674      * Test element statistics, including get and getQuiet
675      * eternal="false"
676      * timeToIdleSeconds="5"
677      * timeToLiveSeconds="10"
678      * overflowToDisk="true"
679      * <p/>
680      * jsr107 has no put quiet
681      */
682     public void testElementStatistics() throws Exception {
683         Ehcache ehcache = new net.sf.ehcache.Cache("testElementStatistics", 1, true, false, 5, 2);
684         manager.addCache(ehcache);
685         Cache cache = new JCache(ehcache, null);
686 
687         cache.put("key1", "value1");
688         cache.put("key2", "value1");
689 
690         CacheEntry cacheEntry = cache.getCacheEntry("key1");
691         assertEquals("Should be one", 1, cacheEntry.getHits());
692 
693         cacheEntry = cache.getCacheEntry("key1");
694         assertEquals("Should be two", 2, cacheEntry.getHits());
695     }
696 
697     /**
698      * Check getting a cache entry where it does not exist
699      */
700     public void testNullCacheEntry() {
701         Ehcache ehcache = new net.sf.ehcache.Cache("testNullCacheEntry", 1, true, false, 5, 2);
702         manager.addCache(ehcache);
703         Cache cache = new JCache(ehcache, null);
704 
705         cache.put("key1", "value1");
706 
707         CacheEntry cacheEntry = cache.getCacheEntry("key1");
708         assertNotNull(cacheEntry);
709         CacheEntry cacheEntry2 = cache.getCacheEntry("keyDoesNotExist");
710         assertNull(cacheEntry2);
711     }
712 
713     /**
714      * Test cache statistics, including get.
715      * Reconcile CacheEntry stats with cache stats and make sure they agree
716      */
717     public void testCacheStatistics() throws Exception {
718         Ehcache ehcache = new net.sf.ehcache.Cache("testCacheStatistics", 1, true, false, 5, 2);
719         manager.addCache(ehcache);
720         Cache cache = new JCache(ehcache, null);
721         cache.put("key1", "value1");
722         cache.put("key2", "value1");
723 
724         CacheEntry cacheEntry = cache.getCacheEntry("key1");
725         assertEquals("Should be one", 1, cacheEntry.getHits());
726         assertEquals("Should be one", 1, cache.getCacheStatistics().getCacheHits());
727 
728 
729         cacheEntry = cache.getCacheEntry("key1");
730         assertEquals("Should be one", 2, cacheEntry.getHits());
731         assertEquals("Should be one", 2, cache.getCacheStatistics().getCacheHits());
732 
733         cacheEntry = cache.getCacheEntry("key2");
734         assertEquals("Should be one", 1, cacheEntry.getHits());
735         assertEquals("Should be one", 3, cache.getCacheStatistics().getCacheHits());
736 
737         assertEquals("Should be 0", 0, cache.getCacheStatistics().getCacheMisses());
738         cache.get("doesnotexist");
739         assertEquals("Should be 1", 1, cache.getCacheStatistics().getCacheMisses());
740 
741 
742     }
743 
744     /**
745      * Checks that getQuiet works how we expect it to
746      * not supported in jsr107
747      */
748 //    public void testGetQuietAndPutQuiet() throws Exception {
749 
750     /**
751      * Test size with put and remove.
752      * <p/>
753      * It checks that size makes sense, and also that getKeys.size() matches getSize()
754      */
755     public void testSizeWithPutAndRemove() throws Exception {
756         //Set size so the second element overflows to disk.
757         Ehcache ehcache = new net.sf.ehcache.Cache("testSizeWithPutAndRemove", 1, true, true, 0, 0);
758         manager.addCache(ehcache);
759         Cache cache = new JCache(ehcache, null);
760 
761         cache.put("key1", "value1");
762         cache.put("key2", "value1");
763 
764         int sizeFromGetSize = cache.getCacheStatistics().getObjectCount();
765         int sizeFromKeys = cache.keySet().size();
766         assertEquals(sizeFromGetSize, sizeFromKeys);
767         assertEquals(2, cache.getCacheStatistics().getObjectCount());
768 
769         /** A class which is not Serializable */
770         class NonSerializable { }
771         
772         cache.put("key1", new NonSerializable());
773         cache.put("key1", "value1");
774 
775         //key1 should be in the Disk Store
776         assertEquals(cache.getCacheStatistics().getObjectCount(), cache.keySet().size());
777         assertEquals(2, cache.getCacheStatistics().getObjectCount());
778         //there were two of these, so size will now be one
779         cache.remove("key1");
780         assertEquals(cache.getCacheStatistics().getObjectCount(), cache.keySet().size());
781         assertEquals(1, cache.getCacheStatistics().getObjectCount());
782         cache.remove("key2");
783         assertEquals(cache.getCacheStatistics().getObjectCount(), cache.keySet().size());
784         assertEquals(0, cache.getCacheStatistics().getObjectCount());
785 
786         //try null values
787         cache.clear();
788         cache.put("nullValue1", null);
789         cache.put("nullValue2", null);
790         //Cannot overflow therefore just one
791         assertEquals(1, cache.getCacheStatistics().getObjectCount());
792         Object nullValue = cache.get("nullValue2");
793         assertNull(nullValue);
794 
795     }
796 
797     /**
798      * Test getKeys after expiry
799      * <p/>
800      * Makes sure that if an element is expired, its key should also be expired
801      */
802     public void testGetKeysAfterExpiry() throws Exception {
803         //Set size so the second element overflows to disk.
804         Cache cache = getTest2Cache();
805         String key1 = "key1";
806         cache.put(key1, "value1");
807         cache.put("key2", "value1");
808         //getSize uses getKeys().size(), so these should be the same
809         assertEquals(cache.getCacheStatistics().getObjectCount(), cache.keySet().size());
810         //getKeys does not do an expiry check, so the expired elements are counted
811         assertEquals(2, cache.getCacheStatistics().getObjectCount());
812         String keyFromDisk = (String) cache.getCacheEntry(key1).getKey();
813         assertTrue(key1.equals(keyFromDisk));
814         Thread.sleep(1020);
815         assertEquals(2, cache.keySet().size());
816         //getKeysWithExpiryCheck does check and gives the correct answer of 0
817         Ehcache ehcache = ((JCache) cache).getBackingCache();
818         ehcache.setStatisticsAccuracy(CacheStatistics.STATISTICS_ACCURACY_GUARANTEED);
819         assertEquals(0, cache.getCacheStatistics().getObjectCount());
820     }
821 
822     /**
823      * Test size after multiple calls, with put and remove
824      */
825     public void testSizeMultipleCallsWithPutAndRemove() throws Exception {
826         //Set size so the second element overflows to disk.
827         //Cache cache = new Cache("test3", 1, true, true, 0, 0);
828         Cache cache = getTest2Cache();
829         cache.put("key1", "value1");
830         cache.put("key2", "value1");
831 
832         //key1 should be in the Disk Store
833         assertEquals(2, cache.getCacheStatistics().getObjectCount());
834         assertEquals(2, cache.getCacheStatistics().getObjectCount());
835         assertEquals(2, cache.getCacheStatistics().getObjectCount());
836         assertEquals(2, cache.getCacheStatistics().getObjectCount());
837         assertEquals(2, cache.getCacheStatistics().getObjectCount());
838         cache.remove("key1");
839         assertEquals(1, cache.getCacheStatistics().getObjectCount());
840         assertEquals(1, cache.getCacheStatistics().getObjectCount());
841         assertEquals(1, cache.getCacheStatistics().getObjectCount());
842         assertEquals(1, cache.getCacheStatistics().getObjectCount());
843         assertEquals(1, cache.getCacheStatistics().getObjectCount());
844         cache.remove("key2");
845         assertEquals(0, cache.getCacheStatistics().getObjectCount());
846         assertEquals(0, cache.getCacheStatistics().getObjectCount());
847         assertEquals(0, cache.getCacheStatistics().getObjectCount());
848         assertEquals(0, cache.getCacheStatistics().getObjectCount());
849         assertEquals(0, cache.getCacheStatistics().getObjectCount());
850     }
851 
852     /**
853      * Checks the expense of checking for duplicates
854      * JSR107 has only one keyset command. It returns a Set rather than a list, so
855      * duplicates are automatically handled.
856      * <p/>
857      * 31ms for 2000 keys, half in memory and half on disk
858      * <p/>
859      */
860     public void testGetKeysPerformance() throws Exception {
861         Cache cache = getTest2Cache();
862 
863         for (int i = 0; i < 2000; i++) {
864             cache.put("key" + i, "value");
865         }
866         //Add some duplicates
867         cache.put("key0", "value");
868         cache.put("key1", "value");
869         cache.put("key2", "value");
870         cache.put("key3", "value");
871         cache.put("key4", "value");
872         //let the spool be written
873         Thread.sleep(1000);
874         StopWatch stopWatch = new StopWatch();
875         Set keys = cache.keySet();
876         assertTrue("Should be 2000 keys. ", keys.size() == 2000);
877         long getKeysTime = stopWatch.getElapsedTime();
878 
879         LOG.info("Time to get 2000 keys: With Duplicate Check: " + getKeysTime);
880         assertTrue("Getting keys took more than 200ms: " + getKeysTime, getKeysTime < 100);
881     }
882 
883     /**
884      * Checks the expense of checking in-memory size
885      * 3467890 bytes in 1601ms for JDK1.4.2
886      * N/A to jsr107
887      */
888 //    public void testCalculateInMemorySizePerformanceAndReasonableness() throws Exception {
889 
890 
891     /**
892      * Expire elements and verify size is correct.
893      */
894     public void testGetSizeAfterExpiry() throws Exception {
895         //Set size so the second element overflows to disk.
896         Cache cache = getTest2Cache();
897         cache.put("key1", "value1");
898         cache.put("key2", "value1");
899 
900         //Let the idle expire
901         Thread.sleep(1020);
902         assertEquals(null, cache.get("key1"));
903         assertEquals(null, cache.get("key2"));
904 
905         assertEquals(0, cache.getCacheStatistics().getObjectCount());
906     }
907 
908     /**
909      * Tests initialisation failures
910      * jsr107 has no lifecycle management
911      */
912 //    public void testInitialiseFailures() {
913 
914 
915     /**
916      * Tests putting nulls throws correct exception
917      *
918      * @throws Exception
919      */
920     public void testNullTreatment() throws Exception {
921         Ehcache ehcache = new net.sf.ehcache.Cache("testNullTreatment", 1, false, false, 5, 1);
922         manager.addCache(ehcache);
923         Cache cache = new JCache(ehcache, null);
924 
925         try {
926             cache.put(null, null);
927             assertNull(cache.get(null));
928             cache.put(null, "value");
929             assertEquals("value", cache.get(null));
930             cache.put("key", null);
931             assertEquals(null, cache.get("key"));
932             assertFalse(null instanceof Serializable);
933         } catch (Exception e) {
934             fail("Should not have thrown an Execption");
935         }
936     }
937 
938     /**
939      * Tests cache, memory store and disk store sizes from config
940      * jsr107 does not breakdowns of store sizes.
941      */
942     public void testSizes() throws Exception {
943         Cache cache = getTest1Cache();
944         assertEquals(0, cache.getCacheStatistics().getObjectCount());
945 
946         for (int i = 0; i < 10010; i++) {
947             cache.put("key" + i, "value1");
948         }
949         assertEquals(10010, cache.getCacheStatistics().getObjectCount());
950 
951         //NonSerializable
952         cache.put(new Object(), Object.class);
953 
954         assertEquals(10011, cache.getCacheStatistics().getObjectCount());
955 
956         cache.remove("key4");
957         cache.remove("key3");
958 
959         assertEquals(10009, cache.getCacheStatistics().getObjectCount());
960 
961         cache.clear();
962         assertEquals(0, cache.getCacheStatistics().getObjectCount());
963 
964     }
965 
966     /**
967      * Tests flushing the cache
968      * jsr107 does not specify a disk store and therefore does not have a flush.
969      */
970 //    public void testFlushWhenOverflowToDisk() throws Exception {
971 
972     /**
973      * Tests put works correctly for Elements with overriden TTL
974      * jsr107 does not support overriding TTL on a per entry basis
975      *
976      */
977 //    public void testPutWithOverriddenTTLAndTTI() throws Exception {
978 
979 
980     /**
981      * Tests using elements with null values. They should work as normal.
982      *
983      * @throws Exception
984      */
985     public void testNonSerializableElement() throws Exception {
986         Ehcache ehcache = new net.sf.ehcache.Cache("testElementWithNonSerializableValue", 1, true, false, 100, 200);
987         manager.addCache(ehcache);
988         Cache cache = new JCache(ehcache, null);
989 
990         cache.put("key1", new Object());
991         cache.put("key2", new Object());
992 
993         //Removed because could not overflow
994         assertNull(cache.get("key1"));
995 
996         //Second one should be in the MemoryStore and retrievable
997         assertNotNull(cache.get("key2"));
998     }
999 
1000 
1001     /**
1002      * Tests what happens when an Element throws an Error on serialization. This mimics
1003      * what a nasty error like OutOfMemoryError could do.
1004      * <p/>
1005      * Before a change to the SpoolAndExpiryThread to handle this situation this test failed and generated
1006      * the following log message.
1007      * Jun 28, 2006 7:17:16 PM net.sf.ehcache.store.DiskStore put
1008      * SEVERE: testThreadKillerCache: Elements cannot be written to disk store because the spool thread has died.
1009      *
1010      * @throws Exception
1011      */
1012     public void testSpoolThreadHandlesThreadKiller() throws Exception {
1013         Ehcache ehcache = new net.sf.ehcache.Cache("testThreadKiller", 1, true, false, 100, 200);
1014         manager.addCache(ehcache);
1015         Cache cache = new JCache(ehcache, null);
1016 
1017         cache.put("key", new ThreadKiller());
1018         cache.put("key1", "one");
1019         cache.put("key2", "two");
1020 
1021         Thread.sleep(2000);
1022 
1023         assertNotNull(cache.get("key1"));
1024         assertNotNull(cache.get("key2"));
1025     }
1026 
1027     /**
1028      * Tests disk store and memory store size
1029      * jsr107 does not support getting store sizes
1030      */
1031 //    public void testGetDiskStoreSize() throws Exception {
1032 
1033     /**
1034      * Tests that attempting to clone a cache fails with the right exception.
1035      * jsr107 does not make clone available
1036      *
1037      */
1038 //    public void testCloneFailures() throws Exception {
1039 
1040 
1041     /**
1042      * Tests that the toString() method works.
1043      */
1044     public void testToString() throws CacheException {
1045         Cache cache = getTest2Cache();
1046         cache.clear();
1047         LOG.info(cache);
1048         assertTrue(cache.toString().indexOf("test2") > -1);
1049         assertTrue(380 < cache.toString().length());
1050     }
1051 
1052     /**
1053      * When does equals mean the same thing as == for an element?
1054      * NA JSR107 does not have elements
1055      */
1056 //    public void testEquals() throws CacheException, InterruptedException {
1057 
1058     /**
1059      * Tests the uniqueness of the GUID
1060      * Not part of jsr107
1061      */
1062 //    public void testGuid() {
1063 
1064     /**
1065      * Does the Object API work?
1066      * jsr107 is an object API
1067      */
1068     public void testAPIObjectCompatibility() throws CacheException {
1069         Cache cache = getTest1Cache();
1070 
1071         Object objectKey = new Object();
1072         Object objectValue = new Object();
1073 
1074         cache.put(objectKey, objectValue);
1075 
1076         //Cannot get it back using get
1077         Object retrievedElement = cache.get(objectKey);
1078         assertNotNull(retrievedElement);
1079 
1080         //Test that equals works
1081         assertEquals(objectValue, retrievedElement);
1082 
1083     }
1084 
1085 
1086     /**
1087      * Does the Serializable API work?
1088      */
1089     public void testAPISerializableCompatibility() throws CacheException {
1090         //Set size so the second element overflows to disk.
1091         Cache cache = getTest2Cache();
1092 
1093         //Try object compatibility
1094         Serializable key = new String("key");
1095         Serializable serializableValue = new String("retrievedValue");
1096         cache.put(key, serializableValue);
1097         cache.put("key2", serializableValue);
1098         Object retrievedValue = cache.get(key);
1099         assertEquals(serializableValue, retrievedValue);
1100     }
1101 
1102     /**
1103      * Test issues reported. N/A
1104      */
1105 //    public void testDiskStoreFlorian() {
1106 
1107 
1108     /**
1109      * Multi-thread read-write test with 20 threads
1110      * Just use MemoryStore to put max stress on cache
1111      * Values that work:
1112      * <pre>
1113      * size     threads     maxTime
1114      * 10000    50          200
1115      * 200000   50          500
1116      * 200000   500         800
1117      * </pre>
1118      */
1119     public void testReadWriteThreads() throws Exception {
1120 
1121         final int size = 9000;
1122         final int maxTime = (int) (410 * StopWatch.getSpeedAdjustmentFactor());
1123         final Cache cache = getTest1Cache();
1124 
1125         long start = System.currentTimeMillis();
1126         final List executables = new ArrayList();
1127         final Random random = new Random();
1128 
1129         for (int i = 0; i < size; i++) {
1130             cache.put("" + i, "value");
1131         }
1132 
1133         // 50% of the time get data
1134         for (int i = 0; i < 30; i++) {
1135             final Executable executable = new Executable() {
1136                 public void execute() throws Exception {
1137                     final StopWatch stopWatch = new StopWatch();
1138                     long start = stopWatch.getElapsedTime();
1139                     cache.get("key" + random.nextInt(size));
1140                     long end = stopWatch.getElapsedTime();
1141                     long elapsed = end - start;
1142                     assertTrue("Get time outside of allowed range: " + elapsed, elapsed < maxTime);
1143                 }
1144             };
1145             executables.add(executable);
1146         }
1147 
1148         //25% of the time add data
1149         for (int i = 0; i < 10; i++) {
1150             final Executable executable = new Executable() {
1151                 public void execute() throws Exception {
1152                     final StopWatch stopWatch = new StopWatch();
1153                     long start = stopWatch.getElapsedTime();
1154                     cache.put("key" + random.nextInt(size), "value");
1155                     long end = stopWatch.getElapsedTime();
1156                     long elapsed = end - start;
1157                     assertTrue("Put time outside of allowed range: " + elapsed, elapsed < maxTime);
1158                 }
1159             };
1160             executables.add(executable);
1161         }
1162 
1163         //25% of the time remove the data
1164         for (int i = 0; i < 10; i++) {
1165             final Executable executable = new Executable() {
1166                 public void execute() throws Exception {
1167                     final StopWatch stopWatch = new StopWatch();
1168                     long start = stopWatch.getElapsedTime();
1169                     cache.remove("key" + random.nextInt(size));
1170                     long end = stopWatch.getElapsedTime();
1171                     long elapsed = end - start;
1172                     assertTrue("Remove time outside of allowed range: " + elapsed, elapsed < maxTime);
1173                 }
1174             };
1175             executables.add(executable);
1176         }
1177 
1178         //some of the time clear the data
1179         for (int i = 0; i < 10; i++) {
1180             final Executable executable = new Executable() {
1181                 public void execute() throws Exception {
1182                     final StopWatch stopWatch = new StopWatch();
1183                     long start = stopWatch.getElapsedTime();
1184                     int randomInteger = random.nextInt(20);
1185                     if (randomInteger == 3) {
1186                         cache.clear();
1187                     }
1188                     long end = stopWatch.getElapsedTime();
1189                     long elapsed = end - start;
1190                     assertTrue("RemoveAll time outside of allowed range: " + elapsed, elapsed < maxTime);
1191                 }
1192             };
1193             executables.add(executable);
1194         }
1195 
1196         runThreads(executables);
1197         long end = System.currentTimeMillis();
1198         LOG.info("Total time for the test: " + (end - start) + " ms");
1199     }
1200 
1201     /**
1202      * Tests the async load with a single item
1203      */
1204     public void testAsynchronousLoad() throws InterruptedException, ExecutionException {
1205 
1206         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1207         JCache jcache = new JCache(manager.getCache("sampleCache1"), countingCacheLoader);
1208         ExecutorService executorService = jcache.getExecutorService();
1209 
1210 
1211         Future future = jcache.asynchronousLoad("key1");
1212         assertFalse(future.isDone());
1213 
1214         Object object = future.get();
1215         assertTrue(future.isDone());
1216         assertNull(object);
1217 
1218         assertFalse(executorService.isShutdown());
1219 
1220         assertEquals(1, jcache.size());
1221         assertEquals(1, countingCacheLoader.getLoadCounter());
1222     }
1223 
1224 
1225     /**
1226      * Tests the public API load method with a single item
1227      */
1228     public void testLoad() throws InterruptedException, ExecutionException, CacheException {
1229 
1230         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1231         JCache jcache = new JCache(manager.getCache("sampleCache1"), countingCacheLoader);
1232         ExecutorService executorService = jcache.getExecutorService();
1233 
1234         jcache.load("key1");
1235 
1236         Thread.sleep(500);
1237 
1238         assertFalse(executorService.isShutdown());
1239 
1240         assertEquals(1, jcache.size());
1241         assertEquals(1, countingCacheLoader.getLoadCounter());
1242     }
1243 
1244 
1245     /**
1246      * Tests that the setLoader method allows the loader to be changed
1247      */
1248     public void testLoadWithDynamicLoaderInjection() throws InterruptedException, ExecutionException, CacheException {
1249 
1250         //null loader so no loading happens
1251         JCache jcache = new JCache(manager.getCache("sampleCache1"), null);
1252         jcache.load("key1");
1253         assertEquals(0, jcache.size());
1254 
1255 
1256         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1257         jcache.setCacheLoader(countingCacheLoader);
1258 
1259         jcache.load("key1");
1260         Thread.sleep(500);
1261 
1262         ExecutorService executorService = jcache.getExecutorService();
1263         assertFalse(executorService.isShutdown());
1264 
1265         assertEquals(1, jcache.size());
1266         assertEquals(1, countingCacheLoader.getLoadCounter());
1267     }
1268 
1269 
1270     /**
1271      * Tests the loadAll async method
1272      */
1273     public void testAsynchronousLoadAll() throws InterruptedException, ExecutionException {
1274 
1275         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1276         JCache jcache = new JCache(manager.getCache("sampleCache1"), countingCacheLoader);
1277         ExecutorService executorService = jcache.getExecutorService();
1278 
1279         List keys = new ArrayList();
1280         for (int i = 0; i < 1000; i++) {
1281             keys.add(new Integer(i));
1282         }
1283 
1284         Future future = jcache.asynchronousLoadAll(keys);
1285         assertFalse(future.isDone());
1286 
1287         Object object = future.get();
1288         assertTrue(future.isDone());
1289         assertNull(object);
1290 
1291         assertFalse(executorService.isShutdown());
1292 
1293         assertEquals(1000, jcache.size());
1294         assertEquals(1000, countingCacheLoader.getLoadAllCounter());
1295     }
1296 
1297     /**
1298      * Tests the loadAll Public API method
1299      */
1300     public void testLoadAll() throws InterruptedException, ExecutionException, CacheException {
1301 
1302         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1303         JCache jcache = new JCache(manager.getCache("sampleCache1"), countingCacheLoader);
1304         ExecutorService executorService = jcache.getExecutorService();
1305 
1306         //check null works ok
1307         jcache.loadAll(null);
1308 
1309         List keys = new ArrayList();
1310         for (int i = 0; i < 999; i++) {
1311             keys.add(new Integer(i));
1312         }
1313         //make on key null
1314         keys.add(null);
1315 
1316         //pre populate only 1 element
1317         jcache.put(new Integer(1), "");
1318 
1319         jcache.loadAll(keys);
1320         Thread.sleep((long) (3000 * StopWatch.getSpeedAdjustmentFactor()));
1321 
1322         assertFalse(executorService.isShutdown());
1323 
1324         assertEquals(1000, jcache.size());
1325         assertEquals(999, countingCacheLoader.getLoadAllCounter());
1326         
1327     }
1328 
1329 
1330     /**
1331      * Tests the getAll Public API method
1332      */
1333     public void testGetAll() throws InterruptedException, ExecutionException, CacheException {
1334 
1335         JCache jcache = new JCache(manager.getCache("sampleCache1"), null);
1336 
1337         //check null CacheLoader
1338         Map map = jcache.getAll(null);
1339         assertNotNull(map);
1340         assertEquals(0, map.size());
1341 
1342 
1343         CountingCacheLoader countingCacheLoader = new CountingCacheLoader();
1344         jcache.setCacheLoader(countingCacheLoader);
1345         ExecutorService executorService = jcache.getExecutorService();
1346 
1347         //check null
1348         map = jcache.getAll(null);
1349         assertNotNull(map);
1350         assertEquals(0, map.size());
1351 
1352 
1353         List keys = new ArrayList();
1354         for (int i = 0; i < 1000; i++) {
1355             keys.add(new Integer(i));
1356         }
1357 
1358         //pre populate only 1 element
1359         jcache.put(new Integer(1), "");
1360 
1361         jcache.getAll(keys);
1362 
1363         assertFalse(executorService.isShutdown());
1364 
1365         assertEquals(1000, jcache.size());
1366         assertEquals(999, countingCacheLoader.getLoadCounter());
1367     }
1368 
1369 
1370 }