1 16 package org.apache.cocoon.components.thread; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.avalon.framework.logger.Logger; 21 import org.easymock.MockControl; 22 23 29 public class DefaultRunnableManagerTestCase extends AbstractTestCase 30 { 31 33 38 public DefaultRunnableManagerTestCase( String name ) 39 { 40 super( name ); 41 } 42 43 45 50 public final void testConfigureDaemonPool( ) 51 throws Exception 52 { 53 final MockControl threadPoolConfigControl = 54 createStrictControl( Configuration.class ); 55 final Configuration threadPoolConfig = 56 (Configuration)threadPoolConfigControl.getMock( ); 57 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "name" ), 58 createValueConfigMock( "daemon" ) ); 59 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "queue-size" ), 60 createIntegerConfigMock( 2 * DefaultRunnableManager.DEFAULT_QUEUE_SIZE, 61 DefaultRunnableManager.DEFAULT_QUEUE_SIZE ) ); 62 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "max-pool-size" ), 63 createIntegerConfigMock( 2 * DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE, 64 DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE ) ); 65 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "min-pool-size" ), 66 createIntegerConfigMock( DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE / 3, 67 DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE ) ); 68 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "priority" ), 69 createValueConfigMock( "LOW", 70 DefaultRunnableManager.DEFAULT_THREAD_PRIORITY ) ); 71 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "daemon" ), 72 createBooleanConfigMock( false, 73 DefaultRunnableManager.DEFAULT_DAEMON_MODE ) ); 74 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "keep-alive-time-ms" ), 75 createLongConfigMock( DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME / 2, 76 DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME ) ); 77 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "block-policy" ), 78 createValueConfigMock( "WAIT", 79 DefaultThreadPool.POLICY_DEFAULT ) ); 80 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "shutdown-graceful" ), 81 createBooleanConfigMock( true, 82 DefaultRunnableManager.DEFAULT_SHUTDOWN_GRACEFUL ) ); 83 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "shutdown-wait-time-ms" ), 84 createIntegerConfigMock( DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME / 2, 85 DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME ) ); 86 threadPoolConfigControl.replay( ); 87 88 final MockControl mainConfigControl = 89 createStrictControl( Configuration.class ); 90 final Configuration mainConfig = 91 (Configuration)mainConfigControl.getMock( ); 92 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 93 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 94 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 95 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 96 createChildrenConfigMock( "thread-pool", 97 new Configuration [] 98 { 99 threadPoolConfig 100 } ) ); 101 mainConfigControl.replay( ); 102 103 final MockControl childLoggerDaemonControl = 104 createStrictControl( Logger.class ); 105 final Logger childLoggerDaemon = 106 (Logger)childLoggerDaemonControl.getMock( ); 107 childLoggerDaemonControl.replay( ); 108 109 final MockControl childLoggerDefaultControl = 110 createStrictControl( Logger.class ); 111 final Logger childLoggerDefault = 112 (Logger)childLoggerDefaultControl.getMock( ); 113 childLoggerDefaultControl.replay( ); 114 115 final MockControl loggerControl = createStrictControl( Logger.class ); 116 final Logger logger = (Logger)loggerControl.getMock( ); 117 logger.warn( "Unknown thread priority \"LOW\". Set to \"NORM\"." ); 118 loggerControl.expectAndReturn( logger.getChildLogger( "daemon" ), 119 childLoggerDaemon ); 120 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 121 logger.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" ); 122 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 123 childLoggerDefault ); 124 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 125 logger.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" ); 126 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 127 logger.debug( "Disposing all thread pools" ); 128 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 129 logger.debug( "Disposing thread pool daemon" ); 130 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 131 logger.debug( "Thread pool daemon disposed" ); 132 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 133 logger.debug( "Disposing thread pool default" ); 134 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 135 logger.debug( "Thread pool default disposed" ); 136 loggerControl.replay( ); 137 138 final DefaultRunnableManager runnableManager = 139 new DefaultRunnableManager( ); 140 runnableManager.enableLogging( logger ); 141 142 try 143 { 144 runnableManager.configure( mainConfig ); 145 } 146 catch( final ConfigurationException ce ) 147 { 148 assertTrue( "Throw unexpected ConfigurationException", false ); 149 } 150 151 runnableManager.dispose( ); 152 verify( ); 153 } 154 155 158 public final void testConfigureMinimal( ) 159 { 160 final MockControl mainConfigControl = 161 createStrictControl( Configuration.class ); 162 final Configuration mainConfig = 163 (Configuration)mainConfigControl.getMock( ); 164 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 165 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 166 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 167 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 168 createChildrenConfigMock( "thread-pool", 169 new Configuration[ 0 ] ) ); 170 mainConfigControl.replay( ); 171 172 final MockControl childLoggerDefaultControl = 173 createStrictControl( Logger.class ); 174 final Logger childLoggerDefault = 175 (Logger)childLoggerDefaultControl.getMock( ); 176 childLoggerDefaultControl.replay( ); 177 178 final MockControl loggerControl = createStrictControl( Logger.class ); 179 final Logger logger = (Logger)loggerControl.getMock( ); 180 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 181 childLoggerDefault ); 182 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 183 logger.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" ); 184 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 185 logger.debug( "Disposing all thread pools" ); 186 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 187 logger.debug( "Disposing thread pool default" ); 188 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 189 logger.debug( "Thread pool default disposed" ); 190 loggerControl.replay( ); 191 192 final DefaultRunnableManager runnableManager = 193 new DefaultRunnableManager( ); 194 runnableManager.enableLogging( logger ); 195 196 try 197 { 198 runnableManager.configure( mainConfig ); 199 } 200 catch( final ConfigurationException ce ) 201 { 202 assertTrue( "Throw unexpected ConfigurationException", false ); 203 } 204 205 runnableManager.dispose( ); 206 verify( ); 207 } 208 209 214 public final void testConfigureMyPool( ) 215 throws Exception 216 { 217 final MockControl threadPoolConfigControl = 218 createStrictControl( Configuration.class ); 219 final Configuration threadPoolConfig = 220 (Configuration)threadPoolConfigControl.getMock( ); 221 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "name" ), 222 createValueConfigMock( "mypool" ) ); 223 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "queue-size" ), 224 createIntegerConfigMock( 2 * DefaultRunnableManager.DEFAULT_QUEUE_SIZE, 225 DefaultRunnableManager.DEFAULT_QUEUE_SIZE ) ); 226 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "max-pool-size" ), 227 createIntegerConfigMock( 2 * DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE, 228 DefaultRunnableManager.DEFAULT_MAX_POOL_SIZE ) ); 229 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "min-pool-size" ), 230 createIntegerConfigMock( DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE / 3, 231 DefaultRunnableManager.DEFAULT_MIN_POOL_SIZE ) ); 232 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "priority" ), 233 createValueConfigMock( "MIN", 234 DefaultRunnableManager.DEFAULT_THREAD_PRIORITY ) ); 235 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "daemon" ), 236 createBooleanConfigMock( false, 237 DefaultRunnableManager.DEFAULT_DAEMON_MODE ) ); 238 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "keep-alive-time-ms" ), 239 createLongConfigMock( DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME / 2, 240 DefaultRunnableManager.DEFAULT_KEEP_ALIVE_TIME ) ); 241 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "block-policy" ), 242 createValueConfigMock( "WAIT", 243 DefaultThreadPool.POLICY_DEFAULT ) ); 244 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "shutdown-graceful" ), 245 createBooleanConfigMock( true, 246 DefaultRunnableManager.DEFAULT_SHUTDOWN_GRACEFUL ) ); 247 threadPoolConfigControl.expectAndReturn( threadPoolConfig.getChild( "shutdown-wait-time-ms" ), 248 createIntegerConfigMock( DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME / 2, 249 DefaultRunnableManager.DEFAULT_SHUTDOWN_WAIT_TIME ) ); 250 threadPoolConfigControl.replay( ); 251 252 final MockControl mainConfigControl = 253 createStrictControl( Configuration.class ); 254 final Configuration mainConfig = 255 (Configuration)mainConfigControl.getMock( ); 256 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 257 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 258 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 259 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 260 createChildrenConfigMock( "thread-pool", 261 new Configuration [] 262 { 263 threadPoolConfig 264 } ) ); 265 mainConfigControl.replay( ); 266 267 final MockControl childLoggerDefaultControl = 268 createStrictControl( Logger.class ); 269 final Logger childLoggerDefault = 270 (Logger)childLoggerDefaultControl.getMock( ); 271 childLoggerDefaultControl.replay( ); 272 273 final MockControl childLoggerMyPoolControl = 274 createStrictControl( Logger.class ); 275 final Logger childLoggerMyPool = 276 (Logger)childLoggerMyPoolControl.getMock( ); 277 childLoggerMyPoolControl.replay( ); 278 279 final MockControl loggerControl = createStrictControl( Logger.class ); 280 final Logger logger = (Logger)loggerControl.getMock( ); 281 loggerControl.expectAndReturn( logger.getChildLogger( "mypool" ), 282 childLoggerMyPool ); 283 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 284 logger.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" ); 285 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 286 childLoggerDefault ); 287 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 288 logger.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" ); 289 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 290 logger.debug( "Disposing all thread pools" ); 291 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 292 logger.debug( "Disposing thread pool mypool" ); 293 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 294 logger.debug( "Thread pool mypool disposed" ); 295 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 296 logger.debug( "Disposing thread pool default" ); 297 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 298 logger.debug( "Thread pool default disposed" ); 299 loggerControl.replay( ); 300 301 final DefaultRunnableManager runnableManager = 302 new DefaultRunnableManager( ); 303 runnableManager.enableLogging( logger ); 304 305 try 306 { 307 runnableManager.configure( mainConfig ); 308 } 309 catch( final ConfigurationException ce ) 310 { 311 assertTrue( "Throw unexpected ConfigurationException", false ); 312 } 313 314 runnableManager.dispose( ); 315 verify( ); 316 } 317 318 322 public final void testCreatePoolStringintintintintbooleanlongStringbooleanint( ) 323 { 324 final MockControl mainConfigControl = 325 createStrictControl( Configuration.class ); 326 final Configuration mainConfig = 327 (Configuration)mainConfigControl.getMock( ); 328 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 329 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 330 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 331 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 332 createChildrenConfigMock( "thread-pool", 333 new Configuration[ 0 ] ) ); 334 mainConfigControl.replay( ); 335 336 final MockControl childLoggerDefaultControl = 337 createStrictControl( Logger.class ); 338 final Logger childLoggerDefault = 339 (Logger)childLoggerDefaultControl.getMock( ); 340 childLoggerDefaultControl.replay( ); 341 342 final MockControl childLoggerMyPoolControl = 343 createStrictControl( Logger.class ); 344 final Logger childLoggerMyPool = 345 (Logger)childLoggerMyPoolControl.getMock( ); 346 childLoggerMyPoolControl.replay( ); 347 348 final MockControl loggerControl = createStrictControl( Logger.class ); 349 final Logger logger = (Logger)loggerControl.getMock( ); 350 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 351 childLoggerDefault ); 352 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 353 logger.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" ); 354 loggerControl.expectAndReturn( logger.getChildLogger( "mypool" ), 355 childLoggerMyPool ); 356 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 357 logger.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" ); 358 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 359 logger.debug( "Disposing all thread pools" ); 360 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 361 logger.debug( "Disposing thread pool mypool" ); 362 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 363 logger.debug( "Thread pool mypool disposed" ); 364 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 365 logger.debug( "Disposing thread pool default" ); 366 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 367 logger.debug( "Thread pool default disposed" ); 368 loggerControl.replay( ); 369 370 final DefaultRunnableManager runnableManager = 371 new DefaultRunnableManager( ); 372 runnableManager.enableLogging( logger ); 373 374 try 375 { 376 runnableManager.configure( mainConfig ); 377 } 378 catch( final ConfigurationException ce ) 379 { 380 assertTrue( "Throw unexpected ConfigurationException", false ); 381 } 382 383 runnableManager.createPool( "mypool", 230, 15, 12, Thread.MIN_PRIORITY, 384 false, 15500, "DISCARD", false, 22200 ); 385 runnableManager.dispose( ); 386 verify( ); 387 } 388 389 393 public final void testCreatePoolintintintintbooleanlongStringbooleanint( ) 394 { 395 final MockControl mainConfigControl = 396 createStrictControl( Configuration.class ); 397 final Configuration mainConfig = 398 (Configuration)mainConfigControl.getMock( ); 399 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 400 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 401 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 402 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 403 createChildrenConfigMock( "thread-pool", 404 new Configuration[ 0 ] ) ); 405 mainConfigControl.replay( ); 406 407 final MockControl childLoggerDefaultControl = 408 createStrictControl( Logger.class ); 409 final Logger childLoggerDefault = 410 (Logger)childLoggerDefaultControl.getMock( ); 411 childLoggerDefaultControl.replay( ); 412 413 final MockControl childLoggerAnonControl = 414 createStrictControl( Logger.class ); 415 final Logger childLoggerAnon = 416 (Logger)childLoggerAnonControl.getMock( ); 417 childLoggerAnonControl.replay( ); 418 419 final MockControl loggerControl = createStrictControl( Logger.class ); 420 final Logger logger = (Logger)loggerControl.getMock( ); 421 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 422 childLoggerDefault ); 423 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 424 logger.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" ); 425 loggerControl.expectAndReturn( logger.getChildLogger( "anon-xxx" ), 426 childLoggerAnon ); 427 loggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 428 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 429 logger.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" ); 430 loggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 431 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 432 logger.debug( "Disposing all thread pools" ); 433 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 434 logger.debug( "Disposing thread pool anon-xxx" ); 435 loggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 436 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 437 logger.debug( "Thread pool anon-xxx disposed" ); 438 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 439 logger.debug( "Disposing thread pool default" ); 440 loggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 441 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 442 logger.debug( "Thread pool default disposed" ); 443 loggerControl.replay( ); 444 445 final DefaultRunnableManager runnableManager = 446 new DefaultRunnableManager( ); 447 runnableManager.enableLogging( logger ); 448 449 try 450 { 451 runnableManager.configure( mainConfig ); 452 } 453 catch( final ConfigurationException ce ) 454 { 455 assertTrue( "Throw unexpected ConfigurationException", false ); 456 } 457 458 final ThreadPool threadPool = 459 runnableManager.createPool( 200, 5, 2, Thread.MAX_PRIORITY, true, 460 15000, "ABORT", true, 22000 ); 461 assertEquals( "queue-size", 200, threadPool.getMaximumQueueSize( ) ); 462 assertEquals( "max-pool-size", 5, threadPool.getMaximumPoolSize( ) ); 463 assertEquals( "min-pool-size", 2, threadPool.getMinimumPoolSize( ) ); 464 assertEquals( "priority", Thread.MAX_PRIORITY, 465 threadPool.getPriority( ) ); 466 assertEquals( "keep-alive-time-ms", 15000, 467 threadPool.getKeepAliveTime( ) ); 468 assertEquals( "block-policy", "ABORT", threadPool.getBlockPolicy( ) ); 469 runnableManager.dispose( ); 470 verify( ); 471 } 472 473 476 public final void testExecuteRunnable( ) 477 { 478 final MockControl mainConfigControl = 479 createStrictControl( Configuration.class ); 480 final Configuration mainConfig = 481 (Configuration)mainConfigControl.getMock( ); 482 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 483 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 484 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 485 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 486 createChildrenConfigMock( "thread-pool", 487 new Configuration[ 0 ] ) ); 488 mainConfigControl.replay( ); 489 490 final MockControl childLoggerControl = 491 createStrictControl( Logger.class ); 492 final Logger childLogger = (Logger)childLoggerControl.getMock( ); 493 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 494 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 495 childLoggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 496 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 497 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 498 childLoggerControl.replay( ); 499 500 final MockControl loggerControl = createStrictControl( Logger.class ); 501 final Logger logger = (Logger)loggerControl.getMock( ); 502 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 503 childLogger ); 504 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 505 logger.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" ); 506 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 507 logger.debug( "Starting the heart" ); 508 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 509 logger.debug( "Entering loop" ); 510 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 511 logger.debug( "No commands available. Will just wait for one" ); 512 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 513 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=0, interval=0" ); 514 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 515 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=0" ); 516 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 517 logger.debug( "No commands available. Will just wait for one" ); 518 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 519 logger.debug( "Exiting loop" ); 520 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 521 logger.debug( "Disposing all thread pools" ); 522 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 523 logger.debug( "Disposing thread pool default" ); 524 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 525 logger.debug( "Thread pool default disposed" ); 526 loggerControl.replay( ); 527 528 final DefaultRunnableManager runnableManager = 529 new DefaultRunnableManager( ); 530 runnableManager.enableLogging( logger ); 531 532 try 533 { 534 runnableManager.configure( mainConfig ); 535 } 536 catch( final ConfigurationException ce ) 537 { 538 assertTrue( "Throw unexpected ConfigurationException", false ); 539 } 540 541 final MockControl runnableControl = 542 createStrictControl( Runnable .class ); 543 final Runnable runnable = (Runnable )runnableControl.getMock( ); 544 runnable.run( ); 545 runnableControl.replay( ); 546 547 try 548 { 549 runnableManager.start( ); 550 Thread.yield( ); 551 Thread.sleep( 20 ); 552 runnableManager.execute( runnable ); 553 Thread.yield( ); 554 Thread.sleep( 20 ); 555 runnableManager.stop( ); 556 Thread.yield( ); 557 Thread.sleep( 20 ); 558 runnableManager.dispose( ); 559 Thread.sleep( 20 ); 560 } 561 catch( final Throwable ex ) 562 { 563 ex.printStackTrace( ); 564 assertTrue( "Unexpected Exception", false ); 565 } 566 567 verify( ); 568 } 569 570 573 public final void testExecuteRunnablelong( ) 574 { 575 final MockControl mainConfigControl = 576 createStrictControl( Configuration.class ); 577 final Configuration mainConfig = 578 (Configuration)mainConfigControl.getMock( ); 579 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 580 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 581 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 582 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 583 createChildrenConfigMock( "thread-pool", 584 new Configuration[ 0 ] ) ); 585 mainConfigControl.replay( ); 586 587 final MockControl childLoggerControl = 588 createStrictControl( Logger.class ); 589 final Logger childLogger = (Logger)childLoggerControl.getMock( ); 590 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 591 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 592 childLoggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 593 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 594 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 595 childLoggerControl.replay( ); 596 597 final MockControl loggerControl = createStrictControl( Logger.class ); 598 final Logger logger = (Logger)loggerControl.getMock( ); 599 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 600 childLogger ); 601 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 602 logger.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" ); 603 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 604 logger.debug( "Starting the heart" ); 605 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 606 logger.debug( "Entering loop" ); 607 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 608 logger.debug( "No commands available. Will just wait for one" ); 609 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 610 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=100, interval=0" ); 611 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 612 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=0" ); 613 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 614 logger.debug( "No commands available. Will just wait for one" ); 615 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 616 logger.debug( "Exiting loop" ); 617 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 618 logger.debug( "Disposing all thread pools" ); 619 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 620 logger.debug( "Disposing thread pool default" ); 621 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 622 logger.debug( "Thread pool default disposed" ); 623 loggerControl.replay( ); 624 625 final DefaultRunnableManager runnableManager = 626 new DefaultRunnableManager( ); 627 runnableManager.enableLogging( logger ); 628 629 try 630 { 631 runnableManager.configure( mainConfig ); 632 } 633 catch( final ConfigurationException ce ) 634 { 635 assertTrue( "Throw unexpected ConfigurationException", false ); 636 } 637 638 final MockControl runnableControl = 639 createStrictControl( Runnable .class ); 640 final Runnable runnable = (Runnable )runnableControl.getMock( ); 641 runnable.run( ); 642 runnableControl.replay( ); 643 644 try 645 { 646 runnableManager.start( ); 647 Thread.yield( ); 648 Thread.sleep( 20 ); 649 runnableManager.execute( runnable, 100, 0 ); 650 Thread.yield( ); 651 Thread.sleep( 200 ); 652 runnableManager.stop( ); 653 Thread.yield( ); 654 Thread.sleep( 20 ); 655 runnableManager.dispose( ); 656 Thread.sleep( 20 ); 657 } 658 catch( final Throwable ex ) 659 { 660 ex.printStackTrace( ); 661 assertTrue( "Unexpected Exception", false ); 662 } 663 664 verify( ); 665 } 666 667 670 public final void testExecuteRunnablelonglong( ) 671 { 672 final MockControl mainConfigControl = 673 createStrictControl( Configuration.class ); 674 final Configuration mainConfig = 675 (Configuration)mainConfigControl.getMock( ); 676 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 677 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 678 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 679 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 680 createChildrenConfigMock( "thread-pool", 681 new Configuration[ 0 ] ) ); 682 mainConfigControl.replay( ); 683 684 final MockControl childLoggerControl = 685 createStrictControl( Logger.class ); 686 final Logger childLogger = (Logger)childLoggerControl.getMock( ); 687 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 688 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 689 childLoggerControl.setMatcher( MockControl.ALWAYS_MATCHER ); 690 childLoggerControl.expectAndReturn( childLogger.isDebugEnabled( ), true ); 691 childLogger.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 692 childLoggerControl.replay( ); 693 694 final MockControl loggerControl = createStrictControl( Logger.class ); 695 final Logger logger = (Logger)loggerControl.getMock( ); 696 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 697 childLogger ); 698 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 699 logger.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" ); 700 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 701 logger.debug( "Starting the heart" ); 702 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 703 logger.debug( "Entering loop" ); 704 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 705 logger.debug( "No commands available. Will just wait for one" ); 706 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 707 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=default, delay=100, interval=100" ); 708 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 709 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"default\", schedule with interval=100" ); 710 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 711 logger.debug( "Exiting loop" ); 712 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 713 logger.debug( "Disposing all thread pools" ); 714 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 715 logger.debug( "Disposing thread pool default" ); 716 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 717 logger.debug( "Thread pool default disposed" ); 718 loggerControl.replay( ); 719 720 final DefaultRunnableManager runnableManager = 721 new DefaultRunnableManager( ); 722 runnableManager.enableLogging( logger ); 723 724 try 725 { 726 runnableManager.configure( mainConfig ); 727 } 728 catch( final ConfigurationException ce ) 729 { 730 assertTrue( "Throw unexpected ConfigurationException", false ); 731 } 732 733 final MockControl runnableControl = 734 createStrictControl( Runnable .class ); 735 final Runnable runnable = (Runnable )runnableControl.getMock( ); 736 runnable.run( ); 737 runnableControl.setVoidCallable( MockControl.ONE_OR_MORE ); 738 runnableControl.replay( ); 739 740 try 741 { 742 runnableManager.start( ); 743 Thread.yield( ); 744 Thread.sleep( 20 ); 745 runnableManager.execute( runnable, 100, 100 ); 746 Thread.yield( ); 747 Thread.sleep( 200 ); 748 runnableManager.stop( ); 749 Thread.yield( ); 750 Thread.sleep( 20 ); 751 runnableManager.dispose( ); 752 Thread.sleep( 20 ); 753 } 754 catch( final Throwable ex ) 755 { 756 ex.printStackTrace( ); 757 assertTrue( "Unexpected Exception", false ); 758 } 759 760 verify( ); 761 } 762 763 766 public final void testExecuteStringRunnable( ) 767 { 768 final MockControl mainConfigControl = 769 createStrictControl( Configuration.class ); 770 final Configuration mainConfig = 771 (Configuration)mainConfigControl.getMock( ); 772 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 773 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 774 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 775 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 776 createChildrenConfigMock( "thread-pool", 777 new Configuration[ 0 ] ) ); 778 mainConfigControl.replay( ); 779 780 final MockControl childLoggerDefaultControl = 781 createStrictControl( Logger.class ); 782 final Logger childLoggerDefault = 783 (Logger)childLoggerDefaultControl.getMock( ); 784 childLoggerDefaultControl.expectAndReturn( childLoggerDefault.isDebugEnabled( ), 785 true ); 786 childLoggerDefault.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 787 childLoggerDefaultControl.setMatcher( MockControl.ALWAYS_MATCHER ); 788 childLoggerDefaultControl.replay( ); 789 790 final MockControl childLoggerMyPoolControl = 791 createStrictControl( Logger.class ); 792 final Logger childLoggerMyPool = 793 (Logger)childLoggerMyPoolControl.getMock( ); 794 childLoggerMyPoolControl.expectAndReturn( childLoggerMyPool.isDebugEnabled( ), 795 true ); 796 childLoggerMyPool.debug( "Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool" ); 797 childLoggerMyPoolControl.replay( ); 798 799 final MockControl loggerControl = createStrictControl( Logger.class ); 800 final Logger logger = (Logger)loggerControl.getMock( ); 801 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 802 childLoggerDefault ); 803 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 804 logger.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" ); 805 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 806 logger.debug( "Starting the heart" ); 807 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 808 logger.debug( "Entering loop" ); 809 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 810 logger.debug( "No commands available. Will just wait for one" ); 811 loggerControl.expectAndReturn( logger.getChildLogger( "mypool" ), 812 childLoggerMyPool ); 813 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 814 logger.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" ); 815 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 816 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=0, interval=0" ); 817 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 818 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=0" ); 819 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 820 logger.debug( "No commands available. Will just wait for one" ); 821 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 822 logger.debug( "Exiting loop" ); 823 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 824 logger.debug( "Disposing all thread pools" ); 825 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 826 logger.debug( "Disposing thread pool mypool" ); 827 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 828 logger.debug( "Thread pool mypool disposed" ); 829 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 830 logger.debug( "Disposing thread pool default" ); 831 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 832 logger.debug( "Thread pool default disposed" ); 833 loggerControl.replay( ); 834 835 final DefaultRunnableManager runnableManager = 836 new DefaultRunnableManager( ); 837 runnableManager.enableLogging( logger ); 838 839 try 840 { 841 runnableManager.configure( mainConfig ); 842 } 843 catch( final ConfigurationException ce ) 844 { 845 assertTrue( "Throw unexpected ConfigurationException", false ); 846 } 847 848 final MockControl runnableControl = 849 createStrictControl( Runnable .class ); 850 final Runnable runnable = (Runnable )runnableControl.getMock( ); 851 runnable.run( ); 852 runnableControl.replay( ); 853 854 try 855 { 856 runnableManager.start( ); 857 Thread.yield( ); 858 Thread.sleep( 20 ); 859 runnableManager.createPool( "mypool", 230, 15, 12, 860 Thread.MIN_PRIORITY, false, 15500, 861 "DISCARD", false, 22200 ); 862 runnableManager.execute( "mypool", runnable ); 863 Thread.yield( ); 864 Thread.sleep( 20 ); 865 runnableManager.stop( ); 866 Thread.yield( ); 867 Thread.sleep( 20 ); 868 runnableManager.dispose( ); 869 Thread.sleep( 20 ); 870 } 871 catch( final Throwable ex ) 872 { 873 ex.printStackTrace( ); 874 assertTrue( "Unexpected Exception", false ); 875 } 876 877 verify( ); 878 } 879 880 883 public final void testExecuteStringRunnablelong( ) 884 { 885 final MockControl mainConfigControl = 886 createStrictControl( Configuration.class ); 887 final Configuration mainConfig = 888 (Configuration)mainConfigControl.getMock( ); 889 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 890 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 891 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 892 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 893 createChildrenConfigMock( "thread-pool", 894 new Configuration[ 0 ] ) ); 895 mainConfigControl.replay( ); 896 897 final MockControl childLoggerDefaultControl = 898 createStrictControl( Logger.class ); 899 final Logger childLoggerDefault = 900 (Logger)childLoggerDefaultControl.getMock( ); 901 childLoggerDefaultControl.expectAndReturn( childLoggerDefault.isDebugEnabled( ), 902 true ); 903 childLoggerDefault.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 904 childLoggerDefaultControl.setMatcher( MockControl.ALWAYS_MATCHER ); 905 childLoggerDefaultControl.replay( ); 906 907 final MockControl childLoggerMyPoolControl = 908 createStrictControl( Logger.class ); 909 final Logger childLoggerMyPool = 910 (Logger)childLoggerMyPoolControl.getMock( ); 911 childLoggerMyPoolControl.expectAndReturn( childLoggerMyPool.isDebugEnabled( ), 912 true ); 913 childLoggerMyPool.debug( "Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool" ); 914 childLoggerMyPoolControl.replay( ); 915 916 final MockControl loggerControl = createStrictControl( Logger.class ); 917 final Logger logger = (Logger)loggerControl.getMock( ); 918 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 919 childLoggerDefault ); 920 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 921 logger.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" ); 922 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 923 logger.debug( "Starting the heart" ); 924 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 925 logger.debug( "Entering loop" ); 926 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 927 logger.debug( "No commands available. Will just wait for one" ); 928 loggerControl.expectAndReturn( logger.getChildLogger( "mypool" ), 929 childLoggerMyPool ); 930 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 931 logger.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" ); 932 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 933 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=100, interval=0" ); 934 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 935 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=0" ); 936 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 937 logger.debug( "No commands available. Will just wait for one" ); 938 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 939 logger.debug( "Exiting loop" ); 940 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 941 logger.debug( "Disposing all thread pools" ); 942 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 943 logger.debug( "Disposing thread pool mypool" ); 944 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 945 logger.debug( "Thread pool mypool disposed" ); 946 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 947 logger.debug( "Disposing thread pool default" ); 948 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 949 logger.debug( "Thread pool default disposed" ); 950 loggerControl.replay( ); 951 952 final DefaultRunnableManager runnableManager = 953 new DefaultRunnableManager( ); 954 runnableManager.enableLogging( logger ); 955 956 try 957 { 958 runnableManager.configure( mainConfig ); 959 } 960 catch( final ConfigurationException ce ) 961 { 962 assertTrue( "Throw unexpected ConfigurationException", false ); 963 } 964 965 final MockControl runnableControl = 966 createStrictControl( Runnable .class ); 967 final Runnable runnable = (Runnable )runnableControl.getMock( ); 968 runnable.run( ); 969 runnableControl.replay( ); 970 971 try 972 { 973 runnableManager.start( ); 974 Thread.yield( ); 975 Thread.sleep( 20 ); 976 runnableManager.createPool( "mypool", 230, 15, 12, 977 Thread.MIN_PRIORITY, false, 15500, 978 "DISCARD", false, 22200 ); 979 runnableManager.execute( "mypool", runnable, 100, 0 ); 980 Thread.yield( ); 981 Thread.sleep( 200 ); 982 runnableManager.stop( ); 983 Thread.yield( ); 984 Thread.sleep( 20 ); 985 runnableManager.dispose( ); 986 Thread.sleep( 20 ); 987 } 988 catch( final Throwable ex ) 989 { 990 ex.printStackTrace( ); 991 assertTrue( "Unexpected Exception", false ); 992 } 993 994 verify( ); 995 } 996 997 1000 public final void testExecuteStringRunnablelonglong( ) 1001 { 1002 final MockControl mainConfigControl = 1003 createStrictControl( Configuration.class ); 1004 final Configuration mainConfig = 1005 (Configuration)mainConfigControl.getMock( ); 1006 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-factory" ), 1007 createValueConfigMock( DefaultRunnableManager.DEFAULT_THREAD_FACTORY, 1008 DefaultRunnableManager.DEFAULT_THREAD_FACTORY ) ); 1009 mainConfigControl.expectAndReturn( mainConfig.getChild( "thread-pools" ), 1010 createChildrenConfigMock( "thread-pool", 1011 new Configuration[ 0 ] ) ); 1012 mainConfigControl.replay( ); 1013 1014 final MockControl childLoggerDefaultControl = 1015 createStrictControl( Logger.class ); 1016 final Logger childLoggerDefault = 1017 (Logger)childLoggerDefaultControl.getMock( ); 1018 childLoggerDefaultControl.expectAndReturn( childLoggerDefault.isDebugEnabled( ), 1019 true ); 1020 childLoggerDefault.debug( "Executing Command: org.apache.cocoon.components.thread.DefaultRunnableManager" ); 1021 childLoggerDefaultControl.setMatcher( MockControl.ALWAYS_MATCHER ); 1022 childLoggerDefaultControl.replay( ); 1023 1024 final MockControl childLoggerMyPoolControl = 1025 createStrictControl( Logger.class ); 1026 final Logger childLoggerMyPool = 1027 (Logger)childLoggerMyPoolControl.getMock( ); 1028 childLoggerMyPoolControl.expectAndReturn( childLoggerMyPool.isDebugEnabled( ), 1029 true ); 1030 childLoggerMyPool.debug( "Executing Command: EasyMock for interface java.lang.Runnable,pool=mypool" ); 1031 childLoggerMyPoolControl.replay( ); 1032 1033 final MockControl loggerControl = createStrictControl( Logger.class ); 1034 final Logger logger = (Logger)loggerControl.getMock( ); 1035 loggerControl.expectAndReturn( logger.getChildLogger( "default" ), 1036 childLoggerDefault ); 1037 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 1038 logger.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" ); 1039 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1040 logger.debug( "Starting the heart" ); 1041 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1042 logger.debug( "Entering loop" ); 1043 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1044 logger.debug( "No commands available. Will just wait for one" ); 1045 loggerControl.expectAndReturn( logger.getChildLogger( "mypool" ), 1046 childLoggerMyPool ); 1047 loggerControl.expectAndReturn( logger.isInfoEnabled( ), true ); 1048 logger.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" ); 1049 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1050 logger.debug( "Command entered: EasyMock for interface java.lang.Runnable, pool=mypool, delay=100, interval=100" ); 1051 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1052 logger.debug( "Executing command EasyMock for interface java.lang.Runnable in pool \"mypool\", schedule with interval=100" ); 1053 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1054 logger.debug( "Exiting loop" ); 1055 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1056 logger.debug( "Disposing all thread pools" ); 1057 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1058 logger.debug( "Disposing thread pool mypool" ); 1059 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1060 logger.debug( "Thread pool mypool disposed" ); 1061 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1062 logger.debug( "Disposing thread pool default" ); 1063 loggerControl.expectAndReturn( logger.isDebugEnabled( ), true ); 1064 logger.debug( "Thread pool default disposed" ); 1065 loggerControl.replay( ); 1066 1067 final DefaultRunnableManager runnableManager = 1068 new DefaultRunnableManager( ); 1069 runnableManager.enableLogging( logger ); 1070 1071 try 1072 { 1073 runnableManager.configure( mainConfig ); 1074 } 1075 catch( final ConfigurationException ce ) 1076 { 1077 assertTrue( "Throw unexpected ConfigurationException", false ); 1078 } 1079 1080 final MockControl runnableControl = 1081 createStrictControl( Runnable .class ); 1082 final Runnable runnable = (Runnable )runnableControl.getMock( ); 1083 runnable.run( ); 1084 runnableControl.replay( ); 1085 1086 try 1087 { 1088 runnableManager.start( ); 1089 Thread.yield( ); 1090 Thread.sleep( 20 ); 1091 runnableManager.createPool( "mypool", 230, 15, 12, 1092 Thread.MIN_PRIORITY, false, 15500, 1093 "DISCARD", false, 22200 ); 1094 runnableManager.execute( "mypool", runnable, 100, 100 ); 1095 Thread.yield( ); 1096 Thread.sleep( 200 ); 1097 runnableManager.stop( ); 1098 Thread.yield( ); 1099 Thread.sleep( 20 ); 1100 runnableManager.dispose( ); 1101 Thread.sleep( 20 ); 1102 } 1103 catch( final Throwable ex ) 1104 { 1105 ex.printStackTrace( ); 1106 assertTrue( "Unexpected Exception", false ); 1107 } 1108 1109 verify( ); 1110 } 1111} 1112 | Popular Tags |