1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.passivation; |
9 |
| |
10 |
| import junit.framework.TestCase; |
11 |
| import org.apache.commons.logging.Log; |
12 |
| import org.apache.commons.logging.LogFactory; |
13 |
| import org.jboss.cache.AbstractCacheListener; |
14 |
| import org.jboss.cache.CacheImpl; |
15 |
| import org.jboss.cache.DefaultCacheFactory; |
16 |
| import org.jboss.cache.Fqn; |
17 |
| import org.jboss.cache.config.CacheLoaderConfig; |
18 |
| import org.jboss.cache.config.Configuration; |
19 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
20 |
| import org.jboss.cache.misc.TestingUtil; |
21 |
| |
22 |
| import java.util.Map; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class LocalPassivationIntegrationTest extends TestCase |
28 |
| { |
29 |
| CacheImpl cache_; |
30 |
| protected final static Log log = LogFactory.getLog(LocalPassivationIntegrationTest.class); |
31 |
| int wakeupIntervalMillis_ = 0; |
32 |
| PassivationListener listener_; |
33 |
| |
34 |
1
| public LocalPassivationIntegrationTest(String s)
|
35 |
| { |
36 |
1
| super(s);
|
37 |
1
| listener_ = new PassivationListener();
|
38 |
| } |
39 |
| |
40 |
1
| public void setUp() throws Exception
|
41 |
| { |
42 |
1
| super.setUp();
|
43 |
1
| TestingUtil.recursiveFileRemove("/tmp/JBossCacheFileCacheLoader");
|
44 |
1
| cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
45 |
1
| initCaches(cache_);
|
46 |
1
| cache_.getConfiguration().setUseRegionBasedMarshalling(true);
|
47 |
| |
48 |
1
| cache_.start();
|
49 |
| |
50 |
1
| cache_.getNotifier().addCacheListener(listener_);
|
51 |
1
| listener_.resetCounter();
|
52 |
| |
53 |
1
| wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
|
54 |
1
| log("wakeupInterval is " + wakeupIntervalMillis_);
|
55 |
1
| if (wakeupIntervalMillis_ <= 0)
|
56 |
| { |
57 |
0
| fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
|
58 |
| } |
59 |
| } |
60 |
| |
61 |
1
| void initCaches(CacheImpl cache) throws Exception
|
62 |
| { |
63 |
1
| cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));
|
64 |
1
| cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
|
65 |
| |
66 |
1
| injectCacheLoaderLocation(cache.getConfiguration(), "/tmp/JBossCacheFileCacheLoader");
|
67 |
| |
68 |
| } |
69 |
| |
70 |
1
| private void injectCacheLoaderLocation(Configuration configuration, String location)
|
71 |
| { |
72 |
1
| for (CacheLoaderConfig.IndividualCacheLoaderConfig iclc : configuration.getCacheLoaderConfig().getIndividualCacheLoaderConfigs())
|
73 |
| { |
74 |
1
| iclc.getProperties().put("location", location);
|
75 |
| } |
76 |
| } |
77 |
| |
78 |
| |
79 |
1
| public void tearDown() throws Exception
|
80 |
| { |
81 |
1
| super.tearDown();
|
82 |
1
| cache_.stop();
|
83 |
| } |
84 |
| |
85 |
| |
86 |
| |
87 |
1
| public void testActivationEvent() throws Exception
|
88 |
| { |
89 |
1
| String rootStr = "/org/jboss/test/data/";
|
90 |
1
| String str = rootStr + "0";
|
91 |
1
| cache_.remove("/");
|
92 |
1
| listener_.resetCounter();
|
93 |
| |
94 |
1
| cache_.put(str, str, str);
|
95 |
| |
96 |
1
| TestingUtil.sleepThread(20000);
|
97 |
1
| assertFalse("UnversionedNode should not exist", cache_.exists(str, str));
|
98 |
1
| String val = (String) cache_.get(str, str);
|
99 |
1
| assertNotNull("DataNode should be activated ", val);
|
100 |
1
| assertEquals("Eviction counter ", 1, listener_.getCounter());
|
101 |
| } |
102 |
| |
103 |
1
| void log(String msg)
|
104 |
| { |
105 |
1
| System.out.println("-- " + msg);
|
106 |
| } |
107 |
| |
108 |
| class PassivationListener extends AbstractCacheListener |
109 |
| { |
110 |
| int counter = 0; |
111 |
| int loadedCounter = 0; |
112 |
| |
113 |
1
| public int getCounter()
|
114 |
| { |
115 |
1
| return counter;
|
116 |
| } |
117 |
| |
118 |
2
| public void resetCounter()
|
119 |
| { |
120 |
2
| counter = 0;
|
121 |
2
| loadedCounter = 0;
|
122 |
| } |
123 |
| |
124 |
4
| public void nodeActivated(Fqn fqn, boolean pre)
|
125 |
| { |
126 |
4
| if (!pre)
|
127 |
| { |
128 |
1
| counter++;
|
129 |
1
| System.out.println("nodeActivate(): counter: " + counter);
|
130 |
| } |
131 |
| } |
132 |
| |
133 |
2
| public void nodePassivated(Fqn fqn, boolean pre)
|
134 |
| { |
135 |
2
| if (pre)
|
136 |
| { |
137 |
1
| System.out.println("nodePassivate(): " + fqn);
|
138 |
| } |
139 |
| } |
140 |
| |
141 |
2
| public void nodeLoaded(Fqn f, boolean pre, Map data)
|
142 |
| { |
143 |
2
| if (!pre)
|
144 |
| { |
145 |
1
| loadedCounter++;
|
146 |
| } |
147 |
| } |
148 |
| |
149 |
| } |
150 |
| } |