Source Code Cross Referenced for ContainerTest.java in  » Net » Terracotta » com » tc » simulator » container » 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 » Net » Terracotta » com.tc.simulator.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.simulator.container;
005:
006:        import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
007:
008:        import com.tc.simulator.app.Application;
009:        import com.tc.simulator.app.ApplicationBuilder;
010:        import com.tc.simulator.app.ApplicationInstantiationException;
011:        import com.tc.simulator.app.ErrorContext;
012:        import com.tc.simulator.app.MockApplication;
013:        import com.tc.simulator.control.MockControl;
014:        import com.tc.simulator.listener.ListenerProvider;
015:        import com.tc.simulator.listener.MockResultsListener;
016:        import com.tcsimulator.container.ContainerStateFactoryObject;
017:        import com.tctest.runner.TestGlobalIdGenerator;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import junit.framework.TestCase;
023:
024:        public class ContainerTest extends TestCase {
025:            private Container container;
026:            private MockContainerConfig config;
027:            private ContainerStateFactory containerStateFactory;
028:            private TestGlobalIdGenerator globalIdGenerator;
029:            private MockControl control;
030:            private MockApplicationBuilder applicationBuilder;
031:            private MockResultsListener resultsListener;
032:
033:            protected void setUp() throws Exception {
034:                super .setUp();
035:
036:                this .config = new MockContainerConfig();
037:                this .config.containerStartTimeout = 10 * 1000;
038:                this .config.applicationStartTimeout = 10 * 1000;
039:                this .config.applicationExecutionTimeout = 10 * 1000;
040:                this .config.instanceCount = 10;
041:
042:                this .containerStateFactory = new ContainerStateFactoryObject(
043:                        new LinkedQueue());
044:                this .globalIdGenerator = new TestGlobalIdGenerator();
045:                this .control = new MockControl();
046:                this .resultsListener = new MockResultsListener();
047:                this .applicationBuilder = new MockApplicationBuilder();
048:                this .applicationBuilder.result = true;
049:                this .container = new Container(this .config,
050:                        this .containerStateFactory, this .globalIdGenerator,
051:                        this .control, this .resultsListener,
052:                        this .applicationBuilder);
053:            }
054:
055:            protected void tearDown() throws Exception {
056:                super .tearDown();
057:                assertNotifyCompleteCalled();
058:            }
059:
060:            public void testInvalidContainerStartTimeout() throws Exception {
061:                this .config.containerStartTimeout = 0;
062:                this .container.run();
063:                assertResult(false);
064:                assertContainerConfigException(ContainerConfigException.INVALID_CONTAINER_START_TIMEOUT);
065:
066:            }
067:
068:            public void testInvalidApplicationStartTimeout() throws Exception {
069:                this .config.applicationStartTimeout = 0;
070:                this .container.run();
071:                assertResult(false);
072:                assertContainerConfigException(ContainerConfigException.INVALID_APPLICATION_START_TIMEOUT);
073:            }
074:
075:            public void testInvalidApplicationExecutionTimeout()
076:                    throws Exception {
077:                this .config.applicationExecutionTimeout = 0;
078:                this .container.run();
079:                assertResult(false);
080:                assertContainerConfigException(ContainerConfigException.INVALID_APPLICATION_EXECUTION_TIMEOUT);
081:            }
082:
083:            public void testApplicationInvalidInstanceCount() throws Exception {
084:                this .config.instanceCount = 0;
085:                this .container.run();
086:                assertResult(false);
087:                assertContainerConfigException(ContainerConfigException.INVALID_APPLICATION_INSTANCE_COUNT);
088:            }
089:
090:            public void testExecutionTimeout() throws Exception {
091:                this .config.applicationExecutionTimeout = 500;
092:                this .applicationBuilder.waitInterval = 2000;
093:
094:                this .container.run();
095:
096:                assertTrue(resultsListener.notifyExecutionTimeoutCalled);
097:                assertFalse(resultsListener.notifyStartTimeoutCalled);
098:                assertTrue(control.notifyCompleteCalled);
099:                assertResult(false);
100:            }
101:
102:            public void testAppBuilderThrowsException() throws Exception {
103:                this .applicationBuilder.throwException = true;
104:                this .applicationBuilder.exception = new ApplicationInstantiationException(
105:                        new RuntimeException());
106:
107:                this .container.run();
108:
109:                assertResult(false);
110:                assertSame(this .applicationBuilder.exception, extractError());
111:            }
112:
113:            public void testNormalRun() throws Exception {
114:                this .config.dumpErrors = true;
115:                this .config.dumpOutput = true;
116:                this .container.run();
117:                assertResult(true);
118:                ContainerResult result = extractResult();
119:                assertEquals(config.getApplicationInstanceCount(), result
120:                        .getApplicationInstanceCount());
121:            }
122:
123:            private void assertContainerConfigException(
124:                    ContainerConfigException.Reason reason) {
125:                assertEquals(1, this .resultsListener.errors.size());
126:                ErrorContext err = (ErrorContext) this .resultsListener.errors
127:                        .get(0);
128:                assertTrue(err.getThrowable() instanceof  ContainerConfigException);
129:                ContainerConfigException e = (ContainerConfigException) err
130:                        .getThrowable();
131:                assertSame(reason, e.getReason());
132:            }
133:
134:            private void assertNotifyCompleteCalled() throws Exception {
135:                assertTrue(this .control.notifyCompleteCalled);
136:            }
137:
138:            private void assertResult(boolean b) throws Exception {
139:                ContainerResult result = extractResult();
140:                assertNotNull(result);
141:                assertEquals(b, result.success());
142:            }
143:
144:            private ContainerResult extractResult() throws Exception {
145:                return (ContainerResult) this .resultsListener.result;
146:            }
147:
148:            private Throwable extractError() throws Exception {
149:                assertEquals(1, this .resultsListener.errors.size());
150:                ErrorContext err = (ErrorContext) this .resultsListener.errors
151:                        .get(0);
152:                return err.getThrowable();
153:            }
154:
155:            static class MockApplicationBuilder implements  ApplicationBuilder {
156:                public List applications = new ArrayList();
157:                public boolean throwException;
158:                public ApplicationInstantiationException exception;
159:                public long waitInterval;
160:                public boolean result;
161:
162:                public synchronized Application newApplication(String appId,
163:                        ListenerProvider listenerProvider)
164:                        throws ApplicationInstantiationException {
165:
166:                    if (this .throwException)
167:                        throw exception;
168:
169:                    MockApplication rv = new MockApplication();
170:                    rv.waitInterval = this .waitInterval;
171:                    rv.result = result;
172:                    applications.add(rv);
173:                    return rv;
174:                }
175:
176:                public ClassLoader getContextClassLoader() {
177:                    return getClass().getClassLoader();
178:                }
179:
180:                public void setAppConfigAttribute(String key, String value) {
181:                    throw new AssertionError(
182:                            "This method needs to be implemented");
183:                }
184:
185:            }
186:
187:            public class MockContainerConfig implements  ContainerConfig {
188:                public int instanceCount;
189:                public long containerStartTimeout;
190:                public long applicationStartTimeout;
191:                public long applicationExecutionTimeout;
192:                public boolean dumpErrors;
193:                public boolean dumpOutput;
194:                public boolean aggregate;
195:                public boolean stream;
196:                public boolean isMaster;
197:
198:                public int getApplicationInstanceCount() {
199:                    return this .instanceCount;
200:                }
201:
202:                public long getContainerStartTimeout() {
203:                    return this .containerStartTimeout;
204:                }
205:
206:                public long getApplicationStartTimeout() {
207:                    return this .applicationStartTimeout;
208:                }
209:
210:                public long getApplicationExecutionTimeout() {
211:                    return this .applicationExecutionTimeout;
212:                }
213:
214:                public boolean dumpErrors() {
215:                    return this .dumpErrors;
216:                }
217:
218:                public boolean dumpOutput() {
219:                    return this .dumpOutput;
220:                }
221:
222:                public boolean aggregate() {
223:                    return this .aggregate;
224:                }
225:
226:                public boolean stream() {
227:                    return this .stream;
228:                }
229:
230:                public boolean isMaster() {
231:                    return this.isMaster;
232:                }
233:
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.