Source Code Cross Referenced for RMICacheManagerPeerTest.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.CacheManager;
021:        import net.sf.ehcache.Ehcache;
022:        import net.sf.ehcache.Element;
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:
026:        import java.net.SocketTimeoutException;
027:        import java.rmi.RemoteException;
028:        import java.rmi.UnmarshalException;
029:        import java.util.ArrayList;
030:        import java.util.Date;
031:        import java.util.List;
032:
033:        /**
034:         * Unit tests for RMICachePeer
035:         *
036:         * Note these tests need a live network interface running in multicast mode to work
037:         *
038:         * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
039:         * @version $Id: RMICacheManagerPeerTest.java 519 2007-07-27 07:11:45Z gregluck $
040:         */
041:        public class RMICacheManagerPeerTest extends TestCase {
042:
043:            private static final Log LOG = LogFactory
044:                    .getLog(RMICacheManagerPeerTest.class.getName());
045:
046:            /**
047:             * manager
048:             */
049:            protected CacheManager manager;
050:            private String hostName = "localhost";
051:            private Integer port = new Integer(40000);
052:            private RMICacheManagerPeerListener peerListener;
053:            private Cache cache;
054:
055:            /**
056:             * {@inheritDoc}
057:             *
058:             * @throws Exception
059:             */
060:            protected void setUp() throws Exception {
061:                manager = CacheManager.create(AbstractCacheTest.TEST_CONFIG_DIR
062:                        + "ehcache.xml");
063:                cache = new Cache("test", 10, false, false, 10, 10);
064:
065:                peerListener = new RMICacheManagerPeerListener(hostName, port,
066:                        manager, new Integer(2000));
067:            }
068:
069:            /**
070:             * Shutdown the cache
071:             */
072:            protected void tearDown() throws InterruptedException {
073:                Thread.sleep(20);
074:                if (peerListener != null) {
075:                    peerListener.dispose();
076:                }
077:                manager.shutdown();
078:            }
079:
080:            /**
081:             * Can we create the peer?
082:             */
083:            public void testCreatePeer() throws RemoteException {
084:                for (int i = 0; i < 10; i++) {
085:                    new RMICachePeer(cache, hostName, port, new Integer(2000));
086:                }
087:            }
088:
089:            /**
090:             * See if socket.setSoTimeout(socketTimeoutMillis) works. Should throw a SocketTimeoutException
091:             *
092:             * @throws RemoteException
093:             */
094:            public void testFailsIfTimeoutExceeded() throws Exception {
095:
096:                RMICachePeer rmiCachePeer = new SlowRMICachePeer(cache,
097:                        hostName, port, new Integer(1000));
098:                peerListener.addCachePeer(cache.getName(), rmiCachePeer);
099:                peerListener.init();
100:
101:                try {
102:                    CachePeer cachePeer = new ManualRMICacheManagerPeerProvider()
103:                            .lookupRemoteCachePeer(rmiCachePeer.getUrl());
104:                    cachePeer.put(new Element("1", new Date()));
105:                    fail();
106:                } catch (UnmarshalException e) {
107:                    assertEquals(SocketTimeoutException.class, e.getCause()
108:                            .getClass());
109:                }
110:            }
111:
112:            /**
113:             * See if socket.setSoTimeout(socketTimeoutMillis) works.
114:             * Should not fail because the put takes less than the timeout.
115:             *
116:             * @throws RemoteException
117:             */
118:            public void testWorksIfTimeoutNotExceeded() throws Exception {
119:
120:                cache = new Cache("test", 10, false, false, 10, 10);
121:                RMICachePeer rmiCachePeer = new SlowRMICachePeer(cache,
122:                        hostName, port, new Integer(2100));
123:
124:                peerListener.addCachePeer(cache.getName(), rmiCachePeer);
125:                peerListener.init();
126:
127:                CachePeer cachePeer = new ManualRMICacheManagerPeerProvider()
128:                        .lookupRemoteCachePeer(rmiCachePeer.getUrl());
129:                cachePeer.put(new Element("1", new Date()));
130:            }
131:
132:            /**
133:             * Test send.
134:             * <p/>
135:             * This is a unit test because it was throwing AbstractMethodError if a method has changed signature,
136:             * or NoSuchMethodError is a new one is added. The problem is that rmic needs
137:             * to recompile the stub after any changes are made to the CachePeer source, something done by ant
138:             * compile but not by the IDE.
139:             */
140:            public void testSend() throws Exception {
141:
142:                cache = new Cache("test", 10, false, false, 10, 10);
143:                RMICachePeer rmiCachePeer = new RMICachePeer(cache, hostName,
144:                        port, new Integer(2100));
145:                manager.addCache(cache);
146:
147:                peerListener.addCachePeer(cache.getName(), rmiCachePeer);
148:                peerListener.init();
149:
150:                CachePeer cachePeer = new ManualRMICacheManagerPeerProvider()
151:                        .lookupRemoteCachePeer(rmiCachePeer.getUrl());
152:                Element element = new Element("1", new Date());
153:                EventMessage eventMessage = new EventMessage(EventMessage.PUT,
154:                        null, element);
155:                List eventMessages = new ArrayList();
156:                eventMessages.add(eventMessage);
157:                cachePeer.send(eventMessages);
158:            }
159:
160:            /**
161:             * RMICachePeer that breaks in lots of interesting ways.
162:             */
163:            class SlowRMICachePeer extends RMICachePeer {
164:
165:                /**
166:                 * Constructor
167:                 * @param cache
168:                 * @param hostName
169:                 * @param port
170:                 * @param socketTimeoutMillis
171:                 * @throws RemoteException
172:                 */
173:                public SlowRMICachePeer(Ehcache cache, String hostName,
174:                        Integer port, Integer socketTimeoutMillis)
175:                        throws RemoteException {
176:                    super (cache, hostName, port, socketTimeoutMillis);
177:                }
178:
179:                /**
180:                 * Puts an Element into the underlying cache without notifying listeners or updating statistics.
181:                 *
182:                 * @param element
183:                 * @throws java.rmi.RemoteException
184:                 * @throws IllegalArgumentException
185:                 * @throws IllegalStateException
186:                 */
187:                public void put(Element element) throws RemoteException,
188:                        IllegalArgumentException, IllegalStateException {
189:                    try {
190:                        Thread.sleep(2000);
191:                    } catch (InterruptedException exception) {
192:                        LOG.debug(exception.getMessage(), exception);
193:                    }
194:                }
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.