KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > passivation > ReplicatedPassivationIntegrationTest


1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * as indicated by the @author tags. See the copyright.txt file in the
5  * distribution for a full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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.AbstractCacheListener;
29 import org.jboss.cache.CacheImpl;
30 import org.jboss.cache.Fqn;
31 import org.jboss.cache.factories.XmlConfigurationParser;
32 import org.jboss.cache.misc.TestingUtil;
33
34 import java.util.Map JavaDoc;
35
36 /**
37  * @author Ben Wang, Feb 11, 2004
38  */

39 public class ReplicatedPassivationIntegrationTest extends TestCase
40 {
41    CacheImpl cache_;
42    CacheImpl cache1_;
43    protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
44    int wakeupIntervalMillis_ = 0;
45    ReplicatedPassivationIntegrationTest.PassivationListener listener_;
46
47    public ReplicatedPassivationIntegrationTest(String JavaDoc s)
48    {
49       super(s);
50       listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
51    }
52
53    public void setUp() throws Exception JavaDoc
54    {
55       super.setUp();
56       cache_ = new CacheImpl();
57       initCaches(cache_);
58       cache_.getConfiguration().setUseRegionBasedMarshalling(true);
59       cache_.start();
60
61       cache1_ = new CacheImpl();
62       initCaches(cache1_);
63       cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
64
65       cache1_.start();
66       cache1_.getNotifier().addCacheListener(listener_);
67       listener_.resetCounter();
68
69       wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
70       log("wakeupInterval is " + wakeupIntervalMillis_);
71       if (wakeupIntervalMillis_ <= 0)
72       {
73          fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
74       }
75    }
76
77    void initCaches(CacheImpl cache) throws Exception JavaDoc
78    {
79       cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml")); // read in generic local xml
80
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
81    }
82
83    public void tearDown() throws Exception JavaDoc
84    {
85       super.tearDown();
86       cache_.stop();
87       cache1_.stop();
88    }
89
90    /**
91     */

92    public void testActivationEvent() throws Exception JavaDoc
93    {
94       String JavaDoc rootStr = "/org/jboss/test/data/";
95       String JavaDoc rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
96       String JavaDoc str = rootStr + "0";
97       cache_.remove("/");
98       listener_.resetCounter();
99
100       cache_.put(str, str, str);
101       cache_.put(rootStr1, str, str);
102
103       TestingUtil.sleepThread(11000);
104       assertFalse("UnversionedNode should not exist", cache1_.exists(str, str));
105       String JavaDoc val;
106       val = (String JavaDoc) cache1_.get(str, str);
107       val = (String JavaDoc) cache1_.get(rootStr1, str);
108       assertNotNull("DataNode should be activated ", val);
109       assertEquals("Eviction counter ", 2, listener_.getCounter());
110    }
111
112    void log(String JavaDoc msg)
113    {
114       System.out.println("-- " + msg);
115    }
116
117    class PassivationListener extends AbstractCacheListener
118    {
119       int counter = 0;
120       int loadedCounter = 0;
121
122       public int getCounter()
123       {
124          return counter;
125       }
126
127       public void resetCounter()
128       {
129          counter = 0;
130          loadedCounter = 0;
131       }
132
133       public void nodeActivated(Fqn fqn, boolean pre)
134       {
135          if (!pre)
136          {
137             counter++;
138             System.out.println("nodeActivate(): counter: " + counter);
139             System.out.println("nodeActivate(): " + fqn);
140          }
141       }
142
143       public void nodePassivated(Fqn fqn, boolean pre)
144       {
145          if (pre)
146          {
147             System.out.println("nodePassivate(): " + fqn);
148          }
149       }
150
151       public void nodeLoaded(Fqn f, boolean pre, Map JavaDoc data)
152       {
153          if (!pre)
154          {
155             loadedCounter++;
156          }
157       }
158
159    }
160 }
161
Popular Tags