Source Code Cross Referenced for TestCall.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » continuations » 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 Framework » rife 1.6.1 » com.uwyn.rife.continuations 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestCall.java 3810 2007-06-25 13:36:58Z gbevin $
007:         */
008:        package com.uwyn.rife.continuations;
009:
010:        import com.uwyn.rife.tools.ExceptionUtils;
011:        import java.lang.reflect.Method;
012:        import junit.framework.TestCase;
013:
014:        public class TestCall extends TestCase {
015:            public TestCall(String name) {
016:                super (name);
017:            }
018:
019:            public void testSimpleCall() throws Throwable {
020:                for (String testclass : new String[] { "$SimpleCallSource",
021:                        "$SimpleCallSourceInterface" }) {
022:                    ContinuableRunnerTest runner = new ContinuableRunnerTest();
023:
024:                    String id1 = runner.start(TestCall.class.getName()
025:                            + testclass);
026:                    assertNull(id1);
027:                    ContinuableObject continuable = runner
028:                            .getCurrentContinuable();
029:                    assertNotNull(continuable);
030:                    Method method_getresult = continuable.getClass().getMethod(
031:                            "getResult", new Class[0]);
032:                    assertEquals(
033:                            "before call\nduring call target 1\nduring call target 2\nafter call",
034:                            method_getresult.invoke(continuable, new Object[0]));
035:                }
036:            }
037:
038:            public void testAnswerInOtherThread() throws Throwable {
039:                for (final String testclass : new String[] {
040:                        "$AnswerInOtherThreadCallSource",
041:                        "$AnswerInOtherThreadCallSourceInterface" }) {
042:                    final ContinuableRunnerTest runner = new ContinuableRunnerTest();
043:                    final ContinuableObject[] continuables = new ContinuableObject[2];
044:                    final String[] ids = new String[2];
045:
046:                    Thread thread1 = new Thread() {
047:                        public void run() {
048:                            try {
049:                                String id = runner.start(TestCall.class
050:                                        .getName()
051:                                        + testclass);
052:                                assertNull(id);
053:                                ids[0] = ContinuationContext.getLastContext()
054:                                        .getId();
055:                                continuables[0] = ContinuationContext
056:                                        .getLastContext().getContinuable();
057:                                assertNotNull(continuables[0]);
058:                                Method method_setdoanswer = continuables[0]
059:                                        .getClass().getMethod("setDoAnswer",
060:                                                new Class[] { boolean.class });
061:                                method_setdoanswer.invoke(continuables[0],
062:                                        new Object[] { true });
063:                            } catch (Throwable e) {
064:                                fail(ExceptionUtils.getExceptionStackTrace(e));
065:                            } finally {
066:                                synchronized (this ) {
067:                                    this .notifyAll();
068:                                }
069:                            }
070:                        }
071:                    };
072:
073:                    Thread thread2 = new Thread() {
074:                        public void run() {
075:                            try {
076:                                String id = runner.run(ids[0]);
077:                                assertNull(id);
078:                                continuables[1] = runner
079:                                        .getCurrentContinuable();
080:                                assertNotNull(continuables[1]);
081:                                Method method_getresult = continuables[1]
082:                                        .getClass().getMethod("getResult",
083:                                                new Class[0]);
084:                                assertEquals("before call\ntrue\nafter call",
085:                                        method_getresult.invoke(
086:                                                continuables[1], new Object[0]));
087:                            } catch (Throwable e) {
088:                                fail(ExceptionUtils.getExceptionStackTrace(e));
089:                            } finally {
090:                                synchronized (this ) {
091:                                    this .notifyAll();
092:                                }
093:                            }
094:                        }
095:                    };
096:
097:                    thread1.start();
098:                    while (thread1.isAlive()) {
099:                        synchronized (thread1) {
100:                            thread1.wait();
101:                        }
102:                    }
103:
104:                    thread2.start();
105:                    while (thread2.isAlive()) {
106:                        synchronized (thread2) {
107:                            thread2.wait();
108:                        }
109:                    }
110:                }
111:            }
112:
113:            // classes for testSimpleCall
114:            public static class SimpleCallSource extends
115:                    AbstractContinuableObject {
116:                private StringBuilder mResult;
117:
118:                public void execute() {
119:                    mResult = new StringBuilder("before call\n");
120:                    String answer = (String) call(SimpleCallTarget1.class);
121:                    mResult.append(answer);
122:                    mResult.append("after call");
123:                }
124:
125:                public String getResult() {
126:                    return mResult.toString();
127:                }
128:            }
129:
130:            public static class SimpleCallTarget1 extends
131:                    AbstractContinuableObject {
132:                public void execute() {
133:                    String answer = "during call target 1\n"
134:                            + call(SimpleCallTarget2.class);
135:                    answer(answer);
136:                }
137:            }
138:
139:            public static class SimpleCallTarget2 extends
140:                    AbstractContinuableObject {
141:                public void execute() {
142:                    String answer = "during call target 2\n";
143:                    answer(answer);
144:                }
145:            }
146:
147:            public static class SimpleCallSourceInterface implements 
148:                    ContinuableObject, ContinuableSupportAware {
149:                private ContinuableSupport mSupport;
150:
151:                public void setContinuableSupport(ContinuableSupport support) {
152:                    mSupport = support;
153:                }
154:
155:                public Object clone() throws CloneNotSupportedException {
156:                    return super .clone();
157:                }
158:
159:                private StringBuilder mResult;
160:
161:                public void execute() {
162:                    mResult = new StringBuilder("before call\n");
163:                    String answer = (String) mSupport
164:                            .call(SimpleCallTarget1Interface.class);
165:                    mResult.append(answer);
166:                    mResult.append("after call");
167:                }
168:
169:                public String getResult() {
170:                    return mResult.toString();
171:                }
172:            }
173:
174:            public static class SimpleCallTarget1Interface implements 
175:                    ContinuableObject, ContinuableSupportAware {
176:                private ContinuableSupport mSupport;
177:
178:                public void setContinuableSupport(ContinuableSupport support) {
179:                    mSupport = support;
180:                }
181:
182:                public Object clone() throws CloneNotSupportedException {
183:                    return super .clone();
184:                }
185:
186:                public void execute() {
187:                    String answer = "during call target 1\n"
188:                            + mSupport.call(SimpleCallTarget2Interface.class);
189:                    mSupport.answer(answer);
190:                }
191:            }
192:
193:            public static class SimpleCallTarget2Interface implements 
194:                    ContinuableObject, ContinuableSupportAware {
195:                private ContinuableSupport mSupport;
196:
197:                public void setContinuableSupport(ContinuableSupport support) {
198:                    mSupport = support;
199:                }
200:
201:                public Object clone() throws CloneNotSupportedException {
202:                    return super .clone();
203:                }
204:
205:                public void execute() {
206:                    String answer = "during call target 2\n";
207:                    mSupport.answer(answer);
208:                }
209:            }
210:
211:            // classes for testAnswerInOtherThread
212:            public static class AnswerInOtherThreadCallSource extends
213:                    AbstractContinuableObject {
214:                private StringBuilder mResult;
215:
216:                public void execute() {
217:                    mResult = new StringBuilder("before call\n");
218:                    Boolean answer = (Boolean) call(AnswerInOtherThreadCallTarget.class);
219:                    mResult.append(answer);
220:                    mResult.append("\nafter call");
221:                }
222:
223:                public String getResult() {
224:                    return mResult.toString();
225:                }
226:            }
227:
228:            public static class AnswerInOtherThreadCallTarget extends
229:                    AbstractContinuableObject {
230:                private boolean mDoAnswer = false;
231:
232:                public void setDoAnswer(boolean doAnswer) {
233:                    mDoAnswer = doAnswer;
234:                }
235:
236:                public void execute() {
237:                    if (mDoAnswer) {
238:                        answer(true);
239:                    }
240:                }
241:            }
242:
243:            public static class AnswerInOtherThreadCallSourceInterface
244:                    implements  ContinuableObject, ContinuableSupportAware {
245:                private ContinuableSupport mSupport;
246:
247:                public void setContinuableSupport(ContinuableSupport support) {
248:                    mSupport = support;
249:                }
250:
251:                public Object clone() throws CloneNotSupportedException {
252:                    return super .clone();
253:                }
254:
255:                private StringBuilder mResult;
256:
257:                public void execute() {
258:                    mResult = new StringBuilder("before call\n");
259:                    Boolean answer = (Boolean) mSupport
260:                            .call(AnswerInOtherThreadCallTargetInterface.class);
261:                    mResult.append(answer);
262:                    mResult.append("\nafter call");
263:                }
264:
265:                public String getResult() {
266:                    return mResult.toString();
267:                }
268:            }
269:
270:            public static class AnswerInOtherThreadCallTargetInterface
271:                    implements  ContinuableObject, ContinuableSupportAware {
272:                private ContinuableSupport mSupport;
273:
274:                public void setContinuableSupport(ContinuableSupport support) {
275:                    mSupport = support;
276:                }
277:
278:                public Object clone() throws CloneNotSupportedException {
279:                    return super .clone();
280:                }
281:
282:                private boolean mDoAnswer = false;
283:
284:                public void setDoAnswer(boolean doAnswer) {
285:                    mDoAnswer = doAnswer;
286:                }
287:
288:                public void execute() {
289:                    if (mDoAnswer) {
290:                        mSupport.answer(true);
291:                    }
292:                }
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.