Source Code Cross Referenced for TestServiceUnitFramework.java in  » ESB » open-esb » com » sun » jbi » framework » 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 » ESB » open esb » com.sun.jbi.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestServiceUnitFramework.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.framework;
030:
031:        import com.sun.jbi.ServiceUnitState;
032:        import com.sun.jbi.management.ComponentInstallationContext;
033:
034:        import java.util.ArrayList;
035:
036:        import javax.management.ObjectName;
037:
038:        /**
039:         * Tests for the ServiceUnitFramework.
040:         *
041:         * @author Sun Microsystems, Inc.
042:         */
043:        public class TestServiceUnitFramework extends junit.framework.TestCase {
044:            /**
045:             * Current test name.
046:             */
047:            private String mTestName;
048:
049:            /**
050:             * Current SRCROOT path.
051:             */
052:            private String mSrcroot;
053:
054:            /**
055:             * Helper class to setup environment for testing.
056:             */
057:            private EnvironmentSetup mSetup;
058:
059:            /**
060:             * Instance of the EnvironmentContext class.
061:             */
062:            private EnvironmentContext mContext;
063:
064:            /**
065:             * Local instance of Component.
066:             */
067:            private Component mComponent;
068:
069:            /**
070:             * Local instance of the ComponentInstallationContext class.
071:             */
072:            private ComponentInstallationContext mInstallContext;
073:
074:            /**
075:             * Instance of the ComponentFramework class.
076:             */
077:            private ComponentFramework mCompFW;
078:
079:            /**
080:             * Local instance of the ComponentRegistry class.
081:             */
082:            private ComponentRegistry mCompReg;
083:
084:            /**
085:             * Local instance of the ServiceUnitFramework class.
086:             */
087:            private ServiceUnitFramework mSuFW;
088:
089:            /**
090:             * The constructor for this testcase, forwards the test name to
091:             * the jUnit TestCase base class.
092:             * @param aTestName String with the name of this test.
093:             */
094:            public TestServiceUnitFramework(String aTestName) {
095:                super (aTestName);
096:                mTestName = aTestName;
097:            }
098:
099:            /**
100:             * Setup for the test. This creates the ComponentRegistry instance
101:             * and other objects needed for the tests.
102:             * @throws Exception when set up fails for any reason.
103:             */
104:            public void setUp() throws Exception {
105:                super .setUp();
106:                System.err.println("***** START of test " + mTestName);
107:                mSrcroot = System.getProperty("junit.srcroot") + "/";
108:
109:                // Create and initialize the EnvironmentContext. Create, initialize,
110:                // and start up the Component Registry and Framework.
111:
112:                mSetup = new EnvironmentSetup();
113:                mContext = mSetup.getEnvironmentContext();
114:                System.err.println("Setting log level to "
115:                        + java.util.logging.Level.FINEST.toString()
116:                        + " for logger " + mContext.getLogger().getName());
117:                mContext.getLogger().setLevel(java.util.logging.Level.FINEST);
118:                System.err.println("Log level is now "
119:                        + mContext.getLogger().getLevel().toString()
120:                        + " for logger " + mContext.getLogger().getName());
121:                mSetup.startup(true, true);
122:                mCompReg = mContext.getComponentRegistry();
123:                mCompFW = mContext.getComponentFramework();
124:
125:                // Create component class path lists
126:
127:                ArrayList bootstrapClassPath = new ArrayList();
128:                bootstrapClassPath.add(mSrcroot
129:                        + Constants.BC_BOOTSTRAP_CLASS_PATH);
130:                ArrayList componentClassPath = new ArrayList();
131:                componentClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH);
132:
133:                // Create installation context
134:
135:                mInstallContext = new ComponentInstallationContext(
136:                        Constants.BC_NAME,
137:                        ComponentInstallationContext.BINDING,
138:                        Constants.BC_LIFECYCLE_CLASS_NAME, componentClassPath,
139:                        null);
140:                mInstallContext.setInstallRoot(mSrcroot);
141:                mInstallContext.setIsInstall(true);
142:
143:                // Install the test component
144:
145:                mCompFW.loadBootstrap(mInstallContext,
146:                        Constants.BC_BOOTSTRAP_CLASS_NAME, bootstrapClassPath,
147:                        null);
148:                mCompFW.installComponent(mInstallContext);
149:
150:                // Get the Component instance and start the component
151:
152:                mComponent = mCompReg.getComponent(Constants.BC_NAME);
153:                mCompFW.startComponent(mComponent);
154:
155:                // Create ServiceUnitFramework instance
156:
157:                mSuFW = new ServiceUnitFramework(mContext);
158:            }
159:
160:            /**
161:             * Cleanup for the test.
162:             * @throws Exception when tearDown fails for any reason.
163:             */
164:            public void tearDown() throws Exception {
165:                super .tearDown();
166:                mCompReg.unregisterComponent(Constants.BC_NAME);
167:                mSetup.shutdown(true, true);
168:                System.err.println("***** END of test " + mTestName);
169:            }
170:
171:            // =============================  test methods ================================
172:
173:            /**
174:             * Tests initializeServiceUnits with a good result.
175:             * @throws Exception if an unexpected error occurs.
176:             */
177:            public void testInitializeServiceUnitsGood() throws Exception {
178:                // Register an SU
179:                mCompReg
180:                        .registerServiceUnit(Constants.BC_NAME,
181:                                Constants.SA_NAME, Constants.SU_NAME,
182:                                Constants.SU_ROOT);
183:                ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
184:
185:                // Initialize the service unit
186:                su.setDesiredState(ServiceUnitState.STOPPED);
187:                mSuFW.initializeServiceUnits(mComponent);
188:                assertTrue("Failure initializing Service Unit, expected state "
189:                        + su.getStateAsString(ServiceUnitState.STOPPED)
190:                        + " but state is " + su.getStateAsString(), su
191:                        .isStopped());
192:            }
193:
194:            /**
195:             * Tests initializeServiceUnits with an exception thrown by the component's
196:             * Service Unit manager.
197:             * @throws Exception if an unexpected error occurs.
198:             */
199:            public void testInitializeServiceUnitsException() throws Exception {
200:                // Register the SU
201:                mCompReg.registerServiceUnit(Constants.BC_NAME,
202:                        Constants.SA_NAME, Constants.SU_NAME_INIT_EXCEPTION,
203:                        Constants.SU_ROOT);
204:                ServiceUnit su = mComponent
205:                        .getServiceUnit(Constants.SU_NAME_INIT_EXCEPTION);
206:
207:                // Initialize the service unit
208:                su.setDesiredState(ServiceUnitState.STOPPED);
209:                mSuFW.initializeServiceUnits(mComponent);
210:                assertTrue(
211:                        "Service Unit initialized but should have thrown exception",
212:                        su.isShutdown());
213:            }
214:
215:            /**
216:             * Tests initializeServiceUnits with a timeout in the component's
217:             * Service Unit manager.
218:             * @throws Exception if an unexpected error occurs.
219:             */
220:            public void testInitializeServiceUnitsTimeout() throws Exception {
221:                // Register the SU
222:                mCompReg.registerServiceUnit(Constants.BC_NAME,
223:                        Constants.SA_NAME, Constants.SU_NAME_INIT_TIMEOUT,
224:                        Constants.SU_ROOT);
225:                ServiceUnit su = mComponent
226:                        .getServiceUnit(Constants.SU_NAME_INIT_TIMEOUT);
227:
228:                // Initialize the service unit
229:                su.setDesiredState(ServiceUnitState.STOPPED);
230:                mSuFW.initializeServiceUnits(mComponent);
231:                assertTrue(
232:                        "Service Unit initialized but should have timed out",
233:                        su.isShutdown());
234:            }
235:
236:            /**
237:             * Tests initializeServiceUnits with consecutive timeouts in the component's
238:             * Service Unit manager.
239:             * @throws Exception if an unexpected error occurs.
240:             */
241:            public void testInitializeServiceUnitsTimeoutLimit()
242:                    throws Exception {
243:                // This deploys 3 SUs that will timeout on their init calls plus one
244:                // SU that will not. The object is to make sure that after 3 consecutive
245:                // timeouts the remaining SUs are not initialized.
246:
247:                String suName;
248:
249:                // Register the first SU
250:                suName = Constants.SU_NAME_INIT_TIMEOUT + "_1";
251:                mCompReg.registerServiceUnit(Constants.BC_NAME,
252:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
253:                ServiceUnit su1 = mComponent.getServiceUnit(suName);
254:
255:                // Register the second SU
256:                suName = Constants.SU_NAME_INIT_TIMEOUT + "_2";
257:                mCompReg.registerServiceUnit(Constants.BC_NAME,
258:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
259:                ServiceUnit su2 = mComponent.getServiceUnit(suName);
260:
261:                // Register the third SU
262:                suName = Constants.SU_NAME_INIT_TIMEOUT + "_3";
263:                mCompReg.registerServiceUnit(Constants.BC_NAME,
264:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
265:                ServiceUnit su3 = mComponent.getServiceUnit(suName);
266:
267:                // Register the fourth SU
268:                suName = Constants.SU_NAME_FIRST;
269:                mCompReg.registerServiceUnit(Constants.BC_NAME,
270:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
271:                ServiceUnit su4 = mComponent.getServiceUnit(suName);
272:
273:                // Initialize the service units. The expected result is that the first
274:                // three will timeout, preventing the fourth from being initialized.
275:                su1.setDesiredState(ServiceUnitState.STOPPED);
276:                su2.setDesiredState(ServiceUnitState.STOPPED);
277:                su3.setDesiredState(ServiceUnitState.STOPPED);
278:                su4.setDesiredState(ServiceUnitState.STOPPED);
279:                mSuFW.initializeServiceUnits(mComponent);
280:                assertTrue("Service Unit " + su1.getName()
281:                        + " initialized but should have timed out", su1
282:                        .isShutdown());
283:                assertTrue("Service Unit " + su2.getName()
284:                        + " initialized but should have timed out", su2
285:                        .isShutdown());
286:                assertTrue("Service Unit " + su3.getName()
287:                        + " initialized but should have timed out", su3
288:                        .isShutdown());
289:                assertTrue("Service Unit " + su4.getName()
290:                        + " initialized but should have been skipped", su4
291:                        .isShutdown());
292:            }
293:
294:            /**
295:             * Tests startServiceUnits with a good result.
296:             * @throws Exception if an unexpected error occurs.
297:             */
298:            public void testStartServiceUnitsGood() throws Exception {
299:                // Register the SU
300:                mCompReg
301:                        .registerServiceUnit(Constants.BC_NAME,
302:                                Constants.SA_NAME, Constants.SU_NAME,
303:                                Constants.SU_ROOT);
304:                ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
305:
306:                // Set the service unit to initialized, and start it
307:                su.setStopped();
308:                su.setDesiredState(ServiceUnitState.STARTED);
309:                mSuFW.startServiceUnits(mComponent);
310:                assertTrue("Failure starting Service Unit, expected state "
311:                        + su.getStateAsString(ServiceUnitState.STARTED)
312:                        + " but state is " + su.getStateAsString(), su
313:                        .isStarted());
314:            }
315:
316:            /**
317:             * Tests startServiceUnits with an exception thrown by the component's
318:             * Service Unit manager.
319:             * @throws Exception if an unexpected error occurs.
320:             */
321:            public void testStartServiceUnitsException() throws Exception {
322:                // Register the SU
323:                mCompReg.registerServiceUnit(Constants.BC_NAME,
324:                        Constants.SA_NAME, Constants.SU_NAME_START_EXCEPTION,
325:                        Constants.SU_ROOT);
326:                ServiceUnit su = mComponent
327:                        .getServiceUnit(Constants.SU_NAME_START_EXCEPTION);
328:
329:                // Set the service unit to initialized, and start it. The start should
330:                // fail.
331:                su.setStopped();
332:                su.setDesiredState(ServiceUnitState.STARTED);
333:                mSuFW.startServiceUnits(mComponent);
334:                assertFalse(
335:                        "Service Unit started but should have thrown exception",
336:                        su.isStarted());
337:            }
338:
339:            /**
340:             * Tests startServiceUnits with a timeout in the component's
341:             * Service Unit manager.
342:             * @throws Exception if an unexpected error occurs.
343:             */
344:            public void testStartServiceUnitsTimeout() throws Exception {
345:                // Register the SU
346:                mCompReg.registerServiceUnit(Constants.BC_NAME,
347:                        Constants.SA_NAME, Constants.SU_NAME_START_TIMEOUT,
348:                        Constants.SU_ROOT);
349:                ServiceUnit su = mComponent
350:                        .getServiceUnit(Constants.SU_NAME_START_TIMEOUT);
351:
352:                // Set the service unit to initialized, and start it. The start should
353:                // fail.
354:                su.setStopped();
355:                su.setDesiredState(ServiceUnitState.STARTED);
356:                mSuFW.startServiceUnits(mComponent);
357:                assertFalse("Service Unit started but should have timed out",
358:                        su.isStarted());
359:            }
360:
361:            /**
362:             * Tests startServiceUnits with consecutive timeouts in the component's
363:             * Service Unit manager.
364:             * @throws Exception if an unexpected error occurs.
365:             */
366:            public void testStartServiceUnitsTimeoutLimit() throws Exception {
367:                // This deploys 3 SUs that will timeout on their start calls plus one
368:                // SU that will not. The object is to make sure that after 3 consecutive
369:                // timeouts the remaining SUs are not started.
370:
371:                String suName;
372:
373:                // Register the first SU
374:                suName = Constants.SU_NAME_START_TIMEOUT + "_1";
375:                mCompReg.registerServiceUnit(Constants.BC_NAME,
376:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
377:                ServiceUnit su1 = mComponent.getServiceUnit(suName);
378:
379:                // Register the second SU
380:                suName = Constants.SU_NAME_START_TIMEOUT + "_2";
381:                mCompReg.registerServiceUnit(Constants.BC_NAME,
382:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
383:                ServiceUnit su2 = mComponent.getServiceUnit(suName);
384:
385:                // Register the third SU
386:                suName = Constants.SU_NAME_START_TIMEOUT + "_3";
387:                mCompReg.registerServiceUnit(Constants.BC_NAME,
388:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
389:                ServiceUnit su3 = mComponent.getServiceUnit(suName);
390:
391:                // Register the fourth SU
392:                suName = Constants.SU_NAME_FIRST;
393:                mCompReg.registerServiceUnit(Constants.BC_NAME,
394:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
395:                ServiceUnit su4 = mComponent.getServiceUnit(suName);
396:
397:                // Set the service units to initialized.
398:                su1.setStopped();
399:                su1.setDesiredState(ServiceUnitState.STARTED);
400:                su2.setStopped();
401:                su2.setDesiredState(ServiceUnitState.STARTED);
402:                su3.setStopped();
403:                su3.setDesiredState(ServiceUnitState.STARTED);
404:                su4.setStopped();
405:                su4.setDesiredState(ServiceUnitState.STARTED);
406:
407:                // Start the service units. The expected result is that the first
408:                // three will timeout, preventing the fourth from being started.
409:                mSuFW.startServiceUnits(mComponent);
410:                assertFalse("Service Unit " + su1.getName()
411:                        + " started but should have timed out", su1.isStarted());
412:                assertFalse("Service Unit " + su2.getName()
413:                        + " started but should have timed out", su2.isStarted());
414:                assertFalse("Service Unit " + su3.getName()
415:                        + " started but should have timed out", su3.isStarted());
416:                assertFalse("Service Unit " + su4.getName()
417:                        + " started but should have been skipped", su4
418:                        .isStarted());
419:            }
420:
421:            /**
422:             * Tests stopServiceUnits with a good result.
423:             * @throws Exception if an unexpected error occurs.
424:             */
425:            public void testStopServiceUnitsGood() throws Exception {
426:                // Register the SU
427:                mCompReg
428:                        .registerServiceUnit(Constants.BC_NAME,
429:                                Constants.SA_NAME, Constants.SU_NAME,
430:                                Constants.SU_ROOT);
431:                ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
432:
433:                // Set the service unit to started, and stop it.
434:                su.setStopped();
435:                su.setStarted();
436:                su.setDesiredState(ServiceUnitState.STOPPED);
437:                mSuFW.stopServiceUnits(mComponent);
438:                assertTrue("Failure stopping Service Unit, expected state "
439:                        + su.getStateAsString(ServiceUnitState.STOPPED)
440:                        + " but state is " + su.getStateAsString(), su
441:                        .isStopped());
442:            }
443:
444:            /**
445:             * Tests stopServiceUnits with an exception thrown by the component's
446:             * Service Unit manager.
447:             * @throws Exception if an unexpected error occurs.
448:             */
449:            public void testStopServiceUnitsException() throws Exception {
450:                // Register the SU
451:                mCompReg.registerServiceUnit(Constants.BC_NAME,
452:                        Constants.SA_NAME, Constants.SU_NAME_STOP_EXCEPTION,
453:                        Constants.SU_ROOT);
454:                ServiceUnit su = mComponent
455:                        .getServiceUnit(Constants.SU_NAME_STOP_EXCEPTION);
456:
457:                // Set the service unit to started, and stop it. The stop should fail.
458:                su.setStopped();
459:                su.setStarted();
460:                su.setDesiredState(ServiceUnitState.STOPPED);
461:                mSuFW.stopServiceUnits(mComponent);
462:                assertFalse(
463:                        "Service Unit stopped but should have thrown exception",
464:                        su.isStopped());
465:            }
466:
467:            /**
468:             * Tests stopServiceUnits with a timeout in the component's
469:             * Service Unit manager.
470:             * @throws Exception if an unexpected error occurs.
471:             */
472:            public void testStopServiceUnitsTimeout() throws Exception {
473:                // Register the SU
474:                mCompReg.registerServiceUnit(Constants.BC_NAME,
475:                        Constants.SA_NAME, Constants.SU_NAME_STOP_TIMEOUT,
476:                        Constants.SU_ROOT);
477:                ServiceUnit su = mComponent
478:                        .getServiceUnit(Constants.SU_NAME_STOP_TIMEOUT);
479:
480:                // Set the service unit to started, and stop it. The stop should time
481:                // out.
482:                su.setStopped();
483:                su.setStarted();
484:                su.setDesiredState(ServiceUnitState.STOPPED);
485:                mSuFW.stopServiceUnits(mComponent);
486:                assertFalse("Service Unit stopped but should have timed out",
487:                        su.isStopped());
488:            }
489:
490:            /**
491:             * Tests stopServiceUnits with consecutive timeouts in the component's
492:             * Service Unit manager.
493:             * @throws Exception if an unexpected error occurs.
494:             */
495:            public void testStopServiceUnitsTimeoutLimit() throws Exception {
496:                // This deploys 3 SUs that will timeout on their stop calls plus one
497:                // SU that will not. The object is to make sure that after 3 consecutive
498:                // timeouts the remaining SUs are not stopped.
499:
500:                String suName;
501:
502:                // Register the first SU
503:                suName = Constants.SU_NAME_STOP_TIMEOUT + "_1";
504:                mCompReg.registerServiceUnit(Constants.BC_NAME,
505:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
506:                ServiceUnit su1 = mComponent.getServiceUnit(suName);
507:
508:                // Register the second SU
509:                suName = Constants.SU_NAME_STOP_TIMEOUT + "_2";
510:                mCompReg.registerServiceUnit(Constants.BC_NAME,
511:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
512:                ServiceUnit su2 = mComponent.getServiceUnit(suName);
513:
514:                // Register the third SU
515:                suName = Constants.SU_NAME_STOP_TIMEOUT + "_3";
516:                mCompReg.registerServiceUnit(Constants.BC_NAME,
517:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
518:                ServiceUnit su3 = mComponent.getServiceUnit(suName);
519:
520:                // Register the fourth SU
521:                suName = Constants.SU_NAME_FIRST;
522:                mCompReg.registerServiceUnit(Constants.BC_NAME,
523:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
524:                ServiceUnit su4 = mComponent.getServiceUnit(suName);
525:
526:                // Set the service units to started.
527:                su1.setStopped();
528:                su1.setStarted();
529:                su1.setDesiredState(ServiceUnitState.STOPPED);
530:                su2.setStopped();
531:                su2.setStarted();
532:                su2.setDesiredState(ServiceUnitState.STOPPED);
533:                su3.setStopped();
534:                su3.setStarted();
535:                su3.setDesiredState(ServiceUnitState.STOPPED);
536:                su4.setStopped();
537:                su4.setStarted();
538:                su4.setDesiredState(ServiceUnitState.STOPPED);
539:
540:                // Stop the service units. The expected result is that the first
541:                // three will timeout, preventing the fourth from being stopped.
542:                mSuFW.startServiceUnits(mComponent);
543:                assertFalse("Service Unit " + su1.getName()
544:                        + " stopped but should have timed out", su1.isStopped());
545:                assertFalse("Service Unit " + su2.getName()
546:                        + " stopped but should have timed out", su2.isStopped());
547:                assertFalse("Service Unit " + su3.getName()
548:                        + " stopped but should have timed out", su3.isStopped());
549:                assertFalse("Service Unit " + su4.getName()
550:                        + " stopped but should have been skipped", su4
551:                        .isStopped());
552:            }
553:
554:            /**
555:             * Tests shutDownServiceUnits with a good result.
556:             * @throws Exception if an unexpected error occurs.
557:             */
558:            public void testShutDownServiceUnitsGood() throws Exception {
559:                // Register the SU
560:                mCompReg
561:                        .registerServiceUnit(Constants.BC_NAME,
562:                                Constants.SA_NAME, Constants.SU_NAME,
563:                                Constants.SU_ROOT);
564:                ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
565:
566:                // Set the service unit to initialized and then shut it down.
567:                su.setStopped();
568:                su.setDesiredState(ServiceUnitState.SHUTDOWN);
569:                mSuFW.shutDownServiceUnits(mComponent);
570:                assertTrue(
571:                        "Failure shutting down Service Unit, expected state "
572:                                + su
573:                                        .getStateAsString(ServiceUnitState.SHUTDOWN)
574:                                + " but state is " + su.getStateAsString(), su
575:                                .isShutdown());
576:            }
577:
578:            /**
579:             * Tests shutDownServiceUnits with an exception thrown by the component's
580:             * Service Unit manager.
581:             * @throws Exception if an unexpected error occurs.
582:             */
583:            public void testShutDownServiceUnitsException() throws Exception {
584:                // Register the SU
585:                mCompReg
586:                        .registerServiceUnit(Constants.BC_NAME,
587:                                Constants.SA_NAME,
588:                                Constants.SU_NAME_SHUTDOWN_EXCEPTION,
589:                                Constants.SU_ROOT);
590:                ServiceUnit su = mComponent
591:                        .getServiceUnit(Constants.SU_NAME_SHUTDOWN_EXCEPTION);
592:
593:                // Set the service unit to initialized and then shut it down. The
594:                // shutdown should fail.
595:                su.setStopped();
596:                su.setDesiredState(ServiceUnitState.SHUTDOWN);
597:                mSuFW.shutDownServiceUnits(mComponent);
598:                assertFalse(
599:                        "Service Unit shut down but should have thrown exception",
600:                        su.isShutdown());
601:            }
602:
603:            /**
604:             * Tests shutDownServiceUnits with a timeout in the component's
605:             * Service Unit manager.
606:             * @throws Exception if an unexpected error occurs.
607:             */
608:            public void testShutDownServiceUnitsTimeout() throws Exception {
609:                // Register the SU
610:                mCompReg.registerServiceUnit(Constants.BC_NAME,
611:                        Constants.SA_NAME, Constants.SU_NAME_SHUTDOWN_TIMEOUT,
612:                        Constants.SU_ROOT);
613:                ServiceUnit su = mComponent
614:                        .getServiceUnit(Constants.SU_NAME_SHUTDOWN_TIMEOUT);
615:
616:                // Set the service unit to initialized and then shut it down. The
617:                // shutdown should time out. 
618:                su.setStopped();
619:                su.setDesiredState(ServiceUnitState.SHUTDOWN);
620:                mSuFW.shutDownServiceUnits(mComponent);
621:                assertFalse("Service Unit shut down but should have timed out",
622:                        su.isShutdown());
623:            }
624:
625:            /**
626:             * Tests shutDownServiceUnits with consecutive timeouts in the component's
627:             * Service Unit manager.
628:             * @throws Exception if an unexpected error occurs.
629:             */
630:            public void testShutDownServiceUnitsTimeoutLimit() throws Exception {
631:                // This deploys 3 SUs that will timeout on their shutDown calls plus one
632:                // SU that will not. The object is to make sure that after 3 consecutive
633:                // timeouts the remaining SUs are not shut down.
634:
635:                String suName;
636:
637:                // Register the first SU
638:                suName = Constants.SU_NAME_SHUTDOWN_TIMEOUT + "_1";
639:                mCompReg.registerServiceUnit(Constants.BC_NAME,
640:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
641:                ServiceUnit su1 = mComponent.getServiceUnit(suName);
642:
643:                // Register the second SU
644:                suName = Constants.SU_NAME_SHUTDOWN_TIMEOUT + "_2";
645:                mCompReg.registerServiceUnit(Constants.BC_NAME,
646:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
647:                ServiceUnit su2 = mComponent.getServiceUnit(suName);
648:
649:                // Register the third SU
650:                suName = Constants.SU_NAME_SHUTDOWN_TIMEOUT + "_3";
651:                mCompReg.registerServiceUnit(Constants.BC_NAME,
652:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
653:                ServiceUnit su3 = mComponent.getServiceUnit(suName);
654:
655:                // Register the fourth SU
656:                suName = Constants.SU_NAME_FIRST;
657:                mCompReg.registerServiceUnit(Constants.BC_NAME,
658:                        Constants.SA_NAME, suName, Constants.SU_ROOT);
659:                ServiceUnit su4 = mComponent.getServiceUnit(suName);
660:
661:                // Set the service units to initialized.
662:                su1.setStopped();
663:                su1.setDesiredState(ServiceUnitState.SHUTDOWN);
664:                su2.setStopped();
665:                su2.setDesiredState(ServiceUnitState.SHUTDOWN);
666:                su3.setStopped();
667:                su3.setDesiredState(ServiceUnitState.SHUTDOWN);
668:                su4.setStopped();
669:                su4.setDesiredState(ServiceUnitState.SHUTDOWN);
670:
671:                // Shut down the service units. The expected result is that the first
672:                // three will timeout, preventing the fourth from being shut down.
673:                mSuFW.shutDownServiceUnits(mComponent);
674:                assertFalse("Service Unit " + su1.getName()
675:                        + " shut down but should have timed out", su1
676:                        .isShutdown());
677:                assertFalse("Service Unit " + su2.getName()
678:                        + " shut down but should have timed out", su2
679:                        .isShutdown());
680:                assertFalse("Service Unit " + su3.getName()
681:                        + " shut down but should have timed out", su3
682:                        .isShutdown());
683:                assertFalse("Service Unit " + su4.getName()
684:                        + " shut down but should have been skipped", su4
685:                        .isShutdown());
686:            }
687:
688:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.