Class: InternetHakai::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/internethakai/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/internethakai/main.rb', line 4

def config
  @config
end

Instance Method Details

#load_config(configpath, basepath = nil, args = nil) ⇒ Object



5
6
7
8
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
# File 'lib/internethakai/main.rb', line 5

def load_config configpath, basepath = nil, args = nil
    if args
        setting = {}
        setting['loop'] = args[:loop] if args.has_key? :loop
        setting['max_request'] = args[:max_request] if args.has_key? :max_request
        setting['max_scenario'] = args[:concurrency] if args.has_key? :concurrency
        setting['log_level'] = args[:log_level] if args.has_key? :log_level
        setting['total_duration'] = args[:duration] if args.has_key? :duration
        setting['max_process'] = args[:max_process] if args.has_key? :max_process
    else
        setting = nil
    end

    @basepath = basepath || File::dirname(configpath)
    @scenario_builder = ScenarioBuilder::new(nil)
    @scenario_builder.load(configpath, setting)
    @scenario_handler = BaseHandler::get_handler("ScenarioHandler")
    @config = @scenario_builder.get_config
    BaseHandler::set_config(@config)
    @scenario_handler.init(@config)

    reporter = BaseHandler::get_handler(@config["reporter"])
    if(@config["log_dir"])
        @basepath = @config["log_dir"]
    end
    starttime = Time::now
    @starttime = starttime
    start = starttime.strftime( '%Y%m%d_%H%M%S' )
    reporter.set_dir(@basepath)
    reporter.init_filename(start)
    if args && args.has_key?(:action_nth)
        @config['actions'] = @config['actions'][args[:action_nth], 1]
    end
    if @test
        @config['loop'] = 1
        @config['max_request'] = 1
        @config['concurrency'] = 1
        @config['max_scenario'] = 1
        @config['max_process'] = 1
        @config.delete('fork')
        @config['max_request_show'] = 1
        @config['max_scenario_show'] = 1
        @config['log_level'] = 3
    end

    @report_path = reporter.get_filename
    @logger = BaseHandler::get_handler(@config["logger"])
    @logger.init(@config)
    @logger.run(start + "\n", 2)
    @logger.run("Rev Mode\n", 2) if @config['rev']
    @logger.run("Target domain = #{@config['domain']}\n", 2)
    if @config.has_key?('total_duration')
        @logger.run("Duration: #{@config['total_duration']}\n", 2)
    else
        @logger.run("Loop: #{@config['loop']}\n", 2)
    end
    @logger.run("Request Concurrency: #{@config['max_request_show']}\n", 2)
    @logger.run("Scenario Concurrency: #{@config['max_scenario_show']}\n", 2)
end

#main(config = nil) ⇒ Object



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
# File 'lib/internethakai/main.rb', line 64

def main config=nil
    #引数か、同じディレクトリの「scenario.yml」を読み込みます。
    args = {}
    @test = false
    opts = OptionParser.new("Usage: #{File::basename($0)} SCENARIO")
    opts.on("-v", "--version", "show version") do
        puts "%s %s" %[File.basename($0), InternetHakai::VERSION]
        puts "ruby %s" % RUBY_VERSION
        exit
    end
    opts.on("--test", "exec in testmode") do
        @test = true
    end
    opts.on('-l NUM', '--loop' 'loop times') do |loop|
        args[:loop] = loop.to_i
    end
    opts.on('-s NUM', '--max-scenario', 'max-scenario') do |conc|
        args[:concurrency] = conc.to_o
    end
    opts.on('-r NUM', '--max-request', 'max-request') do |mr|
        args[:max_request] = mr.to_i
    end
    opts.on('-g NUM', '--log-level', 'log-level') do |l|
        args[:log_level] = l.to_i
    end
    opts.on('-n NUM', '--nth', 'run only nth action') do |l|
        args[:action_nth] = l.to_i
    end
    opts.on('-d NUM', '--duration', 'duration-time') do |l|
        args[:duration] = l.to_i
    end
    opts.on('-p NUM', '--max-process', 'max-process') do |l|
        args[:max_process] = l.to_i
    end
    opts.on_tail("-h", "--help", "show this message") do
        puts opts
        exit
    end
    opts.version = InternetHakai::VERSION
    opts.parse!(ARGV)
    if config.nil?
        config = ARGV[0]
    end
    unless config
        puts "Usage: #{File::basename($0)} SCENARIO"
        exit
    end

    load_config config, nil, args

    @test = InternetHakai::ConcurrencyManager::new
    @test.run(@config, @basepath, @starttime)
end