Class: Blazemeter::Command::Test
- Inherits:
-
Blazemeter::Command
- Object
- Blazemeter::Command
- Blazemeter::Command::Test
- Extended by:
- Utils
- Defined in:
- lib/blazemeter/command/test.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Blazemeter::Command
Class Method Summary collapse
Instance Method Summary collapse
- #cmd_create(argv) ⇒ Object
- #cmd_options(argv) ⇒ Object
- #cmd_query(argv) ⇒ Object
- #cmd_start(argv) ⇒ Object
- #cmd_status(argv) ⇒ Object
- #cmd_stop(argv) ⇒ Object
- #cmd_update(argv) ⇒ Object
Methods included from Utils
Class Method Details
.parse(arguments) ⇒ Object
451 452 453 454 455 456 457 |
# File 'lib/blazemeter/command/test.rb', line 451 def self.parse arguments argv = arguments.is_a?(Array) ? arguments : '' args = parse_cli argv raise "help" if args['help'] args end |
.parse_cli(argv) ⇒ Object
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/blazemeter/command/test.rb', line 459 def self.parse_cli argv hash = { 'steps' => [] } hash["options"] = Hash.new while not argv.empty? hash['steps'] << Hash.new step = hash['steps'].last while not argv.empty? break if argv.first[0,1] != '-' k = argv.shift if ['-u'].member? k hash['options']['USERS'] = shift(k, argv) next end if ['-n'].member? k hash['test_name'] = shift(k, argv) next end if ['-l'].member? k hash['options']['LOCATION'] = shift(k, argv) next end if ['-id'].member? k hash['test_id'] = shift(k, argv) next end if ['-j'].member? k hash['options']['JMETER_VERSION'] = shift(k, argv).to_f next end if ['-r'].member? k hash['options']['OVERRIDE_RAMP_UP'] = shift(k, argv).to_i next end if ['-i'].member? k hash['options']['OVERRIDE_ITERATIONS'] = shift(k, argv).to_i next end if ['-d'].member? k hash['options']['OVERRIDE_DURATION'] = shift(k, argv).to_i next end if ['-en'].member? k hash['options']['NUMBER_OF_ENGINES'] = shift(k, argv).to_i next end if ['-jmx'].member? k hash['jmx_filepath'] = shift(k, argv).to_i next end if ['-a'].member? k hash['apikey'] = shift(k, argv).to_i next end raise ArgumentError, "Unknown option #{k}" end break if hash['help'] end if not hash['help'] #if hash['steps'].empty? # raise ArgumentError, "no options specified!" #end end hash end |
Instance Method Details
#cmd_create(argv) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/blazemeter/command/test.rb', line 9 def cmd_create argv = Hash.new ["options"] = Hash.new begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end vars = Blazemeter::Command::Test.parse argv vars["options"]["TEST_TYPE"] = "jmeter" #hardcoded until next version #todo: check if this can be on even if we don't override anything #todo: move to blazemeter.rb vars["options"]["OVERRIDE"] = 1 #turn on overriding if !vars["test_name"] puts "Enter name for the test: " user_input = gets if user_input.chomp != "" vars["test_name"] = user_input.chomp end end if !vars["options"]["LOCATION"] puts "Enter location(Default - Virginia, California, Oregon, Ireland, Sydney, Tokyo, Singapore, Sao Paulo): " user_input = gets if user_input.chomp != "" vars["options"]["LOCATION"] = user_input.chomp end end if !vars["jmx_filepath"] puts "Enter a path to a JMX file:* " user_input = gets.chomp while user_input.empty? || !File.exist?(user_input) do if !user_input.empty? && !File.exist?(user_input) puts "File doesn't exist. Please enter absolute path, or relative to the "+Dir.pwd end puts "* mandatory field." puts "Enter a path to a JMX file:* " user_input = gets.chomp end vars["jmx_filepath"] = user_input end if !vars["options"]["JMETER_VERSION"] puts "Enter Jmeter version(Default - 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3.2): " user_input = gets if user_input.chomp != "" vars["options"]["JMETER_VERSION"] = user_input.chomp.to_f end end if !vars["options"]["OVERRIDE_RAMP_UP"] puts "Enter ramp up(300sec): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_RAMP_UP"] = user_input.chomp.to_i end end if !vars["options"]["OVERRIDE_ITERATIONS"] puts "Enter iterations(forever): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_ITERATIONS"] = user_input.chomp.to_i end end if !vars["options"]["OVERRIDE_DURATION"] puts "Enter duration(forever): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_DURATION"] = user_input.chomp.to_i end end if vars["options"]["TEST_TYPE"] == "jmeter" # NUMBER_OF_ENGINES only available if JMeter test was selected in TEST_TYPE if !vars["options"]["NUMBER_OF_ENGINES"] #todo: get the limits puts "Enter number of engines(Default- auto, [1-60]): " user_input = gets.chomp while user_input != "" && (user_input.to_i < 1 || user_input.to_i > 60) if(user_input.to_i < 1 || user_input.to_i > 60) puts "Value must be between 1-60" end puts "Enter number of engines(Default- auto, [1-60]): " user_input = gets.chomp end if user_input != "" vars["options"]["NUMBER_OF_ENGINES"] = user_input.to_i end end else #make sure this option isn't passed in case of other test_types vars["options"].delete("NUMBER_OF_ENGINES") end if vars["options"]["NUMBER_OF_ENGINES"] #[Auto] wasn't selected in NUMBER_OF_ENGINES user_text = "Maximum number of concurrent users per load engine[20-36000]" else #[Auto] Was selected in NUMBER_OF_ENGINES user_text = "Maximum number of concurrent users[20-36000]" end if !vars["options"]["USERS"] #mandatory field puts "Enter "+user_text+":" user_input = gets.chomp while user_input.empty? || (user_input.to_i < 20 || user_input.to_i > 36000) do if !user_input.empty? && (user_input.to_i < 20 || user_input.to_i > 36000) puts "Incorrect value. " end puts "* mandatory field." puts "Enter "+user_text+":*" user_input = gets.chomp end vars["options"]["USERS"] = user_input end if vars["options"]["NUMBER_OF_ENGINES"] && vars["options"]["USERS"] #[Auto] wasn't selected in NUMBER_OF_ENGINES vars["options"]["OVERRIDE_THREADS"] = vars["options"]["USERS"] vars["options"].delete("USERS") end if vars["test_name"] test_name = vars["test_name"] end ["options"] = vars["options"] blaze = BlazemeterApi.new(user_key) test_id = blaze.testCreate(test_name, ) if test_id #Upload JMX script filename = File.basename(vars["jmx_filepath"]) blaze.testScriptUpload(test_id, vars["jmx_filepath"], filename) end rescue "help" return help end end |
#cmd_options(argv) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/blazemeter/command/test.rb', line 392 def argv begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end vars = Blazemeter::Command::Test.parse argv if !vars["test_id"] puts "Enter test id: " user_input = gets vars["test_id"] = user_input.chomp end if vars["test_id"] == '' puts "Test id is required" exit end blaze = BlazemeterApi.new(user_key) status = blaze.testGetStatus(vars["test_id"], true) if !status["error"] and status["response_code"] == 200 puts "BlazeMeter options: " puts status else puts "Error retrieving status: " + status["error"] end rescue "help" return help end end |
#cmd_query(argv) ⇒ Object
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/blazemeter/command/test.rb', line 426 def cmd_query argv begin user_key = Blazemeter::Common.get_user_key vars = Blazemeter::Command::Test.parse argv if !vars["test_id"] puts "Enter test id: " user_input = gets if user_input.chomp != "" test_id = user_input.chomp else puts "Test id is required" exit end else test_id = vars["test_id"] end blaze = BlazemeterApi.new(user_key) blaze.testGetArchive(test_id) rescue "help" return help end end |
#cmd_start(argv) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/blazemeter/command/test.rb', line 158 def cmd_start argv begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end vars = Blazemeter::Command::Test.parse argv if !vars["test_id"] puts "Enter test id: " user_input = gets vars["test_id"] = user_input.chomp end if vars["test_id"] == '' puts "Test id is required" exit end blaze = BlazemeterApi.new(user_key) blaze.testStart(vars["test_id"]) rescue "help" return help end end |
#cmd_status(argv) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/blazemeter/command/test.rb', line 359 def cmd_status argv begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end vars = Blazemeter::Command::Test.parse argv if !vars["test_id"] puts "Enter test id: " user_input = gets vars["test_id"] = user_input.chomp end if vars["test_id"] == '' puts "Test id is required" exit end blaze = BlazemeterApi.new(user_key) status = blaze.testGetStatus(vars["test_id"]) if !status["error"] and status["response_code"] == 200 puts "BlazeMeter status: " + status["status"] else puts "Error retrieving status: " + status["error"] end rescue "help" return help end end |
#cmd_stop(argv) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/blazemeter/command/test.rb', line 183 def cmd_stop argv begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end vars = Blazemeter::Command::Test.parse argv if !vars["test_id"] puts "Enter test id: " user_input = gets vars["test_id"] = user_input.chomp end if vars["test_id"] == '' puts "Test id is required" exit end blaze = BlazemeterApi.new(user_key) blaze.testStop(vars["test_id"]) rescue "help" return help end end |
#cmd_update(argv) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/blazemeter/command/test.rb', line 208 def cmd_update argv = Hash.new ["options"] = Hash.new begin user_key = Blazemeter::Common.get_user_key if !user_key puts "You must enter API Key. Use blazemeter api:init" return end blaze = BlazemeterApi.new(user_key) vars = Blazemeter::Command::Test.parse argv #todo: we need to check test type from existing test test_type = "jmeter" #hardcoded until next version #todo: check if this can be on even if we don't override anything vars["options"]["OVERRIDE"] = 1 #turn on overriding if !vars["test_id"] puts "Enter test id: " user_input = gets if user_input.chomp != "" test_id = user_input.chomp else puts "Test id is required" exit end else test_id = vars["test_id"] end old_vars = blaze.testGetStatus(test_id, true) if !vars["options"]["LOCATION"] puts "Enter location(Default - don't change, California, Oregon, Ireland, Sydney, Tokyo, Singapore, Sao Paulo): " user_input = gets if user_input.chomp != "" vars["options"]["LOCATION"] = user_input.chomp end end if !vars["jmx_filepath"] puts "Enter a path to a JMX file(don't change): " user_input = gets.chomp while !user_input.empty? && !File.exist?(user_input) do puts "File doesn't exist. Please enter absolute path, or relative to the "+Dir.pwd puts "Enter a path to a JMX file(don't change): " user_input = gets.chomp end if !user_input.empty? vars["jmx_filepath"] = user_input end end if !vars["options"]["JMETER_VERSION"] puts "Enter Jmeter version(Default - don't change, 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3.2): " user_input = gets if user_input.chomp != "" vars["options"]["JMETER_VERSION"] = user_input.chomp.to_f end end if !vars["options"]["OVERRIDE_RAMP_UP"] puts "Enter ramp up(don't change): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_RAMP_UP"] = user_input.chomp.to_i end end if !vars["options"]["OVERRIDE_ITERATIONS"] puts "Enter iterations(don't change): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_ITERATIONS"] = user_input.chomp.to_i end end if !vars["options"]["OVERRIDE_DURATION"] puts "Enter duration(don't change): " user_input = gets if user_input.chomp != "" vars["options"]["OVERRIDE_DURATION"] = user_input.chomp.to_i end end if test_type == "jmeter" # NUMBER_OF_ENGINES only available if JMeter test was selected in TEST_TYPE if !vars["options"]["NUMBER_OF_ENGINES"] puts "Enter number of engines(Default- don't change, [1-60]): " user_input = gets.chomp while user_input != "" && (user_input.to_i < 1 || user_input.to_i > 60) if(user_input.to_i < 1 || user_input.to_i > 60) puts "Value must be between 1-60" end puts "Enter number of engines(Default- auto, [1-60]): " user_input = gets.chomp end if user_input != "" vars["options"]["NUMBER_OF_ENGINES"] = user_input.to_i end end else #make sure this option isn't passed in case of other test_types vars["options"].delete("NUMBER_OF_ENGINES") end #todo: check number_of_engines value from original test if vars["options"]["NUMBER_OF_ENGINES"] || old_vars["options"]["NUMBER_OF_ENGINES"] != "0" #[Auto] wasn't selected in NUMBER_OF_ENGINES user_text = "Maximum number of concurrent users per load engine(Default- don't change, [20-36000])" else #[Auto] Was selected in NUMBER_OF_ENGINES user_text = "Maximum number of concurrent users(Default- don't change, [20-36000])" end if !vars["options"]["USERS"] puts "Enter "+user_text+":" user_input = gets.chomp while !user_input.empty? && (user_input.to_i < 20 || user_input.to_i > 36000) do puts "Incorrect value. " puts "Enter "+user_text+":" user_input = gets.chomp end if user_input != "" vars["options"]["USERS"] = user_input end end if (vars["options"]["NUMBER_OF_ENGINES"] || old_vars["options"]["NUMBER_OF_ENGINES"] != "0")&& vars["options"]["USERS"] #[Auto] wasn't selected in NUMBER_OF_ENGINES vars["options"]["OVERRIDE_THREADS"] = vars["options"]["USERS"] vars["options"].delete("USERS") end ["options"] = vars["options"] blaze.testUpdate(test_id, ) if vars["jmx_filepath"] filename = File.basename(vars["jmx_filepath"]) blaze.testScriptUpload(test_id, vars["jmx_filepath"], filename) end rescue "help" return help end end |