Source Code Cross Referenced for SocketServerImplTestCase.java in  » Web-Server » JicarillaHTTP » org » jicarilla » net » test » 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 » Web Server » JicarillaHTTP » org.jicarilla.net.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         The Jicarilla Software License
003:
004:         Copyright (c) 2003 Leo Simons.
005:         All rights reserved.
006:
007:         Permission is hereby granted, free of charge, to any person obtaining
008:         a copy of this software and associated documentation files (the
009:         "Software"), to deal in the Software without restriction, including
010:         without limitation the rights to use, copy, modify, merge, publish,
011:         distribute, sublicense, and/or sell copies of the Software, and to
012:         permit persons to whom the Software is furnished to do so, subject to
013:         the following conditions:
014:
015:         The above copyright notice and this permission notice shall be
016:         included in all copies or substantial portions of the Software.
017:
018:         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019:         EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020:         MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021:         IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022:         CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023:         TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024:         SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025:        ==================================================================== */
026:        package org.jicarilla.net.test;
027:
028:        import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
029:        import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
030:        import junit.framework.TestCase;
031:        import org.apache.commons.pool.BasePoolableObjectFactory;
032:        import org.apache.commons.pool.ObjectPool;
033:        import org.apache.commons.pool.impl.SoftReferenceObjectPool;
034:        import org.jicarilla.lang.ExceptionListener;
035:        import org.jicarilla.lang.NoopExceptionListener;
036:        import org.jicarilla.plumbing.Sink;
037:        import org.jicarilla.net.Event;
038:        import org.jicarilla.net.EventFactory;
039:        import org.jicarilla.net.SocketServerConfig;
040:        import org.jicarilla.net.SocketServerException;
041:        import org.jicarilla.net.SocketServerImpl;
042:
043:        import java.net.InetSocketAddress;
044:        import java.nio.ByteBuffer;
045:        import java.nio.channels.SocketChannel;
046:
047:        /**
048:         * <a href="http://www.junit.org/">JUnit</a>
049:         * {@link TestCase testcase} for
050:         * SocketServerImpl.
051:         *
052:         * @todo a lot more tests....
053:         *
054:         * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
055:         * @version $Id: SocketServerImplTestCase.java,v 1.7 2004/03/23 13:37:50 lsimons Exp $
056:         */
057:        public class SocketServerImplTestCase extends TestCase {
058:            public final static int port = 8088;
059:            public final static int backlog = 50;
060:            public final static int threads = 50;
061:            protected SocketServerConfig conf;
062:            protected ExceptionListener exceptionListener;
063:            protected ObjectPool eventPool;
064:            protected ObjectPool channelPool;
065:            protected Sink errorHandler;
066:            protected PooledExecutor threadPool;
067:
068:            public void setUp() throws Exception {
069:                conf = new SocketServerConfig("localhost", port, backlog,
070:                        threads);
071:                exceptionListener = new NoopExceptionListener();
072:                eventPool = new SoftReferenceObjectPool(new EventFactory());
073:                channelPool = new SoftReferenceObjectPool(
074:                        new BasePoolableObjectFactory() {
075:                            public Object makeObject() {
076:                                return new LinkedQueue();
077:                            }
078:                        });
079:                errorHandler = new Sink() {
080:                    public void put(final Object o) {
081:                        final Event e = (Event) o;
082:                        e.getChannel();
083:                    }
084:
085:                    public boolean offer(final Object o, final long l) {
086:                        return true;
087:                    }
088:                };
089:                threadPool = new PooledExecutor();
090:            }
091:
092:            public void tearDown() throws Exception {
093:            }
094:
095:            private final static int lifecycleSleepTime = 200;
096:
097:            public void testLifecycle() throws Throwable {
098:                final SocketServerImpl server = new SocketServerImpl(conf,
099:                        exceptionListener, eventPool, channelPool,
100:                        errorHandler, threadPool);
101:
102:                server.initialize();
103:                Thread.sleep(lifecycleSleepTime);
104:                server.dispose();
105:            }
106:
107:            /*protected class ErrorSink implements Sink
108:            {
109:                public SocketChannel s;
110:
111:                public void put( Object o ) throws InterruptedException
112:                {
113:                    Event e = (Event)o;
114:                    s = e.getChannel();
115:                }
116:
117:                public boolean offer( Object o, long l ) throws InterruptedException
118:                {
119:                    Event e = (Event)o;
120:                    s = e.getChannel();
121:                    return true;
122:                }
123:            }*/
124:            protected static class SavingQueue extends LinkedQueue {
125:                public static SocketChannel s;
126:                public static int received = 0;
127:
128:                public void put(final Object o) throws InterruptedException {
129:                    received++;
130:                    final Event e = (Event) o;
131:                    s = e.getChannel();
132:                }
133:
134:                public boolean offer(final Object o, final long l)
135:                        throws InterruptedException {
136:                    received++;
137:                    final Event e = (Event) o;
138:                    s = e.getChannel();
139:                    return true;
140:                }
141:            }
142:
143:            protected class SavingSocketServerImpl extends SocketServerImpl {
144:                protected SavingSocketServerImpl(final SocketServerConfig conf,
145:                        final ExceptionListener exceptionListener,
146:                        final ObjectPool eventPool,
147:                        final ObjectPool channelPool, final Sink errorHandler,
148:                        final PooledExecutor threadPool) throws Exception {
149:                    super (conf, exceptionListener, eventPool, channelPool,
150:                            errorHandler, threadPool);
151:                }
152:
153:                public SocketChannel s;
154:
155:                public void handleRequest(final SocketChannel c)
156:                        throws SocketServerException, InterruptedException {
157:                    s = c;
158:                    super .handleRequest(c);
159:                }
160:            }
161:
162:            public final static int sleepTime = 500;
163:
164:            public void testStageRecievesCorrectChannel() throws Throwable {
165:                //ErrorSink errorHander = new ErrorSink();
166:                channelPool = new SoftReferenceObjectPool(
167:                        new BasePoolableObjectFactory() {
168:                            public Object makeObject() {
169:                                return new SavingQueue();
170:                            }
171:                        });
172:                final SavingSocketServerImpl server = new SavingSocketServerImpl(
173:                        conf, exceptionListener, eventPool, channelPool,
174:                        errorHandler, threadPool);
175:
176:                server.initialize();
177:
178:                final SocketChannel sc = SocketChannel.open();
179:                sc.socket().connect(new InetSocketAddress("localhost", port));
180:                final char[] str = "Hi!".toCharArray();
181:                final ByteBuffer msg = ByteBuffer.allocate(str.length);
182:                for (int i = 0; i < str.length; i++)
183:                    msg.put((byte) str[i]);
184:                msg.rewind();
185:                sc.write(msg);
186:
187:                Thread.sleep(sleepTime);
188:
189:                server.handleRequest(sc);
190:
191:                Thread.sleep(sleepTime);
192:
193:                assertSame(sc, SavingQueue.s);
194:                assertEquals(2, SavingQueue.received);
195:
196:                SavingQueue.s = null;
197:                SavingQueue.received = 0;
198:
199:                server.dispose();
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.