Source Code Cross Referenced for DefaultRunnableManagerTestCase.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » thread » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.thread 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one or more
0003:         * contributor license agreements.  See the NOTICE file distributed with
0004:         * this work for additional information regarding copyright ownership.
0005:         * The ASF licenses this file to You under the Apache License, Version 2.0
0006:         * (the "License"); you may not use this file except in compliance with
0007:         * the License.  You may obtain a copy of the License at
0008:         *
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:        package org.apache.cocoon.components.thread;
0018:
0019:        import org.apache.avalon.framework.configuration.Configuration;
0020:        import org.apache.avalon.framework.configuration.ConfigurationException;
0021:        import org.apache.avalon.framework.logger.Logger;
0022:        import org.easymock.MockControl;
0023:
0024:        /**
0025:         * The $classType$ class ...
0026:         *
0027:         * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati </a>
0028:         * @version $Id$
0029:         */
0030:        public class DefaultRunnableManagerTestCase extends AbstractTestCase {
0031:            //~ Constructors -----------------------------------------------------------
0032:
0033:            /**
0034:             * Constructor for DefaultRunnableManagerTestCase.
0035:             *
0036:             * @param name
0037:             */
0038:            public DefaultRunnableManagerTestCase(String name) {
0039:                super (name);
0040:            }
0041:
0042:            //~ Methods ----------------------------------------------------------------
0043:
0044:            /**
0045:             * DOCUMENT ME!
0046:             *
0047:             * @throws Exception DOCUMENT ME!
0048:             */
0049:            public final void testConfigureDaemonPool() throws Exception {
0050:                final MockControl threadPoolConfigControl = createStrictControl(Configuration.class);
0051:                final Configuration threadPoolConfig = (Configuration) threadPoolConfigControl
0052:                        .getMock();
0053:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0054:                        .getChild("name"), createValueConfigMock("daemon"));
0055:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0056:                        .getChild("queue-size"), createIntegerConfigMock(
0057:                        2 * DefaultRunnableManager.DEFAULT_QUEUE_SIZE,
0058:                        DefaultRunnableManager.DEFAULT_QUEUE_SIZE));
0059:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0060:                        .getChild("max-pool-size"), createIntegerConfigMock(
0061:                        2 * DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE,
0062:                        DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE));
0063:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0064:                        .getChild("min-pool-size"), createIntegerConfigMock(
0065:                        DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE / 3,
0066:                        DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE));
0067:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0068:                        .getChild("priority"), createValueConfigMock("LOW",
0069:                        DefaultRunnableManager.DEFAULT_THREAD_PRIORITY));
0070:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0071:                        .getChild("daemon"), createBooleanConfigMock(false,
0072:                        DefaultRunnableManager.DEFAULT_DAEMON_MODE));
0073:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0074:                        .getChild("keep-alive-time-ms"), createLongConfigMock(
0075:                        DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME / 2,
0076:                        DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME));
0077:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0078:                        .getChild("block-policy"), createValueConfigMock(
0079:                        "WAIT", DefaultThreadPool.POLICY_DEFAULT));
0080:                threadPoolConfigControl
0081:                        .expectAndReturn(
0082:                                threadPoolConfig.getChild("shutdown-graceful"),
0083:                                createBooleanConfigMock(
0084:                                        true,
0085:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_GRACEFUL));
0086:                threadPoolConfigControl
0087:                        .expectAndReturn(
0088:                                threadPoolConfig
0089:                                        .getChild("shutdown-wait-time-ms"),
0090:                                createIntegerConfigMock(
0091:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME / 2,
0092:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME));
0093:                threadPoolConfigControl.replay();
0094:
0095:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0096:                final Configuration mainConfig = (Configuration) mainConfigControl
0097:                        .getMock();
0098:                mainConfigControl.expectAndReturn(mainConfig
0099:                        .getChild("thread-factory"), createValueConfigMock(
0100:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0101:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0102:                mainConfigControl.expectAndReturn(mainConfig
0103:                        .getChild("thread-pools"),
0104:                        createChildrenConfigMock("thread-pool",
0105:                                new Configuration[] { threadPoolConfig }));
0106:                mainConfigControl.replay();
0107:
0108:                final MockControl childLoggerDaemonControl = createStrictControl(Logger.class);
0109:                final Logger childLoggerDaemon = (Logger) childLoggerDaemonControl
0110:                        .getMock();
0111:                childLoggerDaemonControl.replay();
0112:
0113:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0114:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0115:                        .getMock();
0116:                childLoggerDefaultControl.replay();
0117:
0118:                final MockControl loggerControl = createStrictControl(Logger.class);
0119:                final Logger logger = (Logger) loggerControl.getMock();
0120:                logger
0121:                        .warn("Unknown thread priority \"LOW\". Set to \"NORM\".");
0122:                loggerControl.expectAndReturn(logger.getChildLogger("daemon"),
0123:                        childLoggerDaemon);
0124:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0125:                logger
0126:                        .info("ThreadPool named \"daemon\" created with maximum queue-size=2147483647,max-pool-size=10,min-pool-size=1,priority=5,isDaemon=false,keep-alive-time-ms=30000,block-policy=\"WAIT\",shutdown-wait-time-ms=0");
0127:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0128:                        childLoggerDefault);
0129:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0130:                logger
0131:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0132:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0133:                logger.debug("Disposing all thread pools");
0134:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0135:                logger.debug("Disposing thread pool daemon");
0136:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0137:                logger.debug("Thread pool daemon disposed");
0138:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0139:                logger.debug("Disposing thread pool default");
0140:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0141:                logger.debug("Thread pool default disposed");
0142:                loggerControl.replay();
0143:
0144:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0145:                runnableManager.enableLogging(logger);
0146:
0147:                try {
0148:                    runnableManager.configure(mainConfig);
0149:                } catch (final ConfigurationException ce) {
0150:                    assertTrue("Throw unexpected ConfigurationException", false);
0151:                }
0152:
0153:                runnableManager.dispose();
0154:                verify();
0155:            }
0156:
0157:            /**
0158:             * DOCUMENT ME!
0159:             */
0160:            public final void testConfigureMinimal() {
0161:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0162:                final Configuration mainConfig = (Configuration) mainConfigControl
0163:                        .getMock();
0164:                mainConfigControl.expectAndReturn(mainConfig
0165:                        .getChild("thread-factory"), createValueConfigMock(
0166:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0167:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0168:                mainConfigControl.expectAndReturn(mainConfig
0169:                        .getChild("thread-pools"), createChildrenConfigMock(
0170:                        "thread-pool", new Configuration[0]));
0171:                mainConfigControl.replay();
0172:
0173:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0174:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0175:                        .getMock();
0176:                childLoggerDefaultControl.replay();
0177:
0178:                final MockControl loggerControl = createStrictControl(Logger.class);
0179:                final Logger logger = (Logger) loggerControl.getMock();
0180:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0181:                        childLoggerDefault);
0182:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0183:                logger
0184:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0185:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0186:                logger.debug("Disposing all thread pools");
0187:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0188:                logger.debug("Disposing thread pool default");
0189:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0190:                logger.debug("Thread pool default disposed");
0191:                loggerControl.replay();
0192:
0193:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0194:                runnableManager.enableLogging(logger);
0195:
0196:                try {
0197:                    runnableManager.configure(mainConfig);
0198:                } catch (final ConfigurationException ce) {
0199:                    assertTrue("Throw unexpected ConfigurationException", false);
0200:                }
0201:
0202:                runnableManager.dispose();
0203:                verify();
0204:            }
0205:
0206:            /**
0207:             * DOCUMENT ME!
0208:             *
0209:             * @throws Exception DOCUMENT ME!
0210:             */
0211:            public final void testConfigureMyPool() throws Exception {
0212:                final MockControl threadPoolConfigControl = createStrictControl(Configuration.class);
0213:                final Configuration threadPoolConfig = (Configuration) threadPoolConfigControl
0214:                        .getMock();
0215:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0216:                        .getChild("name"), createValueConfigMock("mypool"));
0217:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0218:                        .getChild("queue-size"), createIntegerConfigMock(
0219:                        2 * DefaultRunnableManager.DEFAULT_QUEUE_SIZE,
0220:                        DefaultRunnableManager.DEFAULT_QUEUE_SIZE));
0221:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0222:                        .getChild("max-pool-size"), createIntegerConfigMock(
0223:                        2 * DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE,
0224:                        DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE));
0225:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0226:                        .getChild("min-pool-size"), createIntegerConfigMock(
0227:                        DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE / 3,
0228:                        DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE));
0229:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0230:                        .getChild("priority"), createValueConfigMock("MIN",
0231:                        DefaultRunnableManager.DEFAULT_THREAD_PRIORITY));
0232:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0233:                        .getChild("daemon"), createBooleanConfigMock(false,
0234:                        DefaultRunnableManager.DEFAULT_DAEMON_MODE));
0235:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0236:                        .getChild("keep-alive-time-ms"), createLongConfigMock(
0237:                        DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME / 2,
0238:                        DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME));
0239:                threadPoolConfigControl.expectAndReturn(threadPoolConfig
0240:                        .getChild("block-policy"), createValueConfigMock(
0241:                        "WAIT", DefaultThreadPool.POLICY_DEFAULT));
0242:                threadPoolConfigControl
0243:                        .expectAndReturn(
0244:                                threadPoolConfig.getChild("shutdown-graceful"),
0245:                                createBooleanConfigMock(
0246:                                        true,
0247:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_GRACEFUL));
0248:                threadPoolConfigControl
0249:                        .expectAndReturn(
0250:                                threadPoolConfig
0251:                                        .getChild("shutdown-wait-time-ms"),
0252:                                createIntegerConfigMock(
0253:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME / 2,
0254:                                        DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME));
0255:                threadPoolConfigControl.replay();
0256:
0257:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0258:                final Configuration mainConfig = (Configuration) mainConfigControl
0259:                        .getMock();
0260:                mainConfigControl.expectAndReturn(mainConfig
0261:                        .getChild("thread-factory"), createValueConfigMock(
0262:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0263:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0264:                mainConfigControl.expectAndReturn(mainConfig
0265:                        .getChild("thread-pools"),
0266:                        createChildrenConfigMock("thread-pool",
0267:                                new Configuration[] { threadPoolConfig }));
0268:                mainConfigControl.replay();
0269:
0270:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0271:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0272:                        .getMock();
0273:                childLoggerDefaultControl.replay();
0274:
0275:                final MockControl childLoggerMyPoolControl = createStrictControl(Logger.class);
0276:                final Logger childLoggerMyPool = (Logger) childLoggerMyPoolControl
0277:                        .getMock();
0278:                childLoggerMyPoolControl.replay();
0279:
0280:                final MockControl loggerControl = createStrictControl(Logger.class);
0281:                final Logger logger = (Logger) loggerControl.getMock();
0282:                loggerControl.expectAndReturn(logger.getChildLogger("mypool"),
0283:                        childLoggerMyPool);
0284:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0285:                logger
0286:                        .info("ThreadPool named \"mypool\" created with maximum queue-size=2147483647,max-pool-size=10,min-pool-size=1,priority=1,isDaemon=false,keep-alive-time-ms=30000,block-policy=\"WAIT\",shutdown-wait-time-ms=0");
0287:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0288:                        childLoggerDefault);
0289:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0290:                logger
0291:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0292:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0293:                logger.debug("Disposing all thread pools");
0294:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0295:                logger.debug("Disposing thread pool mypool");
0296:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0297:                logger.debug("Thread pool mypool disposed");
0298:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0299:                logger.debug("Disposing thread pool default");
0300:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0301:                logger.debug("Thread pool default disposed");
0302:                loggerControl.replay();
0303:
0304:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0305:                runnableManager.enableLogging(logger);
0306:
0307:                try {
0308:                    runnableManager.configure(mainConfig);
0309:                } catch (final ConfigurationException ce) {
0310:                    assertTrue("Throw unexpected ConfigurationException", false);
0311:                }
0312:
0313:                runnableManager.dispose();
0314:                verify();
0315:            }
0316:
0317:            /**
0318:             * Class under test for void createPool(String, int, int, int, int,
0319:             * boolean, long, String, boolean, int)
0320:             */
0321:            public final void testCreatePoolStringintintintintbooleanlongStringbooleanint() {
0322:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0323:                final Configuration mainConfig = (Configuration) mainConfigControl
0324:                        .getMock();
0325:                mainConfigControl.expectAndReturn(mainConfig
0326:                        .getChild("thread-factory"), createValueConfigMock(
0327:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0328:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0329:                mainConfigControl.expectAndReturn(mainConfig
0330:                        .getChild("thread-pools"), createChildrenConfigMock(
0331:                        "thread-pool", new Configuration[0]));
0332:                mainConfigControl.replay();
0333:
0334:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0335:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0336:                        .getMock();
0337:                childLoggerDefaultControl.replay();
0338:
0339:                final MockControl childLoggerMyPoolControl = createStrictControl(Logger.class);
0340:                final Logger childLoggerMyPool = (Logger) childLoggerMyPoolControl
0341:                        .getMock();
0342:                childLoggerMyPoolControl.replay();
0343:
0344:                final MockControl loggerControl = createStrictControl(Logger.class);
0345:                final Logger logger = (Logger) loggerControl.getMock();
0346:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0347:                        childLoggerDefault);
0348:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0349:                logger
0350:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0351:                loggerControl.expectAndReturn(logger.getChildLogger("mypool"),
0352:                        childLoggerMyPool);
0353:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0354:                logger
0355:                        .info("ThreadPool named \"mypool\" created with maximum queue-size=230,max-pool-size=15,min-pool-size=12,priority=1,isDaemon=false,keep-alive-time-ms=15500,block-policy=\"DISCARD\",shutdown-wait-time-ms=22200");
0356:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0357:                logger.debug("Disposing all thread pools");
0358:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0359:                logger.debug("Disposing thread pool mypool");
0360:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0361:                logger.debug("Thread pool mypool disposed");
0362:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0363:                logger.debug("Disposing thread pool default");
0364:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0365:                logger.debug("Thread pool default disposed");
0366:                loggerControl.replay();
0367:
0368:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0369:                runnableManager.enableLogging(logger);
0370:
0371:                try {
0372:                    runnableManager.configure(mainConfig);
0373:                } catch (final ConfigurationException ce) {
0374:                    assertTrue("Throw unexpected ConfigurationException", false);
0375:                }
0376:
0377:                runnableManager.createPool("mypool", 230, 15, 12,
0378:                        Thread.MIN_PRIORITY, false, 15500, "DISCARD", false,
0379:                        22200);
0380:                runnableManager.dispose();
0381:                verify();
0382:            }
0383:
0384:            /**
0385:             * Class under test for ThreadPool createPool(int, int, int, int, boolean,
0386:             * long, String, boolean, int)
0387:             */
0388:            public final void testCreatePoolintintintintbooleanlongStringbooleanint() {
0389:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0390:                final Configuration mainConfig = (Configuration) mainConfigControl
0391:                        .getMock();
0392:                mainConfigControl.expectAndReturn(mainConfig
0393:                        .getChild("thread-factory"), createValueConfigMock(
0394:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0395:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0396:                mainConfigControl.expectAndReturn(mainConfig
0397:                        .getChild("thread-pools"), createChildrenConfigMock(
0398:                        "thread-pool", new Configuration[0]));
0399:                mainConfigControl.replay();
0400:
0401:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0402:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0403:                        .getMock();
0404:                childLoggerDefaultControl.replay();
0405:
0406:                final MockControl childLoggerAnonControl = createStrictControl(Logger.class);
0407:                final Logger childLoggerAnon = (Logger) childLoggerAnonControl
0408:                        .getMock();
0409:                childLoggerAnonControl.replay();
0410:
0411:                final MockControl loggerControl = createStrictControl(Logger.class);
0412:                final Logger logger = (Logger) loggerControl.getMock();
0413:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0414:                        childLoggerDefault);
0415:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0416:                logger
0417:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0418:                loggerControl.expectAndReturn(
0419:                        logger.getChildLogger("anon-xxx"), childLoggerAnon);
0420:                loggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0421:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0422:                logger
0423:                        .info("ThreadPool named \"anon-xxx\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=10,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0424:                loggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0425:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0426:                logger.debug("Disposing all thread pools");
0427:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0428:                logger.debug("Disposing thread pool anon-xxx");
0429:                loggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0430:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0431:                logger.debug("Thread pool anon-xxx disposed");
0432:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0433:                logger.debug("Disposing thread pool default");
0434:                loggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0435:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0436:                logger.debug("Thread pool default disposed");
0437:                loggerControl.replay();
0438:
0439:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0440:                runnableManager.enableLogging(logger);
0441:
0442:                try {
0443:                    runnableManager.configure(mainConfig);
0444:                } catch (final ConfigurationException ce) {
0445:                    assertTrue("Throw unexpected ConfigurationException", false);
0446:                }
0447:
0448:                final ThreadPool threadPool = runnableManager.createPool(200,
0449:                        5, 2, Thread.MAX_PRIORITY, true, 15000, "ABORT", true,
0450:                        22000);
0451:                assertEquals("queue-size", 200, threadPool
0452:                        .getMaximumQueueSize());
0453:                assertEquals("max-pool-size", 5, threadPool
0454:                        .getMaximumPoolSize());
0455:                assertEquals("min-pool-size", 2, threadPool
0456:                        .getMinimumPoolSize());
0457:                assertEquals("priority", Thread.MAX_PRIORITY, threadPool
0458:                        .getPriority());
0459:                assertEquals("keep-alive-time-ms", 15000, threadPool
0460:                        .getKeepAliveTime());
0461:                assertEquals("block-policy", "ABORT", threadPool
0462:                        .getBlockPolicy());
0463:                runnableManager.dispose();
0464:                verify();
0465:            }
0466:
0467:            /**
0468:             * Class under test for void execute(Runnable)
0469:             */
0470:            public final void testExecuteRunnable() {
0471:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0472:                final Configuration mainConfig = (Configuration) mainConfigControl
0473:                        .getMock();
0474:                mainConfigControl.expectAndReturn(mainConfig
0475:                        .getChild("thread-factory"), createValueConfigMock(
0476:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0477:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0478:                mainConfigControl.expectAndReturn(mainConfig
0479:                        .getChild("thread-pools"), createChildrenConfigMock(
0480:                        "thread-pool", new Configuration[0]));
0481:                mainConfigControl.replay();
0482:
0483:                final MockControl childLoggerControl = createStrictControl(Logger.class);
0484:                final Logger childLogger = (Logger) childLoggerControl
0485:                        .getMock();
0486:                childLoggerControl.expectAndReturn(
0487:                        childLogger.isDebugEnabled(), true);
0488:                childLogger
0489:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0490:                childLoggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0491:                childLoggerControl.expectAndReturn(
0492:                        childLogger.isDebugEnabled(), true);
0493:                childLogger
0494:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0495:                childLoggerControl.replay();
0496:
0497:                final MockControl loggerControl = createStrictControl(Logger.class);
0498:                final Logger logger = (Logger) loggerControl.getMock();
0499:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0500:                        childLogger);
0501:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0502:                logger
0503:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0504:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0505:                logger.debug("Starting the heart");
0506:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0507:                logger.debug("Entering loop");
0508:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0509:                logger.debug("No commands available. Will just wait for one");
0510:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0511:                logger
0512:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=0, interval=0");
0513:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0514:                logger
0515:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=0");
0516:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0517:                logger.debug("No commands available. Will just wait for one");
0518:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0519:                logger.debug("Exiting loop");
0520:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0521:                logger.debug("Disposing all thread pools");
0522:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0523:                logger.debug("Disposing thread pool default");
0524:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0525:                logger.debug("Thread pool default disposed");
0526:                loggerControl.replay();
0527:
0528:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0529:                runnableManager.enableLogging(logger);
0530:
0531:                try {
0532:                    runnableManager.configure(mainConfig);
0533:                } catch (final ConfigurationException ce) {
0534:                    assertTrue("Throw unexpected ConfigurationException", false);
0535:                }
0536:
0537:                final MockControl runnableControl = createStrictControl(Runnable.class);
0538:                final Runnable runnable = (Runnable) runnableControl.getMock();
0539:                runnable.run();
0540:                runnableControl.replay();
0541:
0542:                try {
0543:                    runnableManager.start();
0544:                    Thread.yield();
0545:                    Thread.sleep(20);
0546:                    runnableManager.execute(runnable);
0547:                    Thread.yield();
0548:                    Thread.sleep(20);
0549:                    runnableManager.stop();
0550:                    Thread.yield();
0551:                    Thread.sleep(20);
0552:                    runnableManager.dispose();
0553:                    Thread.sleep(20);
0554:                } catch (final Throwable ex) {
0555:                    ex.printStackTrace();
0556:                    assertTrue("Unexpected Exception", false);
0557:                }
0558:
0559:                verify();
0560:            }
0561:
0562:            /**
0563:             * Class under test for void execute(Runnable, long)
0564:             */
0565:            public final void testExecuteRunnablelong() {
0566:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0567:                final Configuration mainConfig = (Configuration) mainConfigControl
0568:                        .getMock();
0569:                mainConfigControl.expectAndReturn(mainConfig
0570:                        .getChild("thread-factory"), createValueConfigMock(
0571:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0572:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0573:                mainConfigControl.expectAndReturn(mainConfig
0574:                        .getChild("thread-pools"), createChildrenConfigMock(
0575:                        "thread-pool", new Configuration[0]));
0576:                mainConfigControl.replay();
0577:
0578:                final MockControl childLoggerControl = createStrictControl(Logger.class);
0579:                final Logger childLogger = (Logger) childLoggerControl
0580:                        .getMock();
0581:                childLoggerControl.expectAndReturn(
0582:                        childLogger.isDebugEnabled(), true);
0583:                childLogger
0584:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0585:                childLoggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0586:                childLoggerControl.expectAndReturn(
0587:                        childLogger.isDebugEnabled(), true);
0588:                childLogger
0589:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0590:                childLoggerControl.replay();
0591:
0592:                final MockControl loggerControl = createStrictControl(Logger.class);
0593:                final Logger logger = (Logger) loggerControl.getMock();
0594:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0595:                        childLogger);
0596:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0597:                logger
0598:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0599:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0600:                logger.debug("Starting the heart");
0601:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0602:                logger.debug("Entering loop");
0603:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0604:                logger.debug("No commands available. Will just wait for one");
0605:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0606:                logger
0607:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=100, interval=0");
0608:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0609:                logger
0610:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=0");
0611:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0612:                logger.debug("No commands available. Will just wait for one");
0613:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0614:                logger.debug("Exiting loop");
0615:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0616:                logger.debug("Disposing all thread pools");
0617:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0618:                logger.debug("Disposing thread pool default");
0619:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0620:                logger.debug("Thread pool default disposed");
0621:                loggerControl.replay();
0622:
0623:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0624:                runnableManager.enableLogging(logger);
0625:
0626:                try {
0627:                    runnableManager.configure(mainConfig);
0628:                } catch (final ConfigurationException ce) {
0629:                    assertTrue("Throw unexpected ConfigurationException", false);
0630:                }
0631:
0632:                final MockControl runnableControl = createStrictControl(Runnable.class);
0633:                final Runnable runnable = (Runnable) runnableControl.getMock();
0634:                runnable.run();
0635:                runnableControl.replay();
0636:
0637:                try {
0638:                    runnableManager.start();
0639:                    Thread.yield();
0640:                    Thread.sleep(20);
0641:                    runnableManager.execute(runnable, 100, 0);
0642:                    Thread.yield();
0643:                    Thread.sleep(200);
0644:                    runnableManager.stop();
0645:                    Thread.yield();
0646:                    Thread.sleep(20);
0647:                    runnableManager.dispose();
0648:                    Thread.sleep(20);
0649:                } catch (final Throwable ex) {
0650:                    ex.printStackTrace();
0651:                    assertTrue("Unexpected Exception", false);
0652:                }
0653:
0654:                verify();
0655:            }
0656:
0657:            /**
0658:             * Class under test for void execute(Runnable, long, long)
0659:             */
0660:            public final void testExecuteRunnablelonglong() {
0661:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0662:                final Configuration mainConfig = (Configuration) mainConfigControl
0663:                        .getMock();
0664:                mainConfigControl.expectAndReturn(mainConfig
0665:                        .getChild("thread-factory"), createValueConfigMock(
0666:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0667:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0668:                mainConfigControl.expectAndReturn(mainConfig
0669:                        .getChild("thread-pools"), createChildrenConfigMock(
0670:                        "thread-pool", new Configuration[0]));
0671:                mainConfigControl.replay();
0672:
0673:                final MockControl childLoggerControl = createStrictControl(Logger.class);
0674:                final Logger childLogger = (Logger) childLoggerControl
0675:                        .getMock();
0676:                childLoggerControl.expectAndReturn(
0677:                        childLogger.isDebugEnabled(), true);
0678:                childLogger
0679:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0680:                childLoggerControl.setMatcher(MockControl.ALWAYS_MATCHER);
0681:                childLoggerControl.expectAndReturn(
0682:                        childLogger.isDebugEnabled(), true);
0683:                childLogger
0684:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0685:                childLoggerControl.replay();
0686:
0687:                final MockControl loggerControl = createStrictControl(Logger.class);
0688:                final Logger logger = (Logger) loggerControl.getMock();
0689:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0690:                        childLogger);
0691:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0692:                logger
0693:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0694:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0695:                logger.debug("Starting the heart");
0696:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0697:                logger.debug("Entering loop");
0698:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0699:                logger.debug("No commands available. Will just wait for one");
0700:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0701:                logger
0702:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=100, interval=100");
0703:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0704:                logger
0705:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=100");
0706:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0707:                logger.debug("Exiting loop");
0708:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0709:                logger.debug("Disposing all thread pools");
0710:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0711:                logger.debug("Disposing thread pool default");
0712:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0713:                logger.debug("Thread pool default disposed");
0714:                loggerControl.replay();
0715:
0716:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0717:                runnableManager.enableLogging(logger);
0718:
0719:                try {
0720:                    runnableManager.configure(mainConfig);
0721:                } catch (final ConfigurationException ce) {
0722:                    assertTrue("Throw unexpected ConfigurationException", false);
0723:                }
0724:
0725:                final MockControl runnableControl = createStrictControl(Runnable.class);
0726:                final Runnable runnable = (Runnable) runnableControl.getMock();
0727:                runnable.run();
0728:                runnableControl.setVoidCallable(MockControl.ONE_OR_MORE);
0729:                runnableControl.replay();
0730:
0731:                try {
0732:                    runnableManager.start();
0733:                    Thread.yield();
0734:                    Thread.sleep(20);
0735:                    runnableManager.execute(runnable, 100, 100);
0736:                    Thread.yield();
0737:                    Thread.sleep(200);
0738:                    runnableManager.stop();
0739:                    Thread.yield();
0740:                    Thread.sleep(20);
0741:                    runnableManager.dispose();
0742:                    Thread.sleep(20);
0743:                } catch (final Throwable ex) {
0744:                    ex.printStackTrace();
0745:                    assertTrue("Unexpected Exception", false);
0746:                }
0747:
0748:                verify();
0749:            }
0750:
0751:            /**
0752:             * Class under test for void execute(String, Runnable)
0753:             */
0754:            public final void testExecuteStringRunnable() {
0755:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0756:                final Configuration mainConfig = (Configuration) mainConfigControl
0757:                        .getMock();
0758:                mainConfigControl.expectAndReturn(mainConfig
0759:                        .getChild("thread-factory"), createValueConfigMock(
0760:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0761:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0762:                mainConfigControl.expectAndReturn(mainConfig
0763:                        .getChild("thread-pools"), createChildrenConfigMock(
0764:                        "thread-pool", new Configuration[0]));
0765:                mainConfigControl.replay();
0766:
0767:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0768:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0769:                        .getMock();
0770:                childLoggerDefaultControl.expectAndReturn(childLoggerDefault
0771:                        .isDebugEnabled(), true);
0772:                childLoggerDefault
0773:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0774:                childLoggerDefaultControl
0775:                        .setMatcher(MockControl.ALWAYS_MATCHER);
0776:                childLoggerDefaultControl.replay();
0777:
0778:                final MockControl childLoggerMyPoolControl = createStrictControl(Logger.class);
0779:                final Logger childLoggerMyPool = (Logger) childLoggerMyPoolControl
0780:                        .getMock();
0781:                childLoggerMyPoolControl.expectAndReturn(childLoggerMyPool
0782:                        .isDebugEnabled(), true);
0783:                childLoggerMyPool
0784:                        .debug("Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool");
0785:                childLoggerMyPoolControl.replay();
0786:
0787:                final MockControl loggerControl = createStrictControl(Logger.class);
0788:                final Logger logger = (Logger) loggerControl.getMock();
0789:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0790:                        childLoggerDefault);
0791:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0792:                logger
0793:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0794:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0795:                logger.debug("Starting the heart");
0796:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0797:                logger.debug("Entering loop");
0798:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0799:                logger.debug("No commands available. Will just wait for one");
0800:                loggerControl.expectAndReturn(logger.getChildLogger("mypool"),
0801:                        childLoggerMyPool);
0802:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0803:                logger
0804:                        .info("ThreadPool named \"mypool\" created with maximum queue-size=230,max-pool-size=15,min-pool-size=12,priority=1,isDaemon=false,keep-alive-time-ms=15500,block-policy=\"DISCARD\",shutdown-wait-time-ms=22200");
0805:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0806:                logger
0807:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=0, interval=0");
0808:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0809:                logger
0810:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=0");
0811:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0812:                logger.debug("No commands available. Will just wait for one");
0813:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0814:                logger.debug("Exiting loop");
0815:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0816:                logger.debug("Disposing all thread pools");
0817:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0818:                logger.debug("Disposing thread pool mypool");
0819:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0820:                logger.debug("Thread pool mypool disposed");
0821:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0822:                logger.debug("Disposing thread pool default");
0823:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0824:                logger.debug("Thread pool default disposed");
0825:                loggerControl.replay();
0826:
0827:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0828:                runnableManager.enableLogging(logger);
0829:
0830:                try {
0831:                    runnableManager.configure(mainConfig);
0832:                } catch (final ConfigurationException ce) {
0833:                    assertTrue("Throw unexpected ConfigurationException", false);
0834:                }
0835:
0836:                final MockControl runnableControl = createStrictControl(Runnable.class);
0837:                final Runnable runnable = (Runnable) runnableControl.getMock();
0838:                runnable.run();
0839:                runnableControl.replay();
0840:
0841:                try {
0842:                    runnableManager.start();
0843:                    Thread.yield();
0844:                    Thread.sleep(20);
0845:                    runnableManager.createPool("mypool", 230, 15, 12,
0846:                            Thread.MIN_PRIORITY, false, 15500, "DISCARD",
0847:                            false, 22200);
0848:                    runnableManager.execute("mypool", runnable);
0849:                    Thread.yield();
0850:                    Thread.sleep(20);
0851:                    runnableManager.stop();
0852:                    Thread.yield();
0853:                    Thread.sleep(20);
0854:                    runnableManager.dispose();
0855:                    Thread.sleep(20);
0856:                } catch (final Throwable ex) {
0857:                    ex.printStackTrace();
0858:                    assertTrue("Unexpected Exception", false);
0859:                }
0860:
0861:                verify();
0862:            }
0863:
0864:            /**
0865:             * Class under test for void execute(String, Runnable, long)
0866:             */
0867:            public final void testExecuteStringRunnablelong() {
0868:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0869:                final Configuration mainConfig = (Configuration) mainConfigControl
0870:                        .getMock();
0871:                mainConfigControl.expectAndReturn(mainConfig
0872:                        .getChild("thread-factory"), createValueConfigMock(
0873:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0874:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0875:                mainConfigControl.expectAndReturn(mainConfig
0876:                        .getChild("thread-pools"), createChildrenConfigMock(
0877:                        "thread-pool", new Configuration[0]));
0878:                mainConfigControl.replay();
0879:
0880:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0881:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0882:                        .getMock();
0883:                childLoggerDefaultControl.expectAndReturn(childLoggerDefault
0884:                        .isDebugEnabled(), true);
0885:                childLoggerDefault
0886:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
0887:                childLoggerDefaultControl
0888:                        .setMatcher(MockControl.ALWAYS_MATCHER);
0889:                childLoggerDefaultControl.replay();
0890:
0891:                final MockControl childLoggerMyPoolControl = createStrictControl(Logger.class);
0892:                final Logger childLoggerMyPool = (Logger) childLoggerMyPoolControl
0893:                        .getMock();
0894:                childLoggerMyPoolControl.expectAndReturn(childLoggerMyPool
0895:                        .isDebugEnabled(), true);
0896:                childLoggerMyPool
0897:                        .debug("Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool");
0898:                childLoggerMyPoolControl.replay();
0899:
0900:                final MockControl loggerControl = createStrictControl(Logger.class);
0901:                final Logger logger = (Logger) loggerControl.getMock();
0902:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
0903:                        childLoggerDefault);
0904:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0905:                logger
0906:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
0907:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0908:                logger.debug("Starting the heart");
0909:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0910:                logger.debug("Entering loop");
0911:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0912:                logger.debug("No commands available. Will just wait for one");
0913:                loggerControl.expectAndReturn(logger.getChildLogger("mypool"),
0914:                        childLoggerMyPool);
0915:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
0916:                logger
0917:                        .info("ThreadPool named \"mypool\" created with maximum queue-size=230,max-pool-size=15,min-pool-size=12,priority=1,isDaemon=false,keep-alive-time-ms=15500,block-policy=\"DISCARD\",shutdown-wait-time-ms=22200");
0918:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0919:                logger
0920:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=100, interval=0");
0921:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0922:                logger
0923:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=0");
0924:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0925:                logger.debug("No commands available. Will just wait for one");
0926:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0927:                logger.debug("Exiting loop");
0928:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0929:                logger.debug("Disposing all thread pools");
0930:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0931:                logger.debug("Disposing thread pool mypool");
0932:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0933:                logger.debug("Thread pool mypool disposed");
0934:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0935:                logger.debug("Disposing thread pool default");
0936:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
0937:                logger.debug("Thread pool default disposed");
0938:                loggerControl.replay();
0939:
0940:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
0941:                runnableManager.enableLogging(logger);
0942:
0943:                try {
0944:                    runnableManager.configure(mainConfig);
0945:                } catch (final ConfigurationException ce) {
0946:                    assertTrue("Throw unexpected ConfigurationException", false);
0947:                }
0948:
0949:                final MockControl runnableControl = createStrictControl(Runnable.class);
0950:                final Runnable runnable = (Runnable) runnableControl.getMock();
0951:                runnable.run();
0952:                runnableControl.replay();
0953:
0954:                try {
0955:                    runnableManager.start();
0956:                    Thread.yield();
0957:                    Thread.sleep(20);
0958:                    runnableManager.createPool("mypool", 230, 15, 12,
0959:                            Thread.MIN_PRIORITY, false, 15500, "DISCARD",
0960:                            false, 22200);
0961:                    runnableManager.execute("mypool", runnable, 100, 0);
0962:                    Thread.yield();
0963:                    Thread.sleep(200);
0964:                    runnableManager.stop();
0965:                    Thread.yield();
0966:                    Thread.sleep(20);
0967:                    runnableManager.dispose();
0968:                    Thread.sleep(20);
0969:                } catch (final Throwable ex) {
0970:                    ex.printStackTrace();
0971:                    assertTrue("Unexpected Exception", false);
0972:                }
0973:
0974:                verify();
0975:            }
0976:
0977:            /**
0978:             * Class under test for void execute(String, Runnable, long, long)
0979:             */
0980:            public final void testExecuteStringRunnablelonglong() {
0981:                final MockControl mainConfigControl = createStrictControl(Configuration.class);
0982:                final Configuration mainConfig = (Configuration) mainConfigControl
0983:                        .getMock();
0984:                mainConfigControl.expectAndReturn(mainConfig
0985:                        .getChild("thread-factory"), createValueConfigMock(
0986:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY,
0987:                        DefaultRunnableManager.DEFAULT_THREAD_FACTORY));
0988:                mainConfigControl.expectAndReturn(mainConfig
0989:                        .getChild("thread-pools"), createChildrenConfigMock(
0990:                        "thread-pool", new Configuration[0]));
0991:                mainConfigControl.replay();
0992:
0993:                final MockControl childLoggerDefaultControl = createStrictControl(Logger.class);
0994:                final Logger childLoggerDefault = (Logger) childLoggerDefaultControl
0995:                        .getMock();
0996:                childLoggerDefaultControl.expectAndReturn(childLoggerDefault
0997:                        .isDebugEnabled(), true);
0998:                childLoggerDefault
0999:                        .debug("Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager");
1000:                childLoggerDefaultControl
1001:                        .setMatcher(MockControl.ALWAYS_MATCHER);
1002:                childLoggerDefaultControl.replay();
1003:
1004:                final MockControl childLoggerMyPoolControl = createStrictControl(Logger.class);
1005:                final Logger childLoggerMyPool = (Logger) childLoggerMyPoolControl
1006:                        .getMock();
1007:                childLoggerMyPoolControl.expectAndReturn(childLoggerMyPool
1008:                        .isDebugEnabled(), true);
1009:                childLoggerMyPool
1010:                        .debug("Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool");
1011:                childLoggerMyPoolControl.replay();
1012:
1013:                final MockControl loggerControl = createStrictControl(Logger.class);
1014:                final Logger logger = (Logger) loggerControl.getMock();
1015:                loggerControl.expectAndReturn(logger.getChildLogger("default"),
1016:                        childLoggerDefault);
1017:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
1018:                logger
1019:                        .info("ThreadPool named \"default\" created with maximum queue-size=2147483647,max-pool-size=5,min-pool-size=5,priority=5,isDaemon=false,keep-alive-time-ms=60000,block-policy=\"RUN\",shutdown-wait-time-ms=-1");
1020:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1021:                logger.debug("Starting the heart");
1022:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1023:                logger.debug("Entering loop");
1024:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1025:                logger.debug("No commands available. Will just wait for one");
1026:                loggerControl.expectAndReturn(logger.getChildLogger("mypool"),
1027:                        childLoggerMyPool);
1028:                loggerControl.expectAndReturn(logger.isInfoEnabled(), true);
1029:                logger
1030:                        .info("ThreadPool named \"mypool\" created with maximum queue-size=230,max-pool-size=15,min-pool-size=12,priority=1,isDaemon=false,keep-alive-time-ms=15500,block-policy=\"DISCARD\",shutdown-wait-time-ms=22200");
1031:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1032:                logger
1033:                        .debug("Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=100, interval=100");
1034:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1035:                logger
1036:                        .debug("Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=100");
1037:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1038:                logger.debug("Exiting loop");
1039:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1040:                logger.debug("Disposing all thread pools");
1041:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1042:                logger.debug("Disposing thread pool mypool");
1043:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1044:                logger.debug("Thread pool mypool disposed");
1045:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1046:                logger.debug("Disposing thread pool default");
1047:                loggerControl.expectAndReturn(logger.isDebugEnabled(), true);
1048:                logger.debug("Thread pool default disposed");
1049:                loggerControl.replay();
1050:
1051:                final DefaultRunnableManager runnableManager = new DefaultRunnableManager();
1052:                runnableManager.enableLogging(logger);
1053:
1054:                try {
1055:                    runnableManager.configure(mainConfig);
1056:                } catch (final ConfigurationException ce) {
1057:                    assertTrue("Throw unexpected ConfigurationException", false);
1058:                }
1059:
1060:                final MockControl runnableControl = createStrictControl(Runnable.class);
1061:                final Runnable runnable = (Runnable) runnableControl.getMock();
1062:                runnable.run();
1063:                runnableControl.replay();
1064:
1065:                try {
1066:                    runnableManager.start();
1067:                    Thread.yield();
1068:                    Thread.sleep(20);
1069:                    runnableManager.createPool("mypool", 230, 15, 12,
1070:                            Thread.MIN_PRIORITY, false, 15500, "DISCARD",
1071:                            false, 22200);
1072:                    runnableManager.execute("mypool", runnable, 100, 100);
1073:                    Thread.yield();
1074:                    Thread.sleep(200);
1075:                    runnableManager.stop();
1076:                    Thread.yield();
1077:                    Thread.sleep(20);
1078:                    runnableManager.dispose();
1079:                    Thread.sleep(20);
1080:                } catch (final Throwable ex) {
1081:                    ex.printStackTrace();
1082:                    assertTrue("Unexpected Exception", false);
1083:                }
1084:
1085:                verify();
1086:            }
1087:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.