module BigBench # Dispatches the command line commands to BigBench calls. Available commands are: # # :include: executor.txt module Executor COMMANDS = [ "--help", "show help", "run local PATH_TO_TEST", "run bots PATH_TO_TEST [REDIS_URL_WITH_PORT REDIS_PASSWORD]", "start bot [REDIS_URL_WITH_PORT REDIS_PASSWORD]", "reset all [REDIS_URL_WITH_PORT REDIS_PASSWORD]" ] # Is thrown when the command is not known class InvalidCommand < StandardError def message puts "\n\n" puts "Sorry, could not compile your command. Please enter one of the following commands:\n\n" COMMANDS.each{ |command| puts command } puts " " "Sorry, could not compile your command." end end # Parses and runs the BigBench funtion that is supplied via the commandline's ARGV. It # throws an InvalidCommand exception if the command is unknown. def self.run!(argv) BigBench::Output.start check_arguments!(argv) send to_executor_method(argv), argv BigBench::Output.done end private # Maps the incoming ARGV to a method def self.to_executor_method(argv) return "show_help" if argv.first == "--help" "#{argv[0]}_#{argv[1]}".to_sym end # Checks if the supplied ARGV has a valid and useable form def self.check_arguments!(argv) raise InvalidCommand.new if argv.nil? or argv.empty? raise InvalidCommand.new unless respond_to?(to_executor_method(argv)) true end # Runs a local test with the specified test.rb. For this mode no redis is needed. def self.run_local(argv) BigBench.load_test! File.open(argv[2], "rb"){ |file| file.read } BigBench.run! BigBench.write_local_trackings_to_file! end # Runs a test on all available bots with the specified test.rb # # bigbench run bots test.rb http://localhost:6379 password # def self.run_bots(argv) # Load and validate tests test = File.open(argv[2], "rb"){ |file| file.read } BigBench.load_test!(test) BigBench.config.mode = :bots # Initialize redis argv.shift(3) BigBench::Store.setup!(*argv) # Load current test to redis & start bots BigBench::Store.test = test BigBench::Store.start BigBench::Output.deployed_test # Wait for bots to run the tests @is_running = true timer = Thread.new{ sleep(BigBench.duration.to_i) BigBench::Store.stop @is_running = false } BigBench::Output.starting_bots_loop loop{ bots = BigBench::Store.bots BigBench::Output.running_bots_loop(bots) sleep(1) break if !@is_running and bots.size == 0 } # Gather trackings from redis and write them to the file BigBench::Output.finished_bots_loop BigBench.write_store_trackings_to_file! BigBench::Store.reset! end # Starts the bot that listens for tests on the redis def self.start_bot(argv) argv.shift(2) BigBench::Store.setup!(*argv) loop { BigBench::Output.bot_is_checking BigBench::Bot.check_test! sleep(BigBench.config.bot_checks_every.to_i) } end # Shows the command line help def self.show_help(argv) File.open("lib/bigbench/help/executor.txt", "rb"){ |file| file.read } end # Resets everything def self.reset_all(argv) argv.shift(2) BigBench::Store.setup!(*argv) BigBench::Store.reset! BigBench::Configuration.reset! BigBench::Benchmark.reset! BigBench::Output.reset end end end