1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| package org.jboss.cache.passivation; |
24 |
| |
25 |
| import junit.framework.TestCase; |
26 |
| import org.apache.commons.logging.Log; |
27 |
| import org.apache.commons.logging.LogFactory; |
28 |
| import org.jboss.cache.CacheImpl; |
29 |
| import org.jboss.cache.DefaultCacheFactory; |
30 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
31 |
| import org.jboss.cache.loader.DummyInMemoryCacheLoader; |
32 |
| import org.jboss.cache.misc.TestingUtil; |
33 |
| import org.jboss.cache.notifications.annotation.CacheListener; |
34 |
| import org.jboss.cache.notifications.annotation.NodeActivated; |
35 |
| import org.jboss.cache.notifications.annotation.NodeLoaded; |
36 |
| import org.jboss.cache.notifications.annotation.NodePassivated; |
37 |
| import org.jboss.cache.notifications.event.NodeEvent; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public class ReplicatedPassivationIntegrationTest extends TestCase |
43 |
| { |
44 |
| CacheImpl cache_; |
45 |
| CacheImpl cache1_; |
46 |
| protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class); |
47 |
| int wakeupIntervalMillis_ = 0; |
48 |
| PassivationListener listener_; |
49 |
| |
50 |
1
| public ReplicatedPassivationIntegrationTest(String s)
|
51 |
| { |
52 |
1
| super(s);
|
53 |
1
| listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
|
54 |
| } |
55 |
| |
56 |
1
| public void setUp() throws Exception
|
57 |
| { |
58 |
1
| super.setUp();
|
59 |
1
| cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
60 |
1
| initCaches(cache_);
|
61 |
1
| cache_.getConfiguration().setUseRegionBasedMarshalling(true);
|
62 |
1
| cache_.start();
|
63 |
| |
64 |
1
| cache1_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
65 |
1
| initCaches(cache1_);
|
66 |
1
| cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
|
67 |
| |
68 |
1
| cache1_.start();
|
69 |
1
| cache1_.getNotifier().addCacheListener(listener_);
|
70 |
1
| listener_.resetCounter();
|
71 |
| |
72 |
1
| wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
|
73 |
1
| log("wakeupInterval is " + wakeupIntervalMillis_);
|
74 |
1
| if (wakeupIntervalMillis_ <= 0)
|
75 |
| { |
76 |
0
| fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
|
77 |
| } |
78 |
| } |
79 |
| |
80 |
2
| void initCaches(CacheImpl cache) throws Exception
|
81 |
| { |
82 |
2
| cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml"));
|
83 |
2
| cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
|
84 |
2
| cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
|
85 |
| } |
86 |
| |
87 |
1
| public void tearDown() throws Exception
|
88 |
| { |
89 |
1
| super.tearDown();
|
90 |
1
| cache_.stop();
|
91 |
1
| cache1_.stop();
|
92 |
| } |
93 |
| |
94 |
| |
95 |
| |
96 |
1
| public void testActivationEvent() throws Exception
|
97 |
| { |
98 |
1
| String rootStr = "/org/jboss/test/data/";
|
99 |
1
| String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
|
100 |
1
| String str = rootStr + "0";
|
101 |
1
| cache_.remove("/");
|
102 |
| |
103 |
1
| cache_.put(str, str, str);
|
104 |
1
| cache_.put(rootStr1, str, str);
|
105 |
| |
106 |
1
| TestingUtil.sleepThread(11000);
|
107 |
1
| assertFalse("UnversionedNode should not exist", cache1_.exists(str, str));
|
108 |
1
| String val;
|
109 |
1
| val = (String) cache1_.get(str, str);
|
110 |
1
| val = (String) cache1_.get(rootStr1, str);
|
111 |
1
| assertNotNull("DataNode should be activated ", val);
|
112 |
| } |
113 |
| |
114 |
1
| void log(String msg)
|
115 |
| { |
116 |
1
| System.out.println("-- " + msg);
|
117 |
| } |
118 |
| |
119 |
| @CacheListener |
120 |
| public class PassivationListener |
121 |
| { |
122 |
| int counter = 0; |
123 |
| int loadedCounter = 0; |
124 |
| |
125 |
0
| public int getCounter()
|
126 |
| { |
127 |
0
| return counter;
|
128 |
| } |
129 |
| |
130 |
1
| public void resetCounter()
|
131 |
| { |
132 |
1
| counter = 0;
|
133 |
1
| loadedCounter = 0;
|
134 |
| } |
135 |
| |
136 |
6
| @NodeActivated
|
137 |
| public void nodeActivated(NodeEvent ne) |
138 |
| { |
139 |
6
| if (!ne.isPre())
|
140 |
| { |
141 |
2
| counter++;
|
142 |
2
| System.out.println("nodeActivate(): counter: " + counter);
|
143 |
2
| System.out.println("nodeActivate(): " + ne.getFqn());
|
144 |
| } |
145 |
| } |
146 |
| |
147 |
4
| @NodePassivated
|
148 |
| public void nodePassivated(NodeEvent ne) |
149 |
| { |
150 |
4
| if (ne.isPre())
|
151 |
| { |
152 |
2
| System.out.println("nodePassivate(): " + ne.getFqn());
|
153 |
| } |
154 |
| } |
155 |
| |
156 |
4
| @NodeLoaded
|
157 |
| public void nodeLoaded(NodeEvent ne) |
158 |
| { |
159 |
4
| if (!ne.isPre())
|
160 |
| { |
161 |
2
| loadedCounter++;
|
162 |
| } |
163 |
| } |
164 |
| |
165 |
| } |
166 |
| } |