request-log-analyzer 1.13.1 → 1.13.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/bin/console +17 -0
- data/lib/cli/command_line_arguments.rb +29 -36
- data/lib/cli/database_console.rb +1 -3
- data/lib/cli/database_console_init.rb +11 -11
- data/lib/cli/progressbar.rb +30 -32
- data/lib/cli/tools.rb +20 -23
- data/lib/request_log_analyzer.rb +8 -8
- data/lib/request_log_analyzer/aggregator.rb +4 -7
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +10 -13
- data/lib/request_log_analyzer/aggregator/echo.rb +5 -7
- data/lib/request_log_analyzer/aggregator/summarizer.rb +15 -18
- data/lib/request_log_analyzer/class_level_inheritable_attributes.rb +23 -0
- data/lib/request_log_analyzer/controller.rb +36 -42
- data/lib/request_log_analyzer/database.rb +4 -6
- data/lib/request_log_analyzer/database/base.rb +39 -41
- data/lib/request_log_analyzer/database/connection.rb +8 -10
- data/lib/request_log_analyzer/database/request.rb +1 -3
- data/lib/request_log_analyzer/database/source.rb +0 -2
- data/lib/request_log_analyzer/database/warning.rb +4 -6
- data/lib/request_log_analyzer/file_format.rb +46 -49
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +15 -19
- data/lib/request_log_analyzer/file_format/apache.rb +42 -45
- data/lib/request_log_analyzer/file_format/delayed_job.rb +13 -15
- data/lib/request_log_analyzer/file_format/delayed_job2.rb +9 -11
- data/lib/request_log_analyzer/file_format/delayed_job21.rb +9 -11
- data/lib/request_log_analyzer/file_format/delayed_job3.rb +5 -8
- data/lib/request_log_analyzer/file_format/delayed_job4.rb +5 -8
- data/lib/request_log_analyzer/file_format/haproxy.rb +44 -48
- data/lib/request_log_analyzer/file_format/merb.rb +13 -17
- data/lib/request_log_analyzer/file_format/mysql.rb +21 -25
- data/lib/request_log_analyzer/file_format/nginx.rb +0 -2
- data/lib/request_log_analyzer/file_format/oink.rb +30 -31
- data/lib/request_log_analyzer/file_format/postgresql.rb +11 -15
- data/lib/request_log_analyzer/file_format/rack.rb +0 -2
- data/lib/request_log_analyzer/file_format/rails.rb +100 -104
- data/lib/request_log_analyzer/file_format/rails3.rb +19 -23
- data/lib/request_log_analyzer/file_format/rails_development.rb +0 -1
- data/lib/request_log_analyzer/file_format/w3c.rb +16 -18
- data/lib/request_log_analyzer/filter.rb +0 -2
- data/lib/request_log_analyzer/filter/anonymize.rb +4 -7
- data/lib/request_log_analyzer/filter/field.rb +3 -6
- data/lib/request_log_analyzer/filter/timespan.rb +2 -6
- data/lib/request_log_analyzer/line_definition.rb +16 -19
- data/lib/request_log_analyzer/log_processor.rb +10 -14
- data/lib/request_log_analyzer/mailer.rb +9 -12
- data/lib/request_log_analyzer/output.rb +12 -14
- data/lib/request_log_analyzer/output/fixed_width.rb +21 -28
- data/lib/request_log_analyzer/output/html.rb +11 -14
- data/lib/request_log_analyzer/request.rb +53 -33
- data/lib/request_log_analyzer/source.rb +2 -5
- data/lib/request_log_analyzer/source/log_parser.rb +9 -16
- data/lib/request_log_analyzer/tracker.rb +10 -12
- data/lib/request_log_analyzer/tracker/duration.rb +4 -6
- data/lib/request_log_analyzer/tracker/frequency.rb +9 -11
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +8 -11
- data/lib/request_log_analyzer/tracker/numeric_value.rb +40 -44
- data/lib/request_log_analyzer/tracker/timespan.rb +5 -8
- data/lib/request_log_analyzer/tracker/traffic.rb +8 -10
- data/lib/request_log_analyzer/version.rb +1 -1
- data/request-log-analyzer.gemspec +6 -6
- data/spec/integration/command_line_usage_spec.rb +33 -33
- data/spec/integration/mailer_spec.rb +181 -185
- data/spec/integration/munin_plugins_rails_spec.rb +20 -20
- data/spec/integration/scout_spec.rb +40 -41
- data/spec/lib/helpers.rb +8 -9
- data/spec/lib/macros.rb +2 -4
- data/spec/lib/matchers.rb +20 -25
- data/spec/lib/mocks.rb +10 -11
- data/spec/lib/testing_format.rb +8 -10
- data/spec/spec_helper.rb +5 -1
- data/spec/unit/aggregator/database_inserter_spec.rb +23 -23
- data/spec/unit/aggregator/summarizer_spec.rb +7 -7
- data/spec/unit/controller/controller_spec.rb +14 -14
- data/spec/unit/controller/log_processor_spec.rb +3 -3
- data/spec/unit/database/base_class_spec.rb +36 -37
- data/spec/unit/database/connection_spec.rb +10 -10
- data/spec/unit/database/database_spec.rb +11 -11
- data/spec/unit/file_format/amazon_s3_format_spec.rb +66 -62
- data/spec/unit/file_format/apache_format_spec.rb +57 -52
- data/spec/unit/file_format/common_regular_expressions_spec.rb +18 -21
- data/spec/unit/file_format/delayed_job21_format_spec.rb +22 -16
- data/spec/unit/file_format/delayed_job2_format_spec.rb +22 -16
- data/spec/unit/file_format/delayed_job3_format_spec.rb +14 -10
- data/spec/unit/file_format/delayed_job4_format_spec.rb +14 -10
- data/spec/unit/file_format/delayed_job_format_spec.rb +12 -12
- data/spec/unit/file_format/file_format_api_spec.rb +19 -19
- data/spec/unit/file_format/format_autodetection_spec.rb +7 -7
- data/spec/unit/file_format/haproxy_format_spec.rb +53 -49
- data/spec/unit/file_format/inheritance_spec.rb +13 -0
- data/spec/unit/file_format/line_definition_spec.rb +35 -33
- data/spec/unit/file_format/merb_format_spec.rb +13 -11
- data/spec/unit/file_format/mysql_format_spec.rb +24 -24
- data/spec/unit/file_format/oink_format_spec.rb +29 -29
- data/spec/unit/file_format/postgresql_format_spec.rb +9 -9
- data/spec/unit/file_format/rack_format_spec.rb +36 -31
- data/spec/unit/file_format/rails3_format_spec.rb +46 -46
- data/spec/unit/file_format/rails_format_spec.rb +52 -53
- data/spec/unit/file_format/w3c_format_spec.rb +27 -24
- data/spec/unit/filter/anonymize_filter_spec.rb +7 -7
- data/spec/unit/filter/field_filter_spec.rb +26 -26
- data/spec/unit/filter/filter_spec.rb +4 -4
- data/spec/unit/filter/timespan_filter_spec.rb +22 -22
- data/spec/unit/mailer_spec.rb +21 -21
- data/spec/unit/request_spec.rb +29 -29
- data/spec/unit/source/log_parser_spec.rb +5 -5
- data/spec/unit/tracker/duration_tracker_spec.rb +23 -23
- data/spec/unit/tracker/frequency_tracker_spec.rb +29 -30
- data/spec/unit/tracker/hourly_spread_spec.rb +35 -35
- data/spec/unit/tracker/numeric_value_tracker_spec.rb +71 -72
- data/spec/unit/tracker/timespan_tracker_spec.rb +31 -31
- data/spec/unit/tracker/tracker_api_spec.rb +43 -44
- data/spec/unit/tracker/traffic_tracker_spec.rb +7 -7
- metadata +38 -35
data/spec/lib/testing_format.rb
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
# Simple log file specification, used to test log parser.
|
2
2
|
class TestingFormat < RequestLogAnalyzer::FileFormat::Base
|
3
|
-
|
4
3
|
format_definition.first do |line|
|
5
4
|
line.header = true
|
6
5
|
line.teaser = /processing /
|
7
6
|
line.regexp = /processing request (\d+)/
|
8
|
-
line.captures = [{ :
|
7
|
+
line.captures = [{ name: :request_no, type: :integer }]
|
9
8
|
end
|
10
9
|
|
11
10
|
format_definition.test do |line|
|
12
11
|
line.teaser = /testing /
|
13
12
|
line.regexp = /testing is (\w+)(?: in (\d+\.\d+)ms)?/
|
14
|
-
line.captures = [{ :
|
15
|
-
{ :
|
13
|
+
line.captures = [{ name: :test_capture, type: :test_type },
|
14
|
+
{ name: :duration, type: :duration, unit: :msec }]
|
16
15
|
end
|
17
16
|
|
18
17
|
format_definition.eval do |line|
|
19
18
|
line.regexp = /evaluation (\{.*\})/
|
20
|
-
line.captures = [{ :
|
19
|
+
line.captures = [{ name: :evaluated, type: :eval, provides: { greating: :string, what: :string } }]
|
21
20
|
end
|
22
21
|
|
23
22
|
format_definition.last do |line|
|
24
23
|
line.footer = true
|
25
24
|
line.teaser = /finishing /
|
26
25
|
line.regexp = /finishing request (\d+)/
|
27
|
-
line.captures = [{ :
|
26
|
+
line.captures = [{ name: :request_no, type: :integer }]
|
28
27
|
end
|
29
28
|
|
30
29
|
format_definition.combined do |line|
|
@@ -34,13 +33,12 @@ class TestingFormat < RequestLogAnalyzer::FileFormat::Base
|
|
34
33
|
end
|
35
34
|
|
36
35
|
report do |analyze|
|
37
|
-
analyze.frequency :test_capture, :
|
36
|
+
analyze.frequency :test_capture, title: 'What is testing exactly?'
|
38
37
|
end
|
39
38
|
|
40
39
|
class Request < RequestLogAnalyzer::Request
|
41
|
-
def convert_test_type(value,
|
40
|
+
def convert_test_type(value, _definition)
|
42
41
|
"Testing is #{value}"
|
43
42
|
end
|
44
43
|
end
|
45
|
-
|
46
|
-
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ module RequestLogAnalyzer::RSpec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Include all files in the spec_helper directory
|
12
|
-
Dir[File.dirname(__FILE__) +
|
12
|
+
Dir[File.dirname(__FILE__) + '/lib/**/*.rb'].each do |file|
|
13
13
|
require file
|
14
14
|
end
|
15
15
|
|
@@ -21,4 +21,8 @@ RSpec.configure do |config|
|
|
21
21
|
config.include RequestLogAnalyzer::RSpec::Helpers
|
22
22
|
|
23
23
|
config.extend RequestLogAnalyzer::RSpec::Macros
|
24
|
+
|
25
|
+
config.expect_with :rspec do |c|
|
26
|
+
c.syntax = :should
|
27
|
+
end
|
24
28
|
end
|
@@ -21,7 +21,7 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
|
|
21
21
|
@database_inserter.prepare
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'should set the file_format' do
|
25
25
|
@database.should_receive(:file_format=).with(testing_format)
|
26
26
|
@database_inserter.prepare
|
27
27
|
end
|
@@ -48,46 +48,46 @@ describe RequestLogAnalyzer::Aggregator::DatabaseInserter do
|
|
48
48
|
context "using a #{name} database" do
|
49
49
|
|
50
50
|
before(:each) do
|
51
|
-
@database_inserter = RequestLogAnalyzer::Aggregator::DatabaseInserter.new(@log_parser, :
|
51
|
+
@database_inserter = RequestLogAnalyzer::Aggregator::DatabaseInserter.new(@log_parser, database: connection, reset_database: true)
|
52
52
|
@database_inserter.prepare
|
53
53
|
|
54
|
-
@incomplete_request = testing_format.request(
|
55
|
-
@completed_request = testing_format.request(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
@incomplete_request = testing_format.request(line_type: :first, request_no: 564)
|
55
|
+
@completed_request = testing_format.request({ line_type: :first, request_no: 564 },
|
56
|
+
{ line_type: :test, test_capture: 'awesome' },
|
57
|
+
{ line_type: :test, test_capture: 'indeed' },
|
58
|
+
{ line_type: :eval, evaluated: { greating: 'howdy' }, greating: 'howdy' },
|
59
|
+
{ line_type: :last, request_no: 564 })
|
60
60
|
end
|
61
61
|
|
62
62
|
after(:each) do
|
63
63
|
@database_inserter.database.send :remove_orm_classes!
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
lambda
|
66
|
+
it 'should insert a record in the request table' do
|
67
|
+
lambda do
|
68
68
|
@database_inserter.aggregate(@incomplete_request)
|
69
|
-
|
69
|
+
end.should change(RequestLogAnalyzer::Database::Request, :count).from(0).to(1)
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
73
|
-
lambda
|
72
|
+
it 'should insert a record in the first_lines table' do
|
73
|
+
lambda do
|
74
74
|
@database_inserter.aggregate(@incomplete_request)
|
75
|
-
|
75
|
+
end.should change(@database_inserter.database.get_class(:first), :count).from(0).to(1)
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it 'should insert records in all relevant line tables' do
|
79
79
|
@database_inserter.aggregate(@completed_request)
|
80
80
|
request = RequestLogAnalyzer::Database::Request.first
|
81
|
-
request.should
|
82
|
-
request.should
|
83
|
-
request.should
|
84
|
-
request.should
|
81
|
+
request.should satisfy { |r| r.test_lines.length == 2 }
|
82
|
+
request.should satisfy { |r| r.first_lines.length == 1 }
|
83
|
+
request.should satisfy { |r| r.eval_lines.length == 1 }
|
84
|
+
request.should satisfy { |r| r.last_lines.length == 1 }
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
RequestLogAnalyzer::Database::Warning.should_receive(:create!).with(hash_including(:
|
89
|
-
@database_inserter.warning(:test_warning,
|
87
|
+
it 'should log a warning in the warnings table' do
|
88
|
+
RequestLogAnalyzer::Database::Warning.should_receive(:create!).with(hash_including(warning_type: 'test_warning'))
|
89
|
+
@database_inserter.warning(:test_warning, 'Testing the warning system', 12)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
@@ -3,23 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe RequestLogAnalyzer::Aggregator::Summarizer do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source, :
|
6
|
+
@summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source, output: mock_output)
|
7
7
|
@summarizer.prepare
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
@summarizer.aggregate(request(:
|
12
|
-
@summarizer.aggregate(request(:
|
10
|
+
it 'not raise exception when creating a report after aggregating multiple requests' do
|
11
|
+
@summarizer.aggregate(request(data: 'bluh1'))
|
12
|
+
@summarizer.aggregate(request(data: 'bluh2'))
|
13
13
|
|
14
14
|
lambda { @summarizer.report(mock_output) }.should_not raise_error
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
@summarizer.aggregate(request(:
|
17
|
+
it 'not raise exception when creating a report after aggregating a single request' do
|
18
|
+
@summarizer.aggregate(request(data: 'bluh1'))
|
19
19
|
lambda { @summarizer.report(mock_output) }.should_not raise_error
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'not raise exception when creating a report after aggregating no requests' do
|
23
23
|
lambda { @summarizer.report(mock_output) }.should_not raise_error
|
24
24
|
end
|
25
25
|
|
@@ -2,40 +2,40 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::Controller do
|
4
4
|
|
5
|
-
it
|
6
|
-
|
5
|
+
it 'should use a custom output generator correctly' do
|
6
|
+
|
7
7
|
mock_output = double('RequestLogAnalyzer::Output::Base')
|
8
8
|
mock_output.stub(:io).and_return(mock_io)
|
9
9
|
mock_output.should_receive(:header)
|
10
10
|
mock_output.should_receive(:footer)
|
11
11
|
|
12
|
-
controller = RequestLogAnalyzer::Controller.new(mock_source, :
|
12
|
+
controller = RequestLogAnalyzer::Controller.new(mock_source, output: mock_output)
|
13
13
|
|
14
14
|
controller.run!
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
controller = RequestLogAnalyzer::Controller.new(mock_source, :
|
19
|
-
|
20
|
-
mock_aggregator = double('RequestLogAnalyzer::Aggregator::Base')
|
17
|
+
it 'should call aggregators correctly when run' do
|
18
|
+
controller = RequestLogAnalyzer::Controller.new(mock_source, output: mock_output)
|
19
|
+
|
20
|
+
mock_aggregator = double('RequestLogAnalyzer::Aggregator::Base')
|
21
21
|
mock_aggregator.should_receive(:prepare).once.ordered
|
22
22
|
mock_aggregator.should_receive(:aggregate).with(an_instance_of(testing_format.request_class)).twice.ordered
|
23
23
|
mock_aggregator.should_receive(:finalize).once.ordered
|
24
24
|
mock_aggregator.should_receive(:report).once.ordered
|
25
|
-
|
25
|
+
|
26
26
|
controller.aggregators << mock_aggregator
|
27
27
|
controller.run!
|
28
28
|
end
|
29
|
-
|
30
|
-
it
|
31
|
-
controller = RequestLogAnalyzer::Controller.new(mock_source, :
|
32
|
-
|
29
|
+
|
30
|
+
it 'should call filters when run' do
|
31
|
+
controller = RequestLogAnalyzer::Controller.new(mock_source, output: mock_output)
|
32
|
+
|
33
33
|
mock_filter = double('RequestLogAnalyzer::Filter::Base')
|
34
34
|
mock_filter.should_receive(:filter).twice.and_return(nil)
|
35
35
|
controller.should_receive(:aggregate_request).twice.and_return(nil)
|
36
|
-
|
36
|
+
|
37
37
|
controller.filters << mock_filter
|
38
38
|
controller.run!
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
end
|
@@ -8,11 +8,11 @@ describe RequestLogAnalyzer::LogProcessor, 'stripping log files' do
|
|
8
8
|
@log_stripper = RequestLogAnalyzer::LogProcessor.new(testing_format, :strip, {})
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should remove a junk line' do
|
12
12
|
@log_stripper.strip_line("junk line\n").should be_empty
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'should keep a teaser line intact' do
|
16
16
|
@log_stripper.strip_line("processing 1234\n").should be_empty
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -5,14 +5,14 @@ describe RequestLogAnalyzer::Database::Base do
|
|
5
5
|
|
6
6
|
describe '.subclass_from_line_definition' do
|
7
7
|
before(:all) do
|
8
|
-
@line_definition = RequestLogAnalyzer::LineDefinition.new(:test,
|
9
|
-
|
10
|
-
|
8
|
+
@line_definition = RequestLogAnalyzer::LineDefinition.new(:test, regexp: /Testing (\w+), tries\: (\d+)/,
|
9
|
+
captures: [{ name: :what, type: :string }, { name: :tries, type: :integer },
|
10
|
+
{ name: :evaluated, type: :hash, provides: { evaluated_field: :duration } }])
|
11
11
|
end
|
12
12
|
|
13
13
|
before(:each) do
|
14
14
|
@orm_class = double('Line ActiveRecord::Base class')
|
15
|
-
@orm_class.stub(
|
15
|
+
@orm_class.stub('table_name=')
|
16
16
|
@orm_class.stub(:belongs_to)
|
17
17
|
@orm_class.stub(:serialize)
|
18
18
|
@orm_class.stub(:line_definition=)
|
@@ -24,41 +24,41 @@ describe RequestLogAnalyzer::Database::Base do
|
|
24
24
|
RequestLogAnalyzer::Database::Base.stub(:database).and_return(@database)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'should create a new subclass using the Base class as parent' do
|
28
28
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'should store the LineDefinition' do
|
32
32
|
@orm_class.should_receive(:line_definition=).with(@line_definition)
|
33
33
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
@orm_class.should_receive(
|
36
|
+
it 'should set the table name for the subclass' do
|
37
|
+
@orm_class.should_receive('table_name=').with('test_lines')
|
38
38
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
@orm_class.should_receive(:belongs_to).with(:request,
|
41
|
+
it 'should set the :belongs_to relationship with the Request class' do
|
42
|
+
@orm_class.should_receive(:belongs_to).with(:request, class_name: 'RequestLogAnalyzer::Database::Request')
|
43
43
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'should set a :has_many relationship in the request class' do
|
47
47
|
RequestLogAnalyzer::Database::Request.should_receive(:has_many).with(:test_lines)
|
48
48
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'should set a :has_many relationship in the source class' do
|
52
52
|
RequestLogAnalyzer::Database::Source.should_receive(:has_many).with(:test_lines)
|
53
53
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
@orm_class.should_receive(:belongs_to).with(:source,
|
56
|
+
it 'should set the :belongs_to relationship with the Source class' do
|
57
|
+
@orm_class.should_receive(:belongs_to).with(:source, class_name: 'RequestLogAnalyzer::Database::Source')
|
58
58
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'should serialize a complex field' do
|
62
62
|
@orm_class.should_receive(:serialize).with(:evaluated, Hash)
|
63
63
|
RequestLogAnalyzer::Database::Base.subclass_from_line_definition(@line_definition, @orm_class)
|
64
64
|
end
|
@@ -76,32 +76,32 @@ describe RequestLogAnalyzer::Database::Base do
|
|
76
76
|
RequestLogAnalyzer::Database::Base.stub(:database).and_return(@database)
|
77
77
|
|
78
78
|
@klass = double('ActiveRecord ORM class')
|
79
|
-
@klass.stub(:column_names).and_return(
|
80
|
-
@klass.stub(
|
79
|
+
@klass.stub(:column_names).and_return(%w(id request_id source_id lineno duration))
|
80
|
+
@klass.stub('table_name=')
|
81
81
|
@klass.stub(:belongs_to)
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
85
|
-
@klass.should_receive(
|
84
|
+
it 'should set the table name' do
|
85
|
+
@klass.should_receive('table_name=').with('completed_lines')
|
86
86
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines', @klass)
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
@klass.should_receive(:belongs_to).with(:request,
|
89
|
+
it 'should create the :belongs_to relation to the request class' do
|
90
|
+
@klass.should_receive(:belongs_to).with(:request, class_name: 'RequestLogAnalyzer::Database::Request')
|
91
91
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines', @klass)
|
92
92
|
end
|
93
93
|
|
94
|
-
it
|
94
|
+
it 'should create the :has_many relation in the request class' do
|
95
95
|
RequestLogAnalyzer::Database::Request.should_receive(:has_many).with(:completed_lines)
|
96
96
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines', @klass)
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
100
|
-
@klass.should_receive(:belongs_to).with(:source,
|
99
|
+
it 'should create the :belongs_to relation to the source class' do
|
100
|
+
@klass.should_receive(:belongs_to).with(:source, class_name: 'RequestLogAnalyzer::Database::Source')
|
101
101
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines', @klass)
|
102
102
|
end
|
103
103
|
|
104
|
-
it
|
104
|
+
it 'should create the :has_many relation in the request class' do
|
105
105
|
RequestLogAnalyzer::Database::Source.should_receive(:has_many).with(:completed_lines)
|
106
106
|
RequestLogAnalyzer::Database::Base.subclass_from_table('completed_lines', @klass)
|
107
107
|
end
|
@@ -111,9 +111,9 @@ describe RequestLogAnalyzer::Database::Base do
|
|
111
111
|
describe '#create_table' do
|
112
112
|
|
113
113
|
before(:all) do
|
114
|
-
@line_definition = RequestLogAnalyzer::LineDefinition.new(:test,
|
115
|
-
|
116
|
-
|
114
|
+
@line_definition = RequestLogAnalyzer::LineDefinition.new(:test, regexp: /Testing (\w+), tries\: (\d+)/,
|
115
|
+
captures: [{ name: :what, type: :string }, { name: :tries, type: :integer },
|
116
|
+
{ name: :evaluated, type: :hash, provides: { evaluated_field: :duration } }])
|
117
117
|
end
|
118
118
|
|
119
119
|
before(:each) do
|
@@ -128,48 +128,47 @@ describe RequestLogAnalyzer::Database::Base do
|
|
128
128
|
@database.remove_orm_classes!
|
129
129
|
end
|
130
130
|
|
131
|
-
it
|
131
|
+
it 'should call create_table with the correct table name' do
|
132
132
|
@database.connection.should_receive(:create_table).with(:test_lines)
|
133
133
|
@klass.create_table!
|
134
134
|
end
|
135
135
|
|
136
|
-
it
|
136
|
+
it 'should not create a table based on the line type name if it already exists' do
|
137
137
|
@klass.stub(:table_exists?).and_return(true)
|
138
138
|
@database.connection.should_not_receive(:create_table).with(:test_lines)
|
139
139
|
@klass.create_table!
|
140
140
|
end
|
141
141
|
|
142
|
-
it
|
142
|
+
it 'should create an index on the request_id field' do
|
143
143
|
@database.connection.should_receive(:add_index).with(:test_lines, [:request_id])
|
144
144
|
@klass.create_table!
|
145
145
|
end
|
146
146
|
|
147
|
-
it
|
147
|
+
it 'should create an index on the source_id field' do
|
148
148
|
@database.connection.should_receive(:add_index).with(:test_lines, [:source_id])
|
149
149
|
@klass.create_table!
|
150
150
|
end
|
151
151
|
|
152
|
-
it
|
152
|
+
it 'should create a request_id field to link the requests together' do
|
153
153
|
@database.connection.table_creator.should_receive(:column).with(:request_id, :integer)
|
154
154
|
@klass.create_table!
|
155
155
|
end
|
156
156
|
|
157
|
-
it
|
157
|
+
it 'should create a lineno field to save the location of the line in the original file' do
|
158
158
|
@database.connection.table_creator.should_receive(:column).with(:lineno, :integer)
|
159
159
|
@klass.create_table!
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
162
|
+
it 'should create a field of the correct type for every defined capture field' do
|
163
163
|
@database.connection.table_creator.should_receive(:column).with(:what, :string)
|
164
164
|
@database.connection.table_creator.should_receive(:column).with(:tries, :integer)
|
165
165
|
@database.connection.table_creator.should_receive(:column).with(:evaluated, :text)
|
166
166
|
@klass.create_table!
|
167
167
|
end
|
168
168
|
|
169
|
-
it
|
169
|
+
it 'should create a field of the correct type for every provided field' do
|
170
170
|
@database.connection.table_creator.should_receive(:column).with(:evaluated_field, :float)
|
171
171
|
@klass.create_table!
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
175
|
-
|
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
3
3
|
describe RequestLogAnalyzer::Database::Connection do
|
4
4
|
describe '.from_string' do
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'should parse a name-value based string' do
|
7
7
|
string = 'adapter=sqlite3;database=filename.db'
|
8
|
-
RequestLogAnalyzer::Database::Connection.from_string(string).should == {:
|
8
|
+
RequestLogAnalyzer::Database::Connection.from_string(string).should == { adapter: 'sqlite3', database: 'filename.db' }
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'should parse an URI-based string for SQLite3' do
|
12
12
|
string = 'sqlite3://filename.db'
|
13
|
-
RequestLogAnalyzer::Database::Connection.from_string(string).should == {:
|
13
|
+
RequestLogAnalyzer::Database::Connection.from_string(string).should == { adapter: 'sqlite3', database: 'filename.db' }
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'should parse an URI-based string for MySQL' do
|
17
17
|
string = 'mysql://localhost.local/database'
|
18
18
|
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
19
|
-
{ :
|
19
|
+
{ adapter: 'mysql', database: 'database', host: 'localhost.local' }
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'should parse an URI-based string for MySQL with only username' do
|
23
23
|
string = 'mysql://username@localhost.local/database'
|
24
24
|
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
25
|
-
{ :
|
25
|
+
{ adapter: 'mysql', database: 'database', host: 'localhost.local', username: 'username' }
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'should parse an URI-based string for MySQL with username and password' do
|
29
29
|
string = 'mysql://username:password@localhost.local/database'
|
30
30
|
RequestLogAnalyzer::Database::Connection.from_string(string).should ==
|
31
|
-
{ :
|
31
|
+
{ adapter: 'mysql', database: 'database', host: 'localhost.local', username: 'username', password: 'password' }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|