1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.passivation; |
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.factories.XmlConfigurationParser; |
17 |
| import org.jboss.cache.loader.DummyInMemoryCacheLoader; |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| public class ConcurrentPassivationTest extends TestCase |
26 |
| { |
27 |
| private CacheImpl cache_; |
28 |
| private int wakeupIntervalMillis_ = 0; |
29 |
| |
30 |
1
| public ConcurrentPassivationTest(String s)
|
31 |
| { |
32 |
1
| super(s);
|
33 |
| } |
34 |
| |
35 |
1
| public void setUp() throws Exception
|
36 |
| { |
37 |
1
| super.setUp();
|
38 |
1
| initCaches();
|
39 |
1
| wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
|
40 |
1
| if (wakeupIntervalMillis_ < 0)
|
41 |
| { |
42 |
0
| fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
|
43 |
| } |
44 |
| |
45 |
| } |
46 |
| |
47 |
1
| void initCaches() throws Exception
|
48 |
| { |
49 |
1
| cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
50 |
1
| cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));
|
51 |
1
| cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
52 |
1
| cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
|
53 |
1
| cache_.start();
|
54 |
| } |
55 |
| |
56 |
1
| public void tearDown() throws Exception
|
57 |
| { |
58 |
1
| super.tearDown();
|
59 |
1
| cache_.stop();
|
60 |
1
| cache_ = null;
|
61 |
| } |
62 |
| |
63 |
1
| public void testConcurrentPassivation() throws Exception
|
64 |
| { |
65 |
1
| Fqn base = Fqn.fromString("/org/jboss/test/data/concurrent/passivation");
|
66 |
| |
67 |
| |
68 |
| |
69 |
1
| for (int i = 0; i < 35000; i++)
|
70 |
| { |
71 |
35000
| cache_.put(new Fqn(base, i / 100), i, "value");
|
72 |
| } |
73 |
| |
74 |
| |
75 |
1
| long loopDone = System.currentTimeMillis() + (5 * wakeupIntervalMillis_);
|
76 |
| |
77 |
1
| System.out.println("Initialised; Loop for " + (5 * wakeupIntervalMillis_) + " millis");
|
78 |
| |
79 |
1
| while (System.currentTimeMillis() < loopDone)
|
80 |
| { |
81 |
| |
82 |
8
| for (int i = 0; i < 35000; i++)
|
83 |
| { |
84 |
280000
| Fqn fqn = new Fqn(base, i / 100);
|
85 |
280000
| assertNotNull("Get on Fqn " + fqn + " returned null", cache_.get(fqn));
|
86 |
| } |
87 |
| } |
88 |
| } |
89 |
| |
90 |
1
| public static Test suite()
|
91 |
| { |
92 |
1
| return new TestSuite(org.jboss.cache.passivation.ConcurrentPassivationTest.class);
|
93 |
| } |
94 |
| |
95 |
0
| public static void main(String[] args)
|
96 |
| { |
97 |
0
| junit.textui.TestRunner.run(org.jboss.cache.passivation.ConcurrentPassivationTest.suite());
|
98 |
| } |
99 |
| } |