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 |
| import java.util.Properties; |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| public class ConcurrentEvictionTest extends TestCase |
27 |
| { |
28 |
| private CacheImpl cache_; |
29 |
| private int wakeupIntervalMillis_ = 0; |
30 |
| private String tmpDir = System.getProperty("java.io.tmpdir", "/tmp"); |
31 |
| private String cacheLoaderDir = "/JBossCacheFileCacheLoader"; |
32 |
| |
33 |
1
| public ConcurrentEvictionTest(String s)
|
34 |
| { |
35 |
1
| super(s);
|
36 |
| } |
37 |
| |
38 |
1
| protected void setUp() throws Exception
|
39 |
| { |
40 |
1
| super.setUp();
|
41 |
1
| initCaches();
|
42 |
1
| wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
|
43 |
1
| if (wakeupIntervalMillis_ < 0)
|
44 |
| { |
45 |
0
| fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
|
46 |
| } |
47 |
| |
48 |
| } |
49 |
| |
50 |
1
| void initCaches() throws Exception
|
51 |
| { |
52 |
1
| TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
|
53 |
1
| cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache("META-INF/local-eviction-cacheloader-service.xml", false);
|
54 |
1
| cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
55 |
1
| Properties p = new Properties();
|
56 |
1
| p.put("location", tmpDir + cacheLoaderDir);
|
57 |
1
| cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setProperties(p);
|
58 |
1
| cache_.start();
|
59 |
| } |
60 |
| |
61 |
1
| public void tearDown() throws Exception
|
62 |
| { |
63 |
1
| super.tearDown();
|
64 |
1
| TestingUtil.recursiveFileRemove(tmpDir + cacheLoaderDir);
|
65 |
1
| cache_.stop();
|
66 |
1
| cache_ = null;
|
67 |
| } |
68 |
| |
69 |
1
| public void testConcurrentEviction() throws Exception
|
70 |
| { |
71 |
1
| Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/eviction");
|
72 |
| |
73 |
| |
74 |
| |
75 |
1
| for (int i = 0; i < 1000; i++)
|
76 |
| { |
77 |
1000
| cache_.put(new Fqn(base, i / 100), i, "value");
|
78 |
| } |
79 |
| |
80 |
| |
81 |
1
| long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
|
82 |
1
| while (System.currentTimeMillis() < loopDone)
|
83 |
| { |
84 |
| |
85 |
275
| for (int i = 0; i < 1000; i++)
|
86 |
| { |
87 |
275000
| Fqn fqn = new Fqn(base, i / 100);
|
88 |
275000
| Integer key = i;
|
89 |
275000
| assertNotNull("found value under Fqn " + fqn + " and key " + key,
|
90 |
| cache_.get(fqn, key)); |
91 |
| } |
92 |
| } |
93 |
| } |
94 |
| |
95 |
1
| public static Test suite()
|
96 |
| { |
97 |
1
| return new TestSuite(ConcurrentEvictionTest.class);
|
98 |
| } |
99 |
| } |