Source Code Cross Referenced for RMIBootstrapCacheLoaderTest.java in  » Cache » ehcache » net » sf » ehcache » distribution » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » ehcache » net.sf.ehcache.distribution 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Copyright 2003-2007 Luck Consulting Pty Ltd
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */package net.sf.ehcache.distribution;
016:
017:        import junit.framework.TestCase;
018:        import net.sf.ehcache.AbstractCacheTest;
019:        import net.sf.ehcache.Cache;
020:        import net.sf.ehcache.CacheException;
021:        import net.sf.ehcache.CacheManager;
022:        import net.sf.ehcache.Element;
023:        import net.sf.ehcache.event.CountingCacheEventListener;
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:
027:        import java.util.Date;
028:
029:        /**
030:         * @author Greg Luck
031:         * @version $Id: RMIBootstrapCacheLoaderTest.java 519 2007-07-27 07:11:45Z gregluck $
032:         */
033:        public class RMIBootstrapCacheLoaderTest extends TestCase {
034:
035:            /**
036:             * A value to represent replicate asynchronously
037:             */
038:            protected static final boolean ASYNCHRONOUS = true;
039:
040:            /**
041:             * A value to represent replicate synchronously
042:             */
043:            protected static final boolean SYNCHRONOUS = false;
044:
045:            private static final Log LOG = LogFactory
046:                    .getLog(RMICacheReplicatorTest.class.getName());
047:
048:            /**
049:             * CacheManager 1 in the cluster
050:             */
051:            protected CacheManager manager1;
052:            /**
053:             * CacheManager 2 in the cluster
054:             */
055:            protected CacheManager manager2;
056:            /**
057:             * CacheManager 3 in the cluster
058:             */
059:            protected CacheManager manager3;
060:            /**
061:             * CacheManager 4 in the cluster
062:             */
063:            protected CacheManager manager4;
064:            /**
065:             * CacheManager 5 in the cluster
066:             */
067:            protected CacheManager manager5;
068:            /**
069:             * CacheManager 6 in the cluster
070:             */
071:            protected CacheManager manager6;
072:
073:            /**
074:             * The name of the cache under test
075:             */
076:            protected String cacheName = "sampleCache1";
077:
078:            /**
079:             * {@inheritDoc}
080:             * Sets up two caches: cache1 is local. cache2 is to be receive updates
081:             *
082:             * @throws Exception
083:             */
084:            protected void setUp() throws Exception {
085:                if (JVMUtil.isSingleRMIRegistryPerVM()) {
086:                    return;
087:                }
088:
089:                MulticastKeepaliveHeartbeatSender.setHeartBeatInterval(1000);
090:
091:                CountingCacheEventListener.resetCounters();
092:                manager1 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
093:                        + "distribution/ehcache-distributed1.xml");
094:                manager2 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
095:                        + "distribution/ehcache-distributed2.xml");
096:
097:                //manager6 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR + "distribution/ehcache-distributed-jndi6.xml");
098:
099:                //allow cluster to be established
100:                Thread.sleep(3000);
101:            }
102:
103:            /**
104:             * Force the VM to grow to its full size. This stops SoftReferences from being reclaimed in favour of
105:             * Heap growth. Only an issue when a VM is cold.
106:             */
107:            protected void forceVMGrowth() {
108:                byte[] forceVMGrowth = new byte[50000000];
109:            }
110:
111:            /**
112:             * {@inheritDoc}
113:             *
114:             * @throws Exception
115:             */
116:            protected void tearDown() throws Exception {
117:
118:                if (JVMUtil.isSingleRMIRegistryPerVM()) {
119:                    return;
120:                }
121:
122:                if (manager1 != null) {
123:                    manager1.shutdown();
124:                }
125:                if (manager2 != null) {
126:                    manager2.shutdown();
127:                }
128:                if (manager3 != null) {
129:                    manager3.shutdown();
130:                }
131:                if (manager4 != null) {
132:                    manager4.shutdown();
133:                }
134:                if (manager5 != null) {
135:                    manager5.shutdown();
136:                }
137:                if (manager6 != null) {
138:                    manager6.shutdown();
139:                }
140:            }
141:
142:            /**
143:             * Tests loading from bootstrap
144:             */
145:            public void testBootstrapFromClusterWithAsyncLoader()
146:                    throws CacheException, InterruptedException {
147:
148:                if (JVMUtil.isSingleRMIRegistryPerVM()) {
149:                    return;
150:                }
151:
152:                forceVMGrowth();
153:
154:                //Give everything a chance to startup
155:                Integer index = null;
156:                for (int i = 0; i < 2; i++) {
157:                    for (int j = 0; j < 1000; j++) {
158:                        index = new Integer(((1000 * i) + j));
159:                        manager1
160:                                .getCache("sampleCache1")
161:                                .put(
162:                                        new Element(
163:                                                index,
164:                                                "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
165:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
166:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
167:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
168:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
169:                    }
170:
171:                }
172:                assertEquals(2000, manager1.getCache("sampleCache1").getSize());
173:
174:                Thread.sleep(8000);
175:                assertEquals(2000, manager2.getCache("sampleCache1").getSize());
176:
177:                manager3 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
178:                        + "distribution/ehcache-distributed3.xml");
179:                Thread.sleep(5000);
180:                assertEquals(2000, manager3.getCache("sampleCache1").getSize());
181:
182:            }
183:
184:            /**
185:             * Tests loading from bootstrap
186:             */
187:            public void testBootstrapFromClusterWithSyncLoader()
188:                    throws CacheException, InterruptedException {
189:
190:                if (JVMUtil.isSingleRMIRegistryPerVM()) {
191:                    return;
192:                }
193:
194:                forceVMGrowth();
195:
196:                //Give everything a chance to startup
197:                Integer index = null;
198:                for (int i = 0; i < 2; i++) {
199:                    for (int j = 0; j < 1000; j++) {
200:                        index = new Integer(((1000 * i) + j));
201:                        manager1
202:                                .getCache("sampleCache2")
203:                                .put(
204:                                        new Element(
205:                                                index,
206:                                                "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
207:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
208:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
209:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
210:                                                        + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
211:                    }
212:
213:                }
214:
215:                assertEquals(2000, manager1.getCache("sampleCache2").getSize());
216:
217:                Thread.sleep(8000);
218:                assertEquals(2000, manager2.getCache("sampleCache2").getSize());
219:
220:                manager3 = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR
221:                        + "distribution/ehcache-distributed3.xml");
222:                //Should not need to wait because the load is synchronous
223:                //Thread.sleep(10000);
224:                assertEquals(2000, manager3.getCache("sampleCache2").getSize());
225:
226:            }
227:
228:            /**
229:             * Create the same named cache in two CacheManagers. Populate the first one. Check that the second one gets the
230:             * entries.
231:             */
232:            public void testAddCacheAndBootstrapOccurs()
233:                    throws InterruptedException {
234:
235:                manager1.addCache("testBootstrap1");
236:                Cache testBootstrap1 = manager1.getCache("testBootstrap1");
237:                for (int i = 0; i < 1000; i++) {
238:                    testBootstrap1.put(new Element("key" + i, new Date()));
239:                }
240:
241:                manager2.addCache("testBootstrap1");
242:                Cache testBootstrap2 = manager2.getCache("testBootstrap1");
243:                //wait for async bootstrap
244:                Thread.sleep(3000);
245:                assertEquals(1000, testBootstrap2.getSize());
246:
247:            }
248:
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.