1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.jcs.jcache.extras.loader;
20
21 import org.apache.commons.jcs.jcache.extras.InternalCacheRule;
22 import org.junit.Rule;
23 import org.junit.Test;
24
25 import javax.cache.Cache;
26 import javax.cache.configuration.Configuration;
27 import javax.cache.configuration.MutableConfiguration;
28 import javax.cache.integration.CacheLoaderException;
29 import java.util.concurrent.atomic.AtomicInteger;
30
31 import static org.junit.Assert.assertEquals;
32
33 public class CompositeCacheLoaderTest
34 {
35 @Rule
36 public final InternalCacheRule rule = new InternalCacheRule(this);
37
38 private final AtomicInteger count = new AtomicInteger(0);
39
40 private final CacheLoaderAdapter<String, String> loader1 = new CacheLoaderAdapter<String, String>()
41 {
42 @Override
43 public String load(String key) throws CacheLoaderException
44 {
45 count.incrementAndGet();
46 return null;
47 }
48 };
49 private final CacheLoaderAdapter<String, String> loader2 = new CacheLoaderAdapter<String, String>()
50 {
51 @Override
52 public String load(String key) throws CacheLoaderException
53 {
54 count.incrementAndGet();
55 return null;
56 }
57 };
58 private final Configuration<?, ?> config = new MutableConfiguration<String, String>()
59 .setStoreByValue(false)
60 .setReadThrough(true)
61 .setCacheLoaderFactory(new CompositeCacheLoader<String, String>(loader1, loader2));
62 private Cache<String, String> cache;
63
64 @Test
65 public void checkComposite()
66 {
67 cache.get("foo");
68 assertEquals(2, count.get());
69 }
70 }