1 /* 2 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * you may not use this file except in compliance with the License. 4 * You may obtain a copy of the License at 5 * 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 package net.sourceforge.basher; 16 17 /** 18 * Defines the context parameters for a performance or testing run. 19 * 20 * @author Johan Lindquist 21 * @version $Revision$ 22 */ 23 public class BasherContext 24 { 25 private boolean manuallyControlled = false; 26 27 private long setupDuration = 10; 28 private long warmupDuration = 0; 29 private long runDuration = 0; 30 private long cooldownDuration = 10; 31 private long teardownDuration = 0; 32 33 private long startCollectionFrom = 0; 34 private long stopCollectionAfter = 0; 35 36 private int initialNumberThreads = 10; 37 private int maxNumberThreads = 0; 38 private int threadIncrementCount = 0; 39 private int threadIncrementInterval = 0; 40 41 private int taskMinDelay = 0; 42 private int taskMaxDelay = 0; 43 44 private long markAverageInterval = 10; 45 46 private String beanShellScriptDirectory = "src/test/basher-scripts"; 47 48 private String runIdentifier; 49 50 private String reportDirectory = "target/basher-reports"; 51 52 private ExecutionType executionType; 53 54 private String name; 55 56 private String includes; 57 58 private String excludes; 59 60 private ProfilerContext profilerContext; 61 62 /** 63 * Retrieves the includes expression for tasks to be included in the run defined by this context. Defined 64 * as a comma separated strings of task names (fully qualified package + task name). Wild-cards allowed. 65 * e.g. An expression of <i>net.sourceforge.*</i> would retrieve all tasks under the <i>net.sourceforge</i> package 66 * 67 * @return The include expression 68 */ 69 public String getIncludes() 70 { 71 return includes; 72 } 73 74 /** 75 * Sets the includes expression for tasks to be included in the run defined by this context. Defined 76 * as a comma separated strings of task names (fully qualified package + task name). Wild-cards allowed. 77 * e.g. An expression of <i>net.sourceforge.*</i> would retrieve all tasks under the <i>net.sourceforge</i> package 78 * 79 * @param includes The include expression 80 */ 81 public void setIncludes( final String includes ) 82 { 83 this.includes = includes; 84 } 85 86 /** 87 * Sets the includes expression for tasks to be included in the run defined by this context. Defined 88 * as a comma separated strings of task names (fully qualified package + task name). Wild-cards allowed. 89 * e.g. An expression of <i>net.sourceforge.*</i> would retrieve all tasks under the <i>net.sourceforge</i> package 90 * 91 * @return The exclude expression 92 */ 93 public String getExcludes() 94 { 95 return excludes; 96 } 97 98 /** 99 * Sets the includes expression for tasks to be included in the run defined by this context. Defined 100 * as a comma separated strings of task names (fully qualified package + task name). Wild-cards allowed. 101 * e.g. An expression of <i>net.sourceforge.*</i> would retrieve all tasks under the <i>net.sourceforge</i> package 102 * 103 * @return The exclude expression 104 */ 105 public void setExcludes( final String excludes ) 106 { 107 this.excludes = excludes; 108 } 109 110 /** 111 * Retrieves the duration (in seconds) of the warm-up run. The length defined here defines how long tasks (and the JVM) are 112 * run as part of warm-up.<br/> 113 * If not set, this default to 0 seconds (no warm-up). 114 * 115 * @return The duration (in seconds) of the setup run 116 */ 117 public long getWarmupDuration() 118 { 119 return warmupDuration; 120 } 121 122 /** 123 * Sets the duration (in seconds) of the warm-up run. The length defined here defines how long tasks (and the JVM) are 124 * run as part of the warm-up phase.<br/> 125 * If not set, this default to 0 seconds (no warm-up). 126 * 127 * @param warmupDuration The duration (in seconds) of the setup run 128 */ 129 public void setWarmupDuration( final long warmupDuration ) 130 { 131 this.warmupDuration = warmupDuration; 132 } 133 134 /** 135 * Sets the duration (in seconds) of the tear-down run. The length defined here defines how long tasks (and the JVM) are 136 * run as part of the tear-down phase.<br/> 137 * If not set, this default to 0 seconds (no tear-down). 138 * 139 * @return The duration (in seconds) of the setup run 140 */ 141 public long getTeardownDuration() 142 { 143 return teardownDuration; 144 } 145 146 /** 147 * Sets the duration (in seconds) of the tear-down run. The length defined here defines how long tasks (and the JVM) are 148 * run as part of the tear-down phase.<br/> 149 * If not set, this default to 0 seconds (no tear-down). 150 * 151 * @param teardownDuration The duration (in seconds) of the setup run 152 */ 153 public void setTeardownDuration( final long teardownDuration ) 154 { 155 this.teardownDuration = teardownDuration; 156 } 157 158 /** 159 * Retrieves the Beanshell directory that should be used for initialization scripts. This is relative to the working 160 * directory or a full path.<br/> 161 * If not set, this defaults to 'src/test/basher-scripts'. 162 * 163 * @return The path of the Beanshell directory 164 */ 165 public String getBeanShellScriptDirectory() 166 { 167 return beanShellScriptDirectory; 168 } 169 170 /** 171 * Sets the Beanshell directory that should be used for initialization scripts. This is relative to the working 172 * directory or a full path.<br/> 173 * If not set, this defaults to 'src/test/basher-scripts'. 174 * 175 * @param beanShellScriptDirectory The BeanShell directory to use 176 */ 177 public void setBeanShellScriptDirectory( final String beanShellScriptDirectory ) 178 { 179 this.beanShellScriptDirectory = beanShellScriptDirectory; 180 } 181 182 /** 183 * Retrieves the time (in seconds) when statistics collection should begin. This time is relative to the start of the 184 * run. 185 * 186 * @return The time, relative from the start of the run, when collection should start 187 */ 188 public long getStartCollectionFrom() 189 { 190 return startCollectionFrom; 191 } 192 193 /** 194 * Sets the time (in seconds) when statistics collection should begin. This time is relative to the start of the 195 * run. 196 * 197 * @param startCollectionFrom The time, relative from the start of the run, when collection should start 198 */ 199 public void setStartCollectionFrom( final long startCollectionFrom ) 200 { 201 this.startCollectionFrom = startCollectionFrom; 202 } 203 204 /** 205 * Retrieves the time (in seconds) when statistics collection should stop. This time is relative to the start of the 206 * run. 207 * 208 * @return The time, relative from the start of the run, when collection should stop 209 */ 210 public long getStopCollectionAfter() 211 { 212 return stopCollectionAfter; 213 } 214 215 /** 216 * Sets the time (in seconds) when statistics collection should stop. This time is relative to the start of the 217 * run. 218 * 219 * @param stopCollectionAfter The time, relative from the start of the run, when collection should stop 220 */ 221 public void setStopCollectionAfter( final long stopCollectionAfter ) 222 { 223 this.stopCollectionAfter = stopCollectionAfter; 224 } 225 226 /** 227 * Retrieves the number of threads which the run should start with. Defaults to 10 228 * 229 * @return The number of threads the run should start with 230 */ 231 public int getInitialNumberThreads() 232 { 233 return initialNumberThreads; 234 } 235 236 /** 237 * Sets the number of threads which the run should start with.<br/> 238 * If not set, this defaults to 10 239 * 240 * @param initialNumberThreads The number of threads the run should start with 241 */ 242 public void setInitialNumberThreads( final int initialNumberThreads ) 243 { 244 this.initialNumberThreads = initialNumberThreads; 245 } 246 247 /** 248 * Retrieves the maximum number of threads allowed in the run. Defaults to 0 (unlimited). This is mainly taken 249 * into account in combination with {@link net.sourceforge.basher.BasherContext#setThreadIncrementCount(int)} and 250 * {@link net.sourceforge.basher.BasherContext#setThreadIncrementInterval(int)}. 251 * 252 * @return The number of threads the run should start with 253 */ 254 public int getMaxNumberThreads() 255 { 256 return maxNumberThreads; 257 } 258 259 /** 260 * Sets the maximum number of threads allowed in the run. This is mainly taken 261 * into account in combination with {@link net.sourceforge.basher.BasherContext#setThreadIncrementCount(int)} and 262 * {@link net.sourceforge.basher.BasherContext#setThreadIncrementInterval(int)}.<br/> 263 * If not set, this defaults to 0 (unlimited). 264 * 265 * @param maxNumberThreads The number of threads the run should start with 266 */ 267 public void setMaxNumberThreads( final int maxNumberThreads ) 268 { 269 this.maxNumberThreads = maxNumberThreads; 270 } 271 272 /** 273 * Sets the number of threads should be added for each <i>threadIncrementInterval</i> allowed in the run.<br/> 274 * If not set, this defaults to 0 (don't add any) 275 * 276 * @return The number of threads to add 277 */ 278 public int getThreadIncrementCount() 279 { 280 return threadIncrementCount; 281 } 282 283 /** 284 * Retrieves the number of threads should be added for each <i>threadIncrementInterval</i> allowed in the run.<br/> 285 * If not set, this defaults to 0 (don't add any) 286 * 287 * @param threadIncrementCount The number of threads to add 288 */ 289 public void setThreadIncrementCount( final int threadIncrementCount ) 290 { 291 this.threadIncrementCount = threadIncrementCount; 292 } 293 294 /** 295 * Retrieves the interval (in seconds) between each attempt at adding more threads. This will be done up till the 296 * <i>maxNumberThreads</i> is reached.<br/> 297 * If not set, this defaults to 0 (don't increment) 298 * 299 * @return The interval between adding threads (in seconds) 300 */ 301 public int getThreadIncrementInterval() 302 { 303 return threadIncrementInterval; 304 } 305 306 /** 307 * Sets the interval (in seconds) between each attempt at adding more threads. This will be done, adding <i></i> 308 * number of threads each time, until the <i>maxNumberThreads</i> limit is reached.<br/> 309 * If not set, this defaults to 0 (don't increment) 310 * 311 * @param threadIncrementInterval The interval between adding threads (in seconds) 312 */ 313 public void setThreadIncrementInterval( final int threadIncrementInterval ) 314 { 315 this.threadIncrementInterval = threadIncrementInterval; 316 } 317 318 /** 319 * Retrieves the minimum delay between running tasks. This is mainly used to stagger the tasks.<br/> 320 * If not set, this defaults to 0 (no delay). 321 * 322 * @return The minimum task delay (in milliseconds) 323 */ 324 public int getTaskMinDelay() 325 { 326 return taskMinDelay; 327 } 328 329 /** 330 * Sets the minimum delay between running tasks. This is mainly used to stagger the tasks.<br/> 331 * If not set, this defaults to 0 (no delay). 332 * 333 * @param taskMinDelay The maximum task delay (in milliseconds) 334 */ 335 public void setTaskMinDelay( final int taskMinDelay ) 336 { 337 this.taskMinDelay = taskMinDelay; 338 } 339 340 /** 341 * Retrieves the maximum delay between running tasks. This is mainly used to stagger the tasks.<br/> 342 * If not set, this defaults to 0 (no delay). 343 * 344 * @return The maximum task delay (in milliseconds) 345 */ 346 public int getTaskMaxDelay() 347 { 348 return taskMaxDelay; 349 } 350 351 /** 352 * Sets the maximum delay between running tasks. This is mainly used to stagger the tasks.<br/> 353 * If not set, this defaults to 0 (no delay). 354 * 355 * @param taskMaxDelay The maximum task delay (in milliseconds) 356 */ 357 public void setTaskMaxDelay( final int taskMaxDelay ) 358 { 359 this.taskMaxDelay = taskMaxDelay; 360 } 361 362 /** 363 * Retrieves the interval between average calculations (in seconds). 364 * 365 * @return The time between average calculations (in seconds) 366 */ 367 public long getMarkAverageInterval() 368 { 369 return markAverageInterval; 370 } 371 372 /** 373 * Sets the interval between average calculations (in seconds). 374 * 375 * @param markAverageInterval The time between average calculations (in seconds) 376 */ 377 public void setMarkAverageInterval( final long markAverageInterval ) 378 { 379 this.markAverageInterval = markAverageInterval; 380 } 381 382 383 /** 384 * Retrieves the name of this Basher context. 385 * 386 * @return The name of the context 387 */ 388 public String getName() 389 { 390 return name; 391 } 392 393 /** 394 * Sets the name of this Basher context. 395 * 396 * @param name The name of the Basher context 397 */ 398 public void setName( final String name ) 399 { 400 this.name = name; 401 } 402 403 /** 404 * Retrieves the report directory to be used for the running.<br/> 405 * If not set, this defaults to 'target/basher-reports'. 406 * 407 * @return The report directory 408 */ 409 public String getReportDirectory() 410 { 411 return reportDirectory; 412 } 413 414 /** 415 * Sets the report directory to be used for the running.<br/> 416 * If not set, this defaults to 'target/basher-reports'. 417 * 418 * @param reportDirectory The report directory 419 */ 420 public void setReportDirectory( final String reportDirectory ) 421 { 422 this.reportDirectory = reportDirectory; 423 } 424 425 /** 426 * Retrieves the duration (in seconds) of the setup run. The length defined here defines how long tasks (and the JVM) are 427 * run (and how 'warmed up' the JVM could be before starting statistics collection).<br/> 428 * If not set, this default to 10 seconds. 429 * 430 * @return The duration (in seconds) of the setup run 431 */ 432 public long getSetupDuration() 433 { 434 return setupDuration; 435 } 436 437 /** 438 * Sets the duration (in seconds) of the setup run. The length defined here defines how long tasks (and the JVM) are 439 * run (and how 'warmed up' the JVM could be before starting statistics collection).<br/> 440 * If not set, this default to 10 seconds. 441 * 442 * @param setupDuration The duration (in seconds) of the setup run 443 */ 444 public void setSetupDuration( final long setupDuration ) 445 { 446 this.setupDuration = setupDuration; 447 } 448 449 /** 450 * Retrieves the duration (in seconds) of the run. The length defined here defines how long statistics are 451 * collected for.<br/> 452 * 453 * @return The duration (in seconds) of the run 454 */ 455 public long getRunDuration() 456 { 457 return runDuration; 458 } 459 460 /** 461 * Sets the duration (in seconds) of the run. The length defined here defines how long statistics are 462 * collected for.<br/> 463 * 464 * @param runDuration The duration (in seconds) of the run 465 */ 466 public void setRunDuration( final long runDuration ) 467 { 468 this.runDuration = runDuration; 469 } 470 471 /** 472 * Retrieves the duration (in seconds) of the cooldown run. The length defined here defines how long tasks are 473 * run for after stopping collection.<br/> 474 * If not set, this default to 10 seconds. 475 * 476 * @return The duration (in seconds) of the setup run 477 */ 478 public long getCooldownDuration() 479 { 480 return cooldownDuration; 481 } 482 483 /** 484 * Sets the duration (in seconds) of the cooldown run. The length defined here defines how long tasks are 485 * run for after stopping collection.<br/> 486 * If not set, this default to 10 seconds. 487 * 488 * @param cooldownDuration The duration (in seconds) of the setup run 489 */ 490 public void setCooldownDuration( final long cooldownDuration ) 491 { 492 this.cooldownDuration = cooldownDuration; 493 } 494 495 /** 496 * @return 497 */ 498 public ExecutionType getExecutionType() 499 { 500 return executionType; 501 } 502 503 /** 504 * @param executionType 505 */ 506 public void setExecutionType( final ExecutionType executionType ) 507 { 508 this.executionType = executionType; 509 } 510 511 /** Retrieves the run identifier to use. If not specified, one will be generated. 512 * @return The run identifier 513 */ 514 public String getRunIdentifier() 515 { 516 return runIdentifier; 517 } 518 519 /** Specifies the run identifier to use. If not set, one will be generated 520 * @param runIdentifier The run identifier 521 */ 522 public void setRunIdentifier( final String runIdentifier ) 523 { 524 this.runIdentifier = runIdentifier; 525 } 526 527 /** Flag indicating whether or not the run is controlled by the user, through the APIs or BeanShell. This 528 * defaults to false, runs being controlled by Basher. 529 * 530 * @return True if the user controls the runs, otherwise false 531 */ 532 public boolean isManuallyControlled() 533 { 534 return manuallyControlled; 535 } 536 537 /** Flag indicating whether or not the run is controlled by the user. This defaults to false, runs being controlled by Basher. 538 * 539 * @param manuallyControlled True if the user should control the runs, otherwise false 540 */ 541 public void setManuallyControlled( final boolean manuallyControlled ) 542 { 543 this.manuallyControlled = manuallyControlled; 544 } 545 546 /** 547 * 548 * @return 549 */ 550 public ProfilerContext getProfilerContext() 551 { 552 return profilerContext; 553 } 554 555 /** 556 * 557 * @param profilerContext 558 */ 559 public void setProfilerContext(final ProfilerContext profilerContext) 560 { 561 this.profilerContext = profilerContext; 562 } 563 564 @Override 565 public boolean equals(final Object o) 566 { 567 if (this == o) 568 { 569 return true; 570 } 571 if (o == null || getClass() != o.getClass()) 572 { 573 return false; 574 } 575 576 final BasherContext that = (BasherContext) o; 577 578 if (cooldownDuration != that.cooldownDuration) 579 { 580 return false; 581 } 582 if (initialNumberThreads != that.initialNumberThreads) 583 { 584 return false; 585 } 586 if (manuallyControlled != that.manuallyControlled) 587 { 588 return false; 589 } 590 if (markAverageInterval != that.markAverageInterval) 591 { 592 return false; 593 } 594 if (maxNumberThreads != that.maxNumberThreads) 595 { 596 return false; 597 } 598 if (runDuration != that.runDuration) 599 { 600 return false; 601 } 602 if (setupDuration != that.setupDuration) 603 { 604 return false; 605 } 606 if (startCollectionFrom != that.startCollectionFrom) 607 { 608 return false; 609 } 610 if (stopCollectionAfter != that.stopCollectionAfter) 611 { 612 return false; 613 } 614 if (taskMaxDelay != that.taskMaxDelay) 615 { 616 return false; 617 } 618 if (taskMinDelay != that.taskMinDelay) 619 { 620 return false; 621 } 622 if (teardownDuration != that.teardownDuration) 623 { 624 return false; 625 } 626 if (threadIncrementCount != that.threadIncrementCount) 627 { 628 return false; 629 } 630 if (threadIncrementInterval != that.threadIncrementInterval) 631 { 632 return false; 633 } 634 if (warmupDuration != that.warmupDuration) 635 { 636 return false; 637 } 638 if (beanShellScriptDirectory != null ? !beanShellScriptDirectory.equals(that.beanShellScriptDirectory) : that.beanShellScriptDirectory != null) 639 { 640 return false; 641 } 642 if (excludes != null ? !excludes.equals(that.excludes) : that.excludes != null) 643 { 644 return false; 645 } 646 if (executionType != null ? !executionType.equals(that.executionType) : that.executionType != null) 647 { 648 return false; 649 } 650 if (includes != null ? !includes.equals(that.includes) : that.includes != null) 651 { 652 return false; 653 } 654 if (name != null ? !name.equals(that.name) : that.name != null) 655 { 656 return false; 657 } 658 if (profilerContext != null ? !profilerContext.equals(that.profilerContext) : that.profilerContext != null) 659 { 660 return false; 661 } 662 if (reportDirectory != null ? !reportDirectory.equals(that.reportDirectory) : that.reportDirectory != null) 663 { 664 return false; 665 } 666 if (runIdentifier != null ? !runIdentifier.equals(that.runIdentifier) : that.runIdentifier != null) 667 { 668 return false; 669 } 670 671 return true; 672 } 673 674 @Override 675 public String toString() 676 { 677 return "BasherContext{" + 678 "manuallyControlled=" + manuallyControlled + 679 ", setupDuration=" + setupDuration + 680 ", warmupDuration=" + warmupDuration + 681 ", runDuration=" + runDuration + 682 ", cooldownDuration=" + cooldownDuration + 683 ", teardownDuration=" + teardownDuration + 684 ", startCollectionFrom=" + startCollectionFrom + 685 ", stopCollectionAfter=" + stopCollectionAfter + 686 ", initialNumberThreads=" + initialNumberThreads + 687 ", maxNumberThreads=" + maxNumberThreads + 688 ", threadIncrementCount=" + threadIncrementCount + 689 ", threadIncrementInterval=" + threadIncrementInterval + 690 ", taskMinDelay=" + taskMinDelay + 691 ", taskMaxDelay=" + taskMaxDelay + 692 ", markAverageInterval=" + markAverageInterval + 693 ", beanShellScriptDirectory='" + beanShellScriptDirectory + '\'' + 694 ", runIdentifier='" + runIdentifier + '\'' + 695 ", reportDirectory='" + reportDirectory + '\'' + 696 ", executionType=" + executionType + 697 ", name='" + name + '\'' + 698 ", includes='" + includes + '\'' + 699 ", excludes='" + excludes + '\'' + 700 ", profilerContext=" + profilerContext + 701 '}'; 702 } 703 }