1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.eviction; |
9 |
| |
10 |
| import junit.framework.Test; |
11 |
| import junit.framework.TestCase; |
12 |
| import junit.framework.TestSuite; |
13 |
| import org.jboss.cache.CacheImpl; |
14 |
| import org.jboss.cache.DefaultCacheFactory; |
15 |
| import org.jboss.cache.Fqn; |
16 |
| import org.jboss.cache.misc.TestingUtil; |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| public class ConcurrentEvictionTest extends TestCase |
25 |
| { |
26 |
| private CacheImpl cache_; |
27 |
| private int wakeupIntervalMillis_ = 0; |
28 |
| |
29 |
1
| public ConcurrentEvictionTest(String s)
|
30 |
| { |
31 |
1
| super(s);
|
32 |
| } |
33 |
| |
34 |
1
| protected void setUp() throws Exception
|
35 |
| { |
36 |
1
| super.setUp();
|
37 |
1
| initCaches();
|
38 |
1
| wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
|
39 |
1
| if (wakeupIntervalMillis_ < 0)
|
40 |
| { |
41 |
0
| fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
|
42 |
| } |
43 |
| |
44 |
| } |
45 |
| |
46 |
1
| void initCaches() throws Exception
|
47 |
| { |
48 |
1
| TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader");
|
49 |
1
| cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-eviction-cacheloader-service.xml", false);
|
50 |
1
| cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
|
51 |
1
| cache_.start();
|
52 |
| } |
53 |
| |
54 |
1
| public void tearDown() throws Exception
|
55 |
| { |
56 |
1
| super.tearDown();
|
57 |
1
| TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader");
|
58 |
1
| cache_.stop();
|
59 |
1
| cache_ = null;
|
60 |
| } |
61 |
| |
62 |
1
| public void testConcurrentEviction() throws Exception
|
63 |
| { |
64 |
1
| Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction");
|
65 |
| |
66 |
| |
67 |
| |
68 |
1
| for (int i = 0; i < 1000; i++)
|
69 |
| { |
70 |
1000
| cache_.put(new Fqn(base, i / 100), new Integer(i), "value");
|
71 |
| } |
72 |
| |
73 |
| |
74 |
1
| long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
|
75 |
1
| while (System.currentTimeMillis() < loopDone)
|
76 |
| { |
77 |
| |
78 |
359
| for (int i = 0; i < 1000; i++)
|
79 |
| { |
80 |
359000
| Fqn fqn = new Fqn(base, i / 100);
|
81 |
359000
| Integer key = i;
|
82 |
359000
| assertNotNull("found value under Fqn " + fqn + " and key " + key,
|
83 |
| cache_.get(fqn, key)); |
84 |
| } |
85 |
| } |
86 |
| } |
87 |
| |
88 |
1
| public static Test suite()
|
89 |
| { |
90 |
1
| return new TestSuite(ConcurrentEvictionTest.class);
|
91 |
| } |
92 |
| } |