newrelic_rpm 3.0.1 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +2 -3
- data/README.rdoc +3 -3
- data/lib/new_relic/agent.rb +19 -7
- data/lib/new_relic/agent/agent.rb +83 -19
- data/lib/new_relic/agent/beacon_configuration.rb +8 -12
- data/lib/new_relic/agent/browser_monitoring.rb +8 -8
- data/lib/new_relic/agent/error_collector.rb +13 -13
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +10 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +41 -35
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +92 -0
- data/lib/new_relic/agent/method_tracer.rb +0 -2
- data/lib/new_relic/agent/shim_agent.rb +2 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -60
- data/lib/new_relic/agent/stats_engine/transactions.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/collection_helper.rb +0 -2
- data/lib/new_relic/control/class_methods.rb +25 -12
- data/lib/new_relic/control/logging_methods.rb +30 -17
- data/lib/new_relic/data_serialization.rb +81 -0
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +9 -5
- data/lib/new_relic/metric_spec.rb +7 -1
- data/lib/new_relic/rack/browser_monitoring.rb +1 -7
- data/lib/new_relic/stats.rb +4 -0
- data/lib/new_relic/transaction_analysis.rb +45 -88
- data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -0
- data/lib/new_relic/transaction_sample.rb +15 -332
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +250 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/version.rb +3 -3
- data/newrelic.yml +3 -3
- data/newrelic_rpm.gemspec +27 -4
- data/test/active_record_fixtures.rb +31 -13
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -3
- data/test/new_relic/agent/agent_test.rb +73 -28
- data/test/new_relic/agent/agent_test_controller_test.rb +11 -10
- data/test/new_relic/agent/beacon_configuration_test.rb +37 -20
- data/test/new_relic/agent/browser_monitoring_test.rb +17 -28
- data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -7
- data/test/new_relic/agent/error_collector_test.rb +6 -7
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +12 -5
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +195 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +60 -58
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -1
- data/test/new_relic/agent/method_tracer_test.rb +8 -8
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +4 -3
- data/test/new_relic/agent/{stats_engine/stats_engine_test.rb → stats_engine_test.rb} +8 -8
- data/test/new_relic/agent/transaction_sampler_test.rb +1 -1
- data/test/new_relic/agent/worker_loop_test.rb +2 -2
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/logging_methods_test.rb +157 -0
- data/test/new_relic/control_test.rb +10 -10
- data/test/new_relic/data_serialization_test.rb +50 -0
- data/test/new_relic/local_environment_test.rb +13 -13
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_spec_test.rb +8 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +454 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_test.rb +51 -0
- data/test/test_helper.rb +4 -14
- metadata +32 -7
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
2
|
+
require 'new_relic/control/logging_methods'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class BaseLoggingMethods
|
6
|
+
# stub class to enable testing of the module
|
7
|
+
include NewRelic::Control::LoggingMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@base = BaseLoggingMethods.new
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_log_basic
|
17
|
+
mock_logger = mock('logger')
|
18
|
+
@base.instance_eval { @log = mock_logger }
|
19
|
+
assert_equal mock_logger, @base.log
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_log_no_log
|
23
|
+
log = @base.log
|
24
|
+
assert_equal Logger, log.class
|
25
|
+
assert_equal Logger::INFO, log.level
|
26
|
+
# have to root around in the logger for the logdev
|
27
|
+
assert_equal STDOUT, log.instance_eval { @logdev }.dev
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_logbang_basic
|
31
|
+
@base.expects(:should_log?).returns(true)
|
32
|
+
@base.expects(:to_stdout).with('whee')
|
33
|
+
@base.instance_eval { @log = nil }
|
34
|
+
@base.log!('whee')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_logbang_should_not_log
|
38
|
+
@base.expects(:should_log?).returns(false)
|
39
|
+
assert_equal nil, @base.log!('whee')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_logbang_with_log
|
43
|
+
@base.expects(:should_log?).returns(true)
|
44
|
+
@base.expects(:to_stdout).with('whee')
|
45
|
+
fake_logger = mock('log')
|
46
|
+
fake_logger.expects(:send).with(:info, 'whee')
|
47
|
+
@base.instance_eval { @log = fake_logger }
|
48
|
+
@base.log!('whee')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_log_no_settings
|
52
|
+
@base.instance_eval { @settings = nil }
|
53
|
+
assert !@base.should_log?
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_log_agent_disabled
|
57
|
+
@base.instance_eval { @settings = true }
|
58
|
+
@base.expects(:agent_enabled?).returns(false)
|
59
|
+
assert !@base.should_log?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_log_agent_enabled
|
63
|
+
@base.instance_eval { @settings = true }
|
64
|
+
@base.expects(:agent_enabled?).returns(true)
|
65
|
+
assert @base.should_log?
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_set_log_level_base
|
69
|
+
fake_logger = mock('logger')
|
70
|
+
# bad configuration
|
71
|
+
@base.expects(:fetch).with('log_level', 'info').returns('whee')
|
72
|
+
fake_logger.expects(:level=).with(Logger::INFO)
|
73
|
+
assert_equal fake_logger, @base.set_log_level!(fake_logger)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_set_log_level_with_each_level
|
77
|
+
fake_logger = mock('logger')
|
78
|
+
%w[debug info warn error fatal].each do |level|
|
79
|
+
@base.expects(:fetch).with('log_level', 'info').returns(level)
|
80
|
+
fake_logger.expects(:level=).with(Logger.const_get(level.upcase))
|
81
|
+
assert_equal fake_logger, @base.set_log_level!(fake_logger)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_set_log_format
|
86
|
+
fake_logger = Object.new
|
87
|
+
assert !fake_logger.respond_to?(:format_message)
|
88
|
+
assert_equal fake_logger, @base.set_log_format!(fake_logger)
|
89
|
+
assert fake_logger.respond_to?(:format_message)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_setup_log_file_not_exist
|
93
|
+
@base.expects(:log_path).returns('logpath')
|
94
|
+
@base.expects(:log_file_name).returns('logfilename')
|
95
|
+
fake_logger = mock('logger')
|
96
|
+
@base.expects(:log).returns(fake_logger)
|
97
|
+
@base.setup_log
|
98
|
+
assert_equal nil, @base.instance_eval { @log }
|
99
|
+
assert_equal 'logpath/logfilename', @base.instance_eval { @log_file }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_setup_log_existing_file
|
103
|
+
fake_logger = mock('logger')
|
104
|
+
Logger.expects(:new).with('logpath/logfilename').returns(fake_logger)
|
105
|
+
@base.expects(:log_path).returns('logpath')
|
106
|
+
@base.expects(:log_file_name).returns('logfilename')
|
107
|
+
@base.expects(:set_log_format!).with(fake_logger)
|
108
|
+
@base.expects(:set_log_level!).with(fake_logger)
|
109
|
+
assert_equal fake_logger, @base.setup_log
|
110
|
+
assert_equal fake_logger, @base.instance_eval { @log }
|
111
|
+
assert_equal 'logpath/logfilename', @base.instance_eval { @log_file }
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_to_stdout
|
115
|
+
STDOUT.expects(:puts).with('** [NewRelic] whee')
|
116
|
+
@base.to_stdout('whee')
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_log_path_exists
|
120
|
+
@base.instance_eval { @log_path = 'logpath' }
|
121
|
+
assert_equal 'logpath', @base.log_path
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_log_path_path_exists
|
125
|
+
@base.instance_eval { @log_path = nil }
|
126
|
+
@base.expects(:fetch).with('log_file_path', 'log/').returns('log/')
|
127
|
+
assert File.directory?('log/')
|
128
|
+
assert_equal File.expand_path('log/'), @base.log_path
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_log_path_path_created
|
132
|
+
path = File.expand_path('tmp/log_path_test')
|
133
|
+
@base.instance_eval { @log_path = nil }
|
134
|
+
@base.expects(:fetch).with('log_file_path', 'log/').returns('tmp/log_path_test')
|
135
|
+
assert !File.directory?(path) || FileUtils.rmdir(path)
|
136
|
+
@base.expects(:log!).never
|
137
|
+
assert_equal path, @base.log_path
|
138
|
+
assert File.directory?(path)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_log_path_path_unable_to_create
|
142
|
+
path = File.expand_path('tmp/log_path_test')
|
143
|
+
@base.instance_eval { @log_path = nil }
|
144
|
+
@base.expects(:fetch).with('log_file_path', 'log/').returns('tmp/log_path_test')
|
145
|
+
assert !File.directory?(path) || FileUtils.rmdir(path)
|
146
|
+
@base.expects(:log!).with("Error creating New Relic log directory '#{path}'", :error)
|
147
|
+
Dir.expects(:mkdir).with(path).raises('cannot make directory bro!')
|
148
|
+
assert_equal path, @base.log_path
|
149
|
+
assert !File.directory?(path)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_log_file_name
|
153
|
+
@base.expects(:fetch).with('log_file_name', 'newrelic_agent.log').returns('log_file_name')
|
154
|
+
assert_equal 'log_file_name', @base.log_file_name
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
@@ -58,7 +58,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
assert_equal :test, c.framework
|
60
60
|
assert_match /test/i, c.dispatcher_instance_id
|
61
|
-
assert("" == c.dispatcher.to_s)
|
61
|
+
assert("" == c.dispatcher.to_s, "Expected dispatcher to be empty, but was #{c.dispatcher.to_s}")
|
62
62
|
assert !c['enabled']
|
63
63
|
assert_equal false, c['monitor_mode']
|
64
64
|
c.local_env
|
@@ -129,20 +129,20 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
129
129
|
def test_config_apdex
|
130
130
|
assert_equal 1.1, c.apdex_t
|
131
131
|
end
|
132
|
-
def test_transaction_threshold
|
133
|
-
assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
134
|
-
assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
135
|
-
end
|
132
|
+
# def test_transaction_threshold
|
133
|
+
# assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
134
|
+
# assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
135
|
+
# end
|
136
136
|
def test_log_file_name
|
137
137
|
NewRelic::Control.instance.setup_log
|
138
138
|
assert_match /newrelic_agent.log$/, c.instance_variable_get('@log_file')
|
139
139
|
end
|
140
140
|
|
141
|
-
def test_transaction_threshold__apdex
|
142
|
-
forced_start
|
143
|
-
assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
144
|
-
assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
145
|
-
end
|
141
|
+
# def test_transaction_threshold__apdex
|
142
|
+
# forced_start
|
143
|
+
# assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
144
|
+
# assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
145
|
+
# end
|
146
146
|
|
147
147
|
def test_transaction_threshold__default
|
148
148
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
require 'new_relic/data_serialization'
|
3
|
+
class NewRelic::DataSerializationTest < Test::Unit::TestCase
|
4
|
+
def test_load_from_file
|
5
|
+
file = './log/newrelic_agent_store.db'
|
6
|
+
File.open(file, 'w') do |f|
|
7
|
+
f.write(Marshal.dump('a happy string'))
|
8
|
+
end
|
9
|
+
assert_equal('a happy string', NewRelic::DataSerialization.load_from_file, "should pull the dumped item from the file")
|
10
|
+
assert_equal(0, File.size(file), "Should not leave any data in the file")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_dump_to_file
|
14
|
+
file = './log/newrelic_agent_store.db'
|
15
|
+
expected_contents = Marshal.dump('a happy string')
|
16
|
+
NewRelic::DataSerialization.dump_to_file do
|
17
|
+
'a happy string'
|
18
|
+
end
|
19
|
+
assert_equal(expected_contents, File.read(file), "should have dumped the contents")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_dump_to_file_yields_old_data
|
23
|
+
file = './log/newrelic_agent_store.db'
|
24
|
+
expected_contents = 'a happy string'
|
25
|
+
File.open(file, 'w') do |f|
|
26
|
+
f.write(Marshal.dump(expected_contents))
|
27
|
+
end
|
28
|
+
contents = nil
|
29
|
+
NewRelic::DataSerialization.dump_to_file do |old_data|
|
30
|
+
contents = old_data
|
31
|
+
'a happy string'
|
32
|
+
end
|
33
|
+
assert_equal(contents, expected_contents, "should have dumped the contents")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_round_trip
|
37
|
+
NewRelic::DataSerialization.dump_to_file do
|
38
|
+
'a' * 30
|
39
|
+
end
|
40
|
+
assert_equal('a'*30, NewRelic::DataSerialization.load_from_file, "should be the same after serialization")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_send_data
|
44
|
+
NewRelic::DataSerialization.expects(:max_size).returns(20)
|
45
|
+
NewRelic::DataSerialization.dump_to_file do
|
46
|
+
"a" * 30
|
47
|
+
end
|
48
|
+
assert(NewRelic::DataSerialization.should_send_data?, 'Should be over limit')
|
49
|
+
end
|
50
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
2
|
class NewRelic::LocalEnvironmentTest < Test::Unit::TestCase
|
3
3
|
|
4
|
-
def teardown
|
4
|
+
def self.teardown
|
5
5
|
# To remove mock server instances from ObjectSpace
|
6
6
|
ObjectSpace.garbage_collect
|
7
7
|
super
|
@@ -13,18 +13,18 @@ class NewRelic::LocalEnvironmentTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
MOCK_OPTIONS = MockOptions.new
|
15
15
|
|
16
|
-
def test_environment
|
17
|
-
e = NewRelic::LocalEnvironment.new
|
18
|
-
assert(nil == e.environment) # working around a bug in 1.9.1
|
19
|
-
assert_match /test/i, e.dispatcher_instance_id
|
20
|
-
end
|
21
|
-
def test_no_webrick
|
22
|
-
Object.const_set :OPTIONS, 'foo'
|
23
|
-
e = NewRelic::LocalEnvironment.new
|
24
|
-
assert(nil == e.environment) # working around a bug in 1.9.1
|
25
|
-
assert_match /test/i, e.dispatcher_instance_id
|
26
|
-
Object.class_eval { remove_const :OPTIONS }
|
27
|
-
end
|
16
|
+
# def test_environment
|
17
|
+
# e = NewRelic::LocalEnvironment.new
|
18
|
+
# assert(nil == e.environment) # working around a bug in 1.9.1
|
19
|
+
# assert_match /test/i, e.dispatcher_instance_id
|
20
|
+
# end
|
21
|
+
# def test_no_webrick
|
22
|
+
# Object.const_set :OPTIONS, 'foo'
|
23
|
+
# e = NewRelic::LocalEnvironment.new
|
24
|
+
# assert(nil == e.environment) # working around a bug in 1.9.1
|
25
|
+
# assert_match /test/i, e.dispatcher_instance_id
|
26
|
+
# Object.class_eval { remove_const :OPTIONS }
|
27
|
+
# end
|
28
28
|
|
29
29
|
def test_passenger
|
30
30
|
class << self
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
require 'new_relic/metric_data'
|
3
|
+
class NewRelic::MetricDataTest < Test::Unit::TestCase
|
4
|
+
def test_initialize_basic
|
5
|
+
spec = mock('metric_spec')
|
6
|
+
stats = mock('stats')
|
7
|
+
metric_id = mock('metric_id')
|
8
|
+
md = NewRelic::MetricData.new(spec, stats, metric_id)
|
9
|
+
assert_equal spec, md.metric_spec
|
10
|
+
assert_equal stats, md.stats
|
11
|
+
assert_equal metric_id, md.metric_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_eql_basic
|
15
|
+
spec = mock('metric_spec')
|
16
|
+
stats = mock('stats')
|
17
|
+
metric_id = mock('metric_id')
|
18
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
19
|
+
md2 = NewRelic::MetricData.new(spec, stats, metric_id)
|
20
|
+
assert(md1.eql?(md2), "The example metric data objects should be eql?: #{md1.inspect} #{md2.inspect}")
|
21
|
+
assert(md2.eql?(md1), "The example metric data objects should be eql?: #{md1.inspect} #{md2.inspect}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_eql_unequal_specs
|
25
|
+
|
26
|
+
spec = mock('metric_spec')
|
27
|
+
other_spec = mock('other_spec')
|
28
|
+
stats = mock('stats')
|
29
|
+
metric_id = mock('metric_id')
|
30
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
31
|
+
md2 = NewRelic::MetricData.new(other_spec, stats, metric_id)
|
32
|
+
assert(!md1.eql?(md2), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
|
33
|
+
assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
|
34
|
+
end
|
35
|
+
def test_eql_unequal_stats
|
36
|
+
spec = mock('metric_spec')
|
37
|
+
stats = mock('stats')
|
38
|
+
other_stats = mock('other_stats')
|
39
|
+
metric_id = mock('metric_id')
|
40
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
41
|
+
md2 = NewRelic::MetricData.new(spec, other_stats, metric_id)
|
42
|
+
assert(!md1.eql?(md2), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
|
43
|
+
assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_eql_unequal_metric_ids_dont_matter
|
47
|
+
spec = mock('metric_spec')
|
48
|
+
stats = mock('stats')
|
49
|
+
metric_id = mock('metric_id')
|
50
|
+
other_metric_id = mock('other_metric_id')
|
51
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
52
|
+
md2 = NewRelic::MetricData.new(spec, stats, other_metric_id)
|
53
|
+
assert(md1.eql?(md2), "The example metric data objects should be eql? with different metric_ids: #{md1.inspect} #{md2.inspect}")
|
54
|
+
assert(md2.eql?(md1), "The example metric data objects should be eql? with different metric_ids: #{md1.inspect} #{md2.inspect}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_original_spec_basic
|
58
|
+
spec = mock('metric_spec')
|
59
|
+
stats = mock('stats')
|
60
|
+
metric_id = mock('metric_id')
|
61
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
62
|
+
original_spec = md1.instance_variable_get('@original_spec')
|
63
|
+
assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
|
64
|
+
assert_equal(spec, md1.metric_spec, "should return the metric spec for original spec when original spec is nil, but was #{md1.original_spec}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_metric_spec_equal_should_not_set_original_spec_with_no_metric_spec
|
68
|
+
stats = mock('stats')
|
69
|
+
metric_id = mock('metric_id')
|
70
|
+
md1 = NewRelic::MetricData.new(nil, stats, metric_id)
|
71
|
+
original_spec = md1.instance_variable_get('@original_spec')
|
72
|
+
assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
|
73
|
+
|
74
|
+
new_spec = mock('new metric_spec')
|
75
|
+
assert_equal(new_spec, md1.metric_spec=(new_spec), "should return the new spec")
|
76
|
+
|
77
|
+
new_original_spec = md1.instance_variable_get('@original_spec')
|
78
|
+
assert_equal(nil, new_original_spec, "should not set @original_spec but was #{new_original_spec.inspect}")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_metric_spec_equal_should_set_original_spec_with_existing_metric_spec
|
82
|
+
spec = mock('metric_spec')
|
83
|
+
stats = mock('stats')
|
84
|
+
metric_id = mock('metric_id')
|
85
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
86
|
+
original_spec = md1.instance_variable_get('@original_spec')
|
87
|
+
assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
|
88
|
+
|
89
|
+
new_spec = mock('new metric_spec')
|
90
|
+
assert_equal(new_spec, md1.metric_spec=(new_spec), "should return the new spec")
|
91
|
+
|
92
|
+
new_original_spec = md1.instance_variable_get('@original_spec')
|
93
|
+
assert_equal(spec, new_original_spec, "should set @original_spec to the existing metric_spec but was #{new_original_spec.inspect}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_hash
|
97
|
+
spec = mock('metric_spec')
|
98
|
+
stats = mock('stats')
|
99
|
+
metric_id = mock('metric_id')
|
100
|
+
md1 = NewRelic::MetricData.new(spec, stats, metric_id)
|
101
|
+
assert((spec.hash ^ stats.hash) == md1.hash, "expected #{spec.hash ^ stats.hash} to equal #{md1.hash}")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_to_json_no_metric_id
|
105
|
+
md = NewRelic::MetricData.new(NewRelic::MetricSpec.new('Custom/test/method', ''), NewRelic::MethodTraceStats.new, nil)
|
106
|
+
json = md.to_json
|
107
|
+
assert(json.include?('"Custom/test/method"'), "should include the metric spec in the json")
|
108
|
+
assert(json.include?('"metric_id":null}'), "should have a null metric_id")
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_to_json_with_metric_id
|
112
|
+
md = NewRelic::MetricData.new(NewRelic::MetricSpec.new('Custom/test/method', ''), NewRelic::MethodTraceStats.new, 12345)
|
113
|
+
assert_equal('{"metric_spec":null,"stats":{"total_exclusive_time":0.0,"min_call_time":0.0,"call_count":0,"sum_of_squares":0.0,"total_call_time":0.0,"max_call_time":0.0},"metric_id":12345}', md.to_json, "should not include the metric spec and should have a metric_id")
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_to_s_with_metric_spec
|
117
|
+
md = NewRelic::MetricData.new(NewRelic::MetricSpec.new('Custom/test/method', ''), NewRelic::MethodTraceStats.new, 12345)
|
118
|
+
assert_equal('Custom/test/method(): [01/01/70 12:00AM UTC, 0.000s; 0 calls 0s]', md.to_s, "should not include the metric id and should include the metric spec")
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_to_s_without_metric_spec
|
122
|
+
md = NewRelic::MetricData.new(nil, NewRelic::MethodTraceStats.new, 12345)
|
123
|
+
assert_equal('12345: [01/01/70 12:00AM UTC, 0.000s; 0 calls 0s]', md.to_s, "should include the metric id and not have a metric spec")
|
124
|
+
end
|
125
|
+
end
|
@@ -59,6 +59,14 @@ class NewRelic::MetricSpecTest < Test::Unit::TestCase
|
|
59
59
|
compare_metric_data(metric_data, import)
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_truncate!
|
63
|
+
spec = NewRelic::MetricSpec.new('a', 'b')
|
64
|
+
spec.name = "a" * 300
|
65
|
+
spec.scope = "b" * 300
|
66
|
+
spec.truncate!
|
67
|
+
assert_equal("a" * 255, spec.name, "should have shortened the name")
|
68
|
+
assert_equal("b" * 255, spec.scope, "should have shortened the scope")
|
69
|
+
end
|
62
70
|
|
63
71
|
private
|
64
72
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helper'))
|
2
|
+
require 'new_relic/transaction_analysis/segment_summary'
|
3
|
+
class NewRelic::TransactionAnalysis::SegmentSummaryTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@sample = mock('sample')
|
7
|
+
@ss = NewRelic::TransactionAnalysis::SegmentSummary.new('Controller/foo', @sample)
|
8
|
+
end
|
9
|
+
|
10
|
+
# these are mostly stub tests just making sure that the API doesn't
|
11
|
+
# change if anyone ever needs to modify it.
|
12
|
+
|
13
|
+
def test_insert
|
14
|
+
segment = mock('segment')
|
15
|
+
segment.expects(:metric_name).returns('Controller/foo')
|
16
|
+
segment.expects(:duration).returns(0.1)
|
17
|
+
segment.expects(:exclusive_duration).returns(0.1)
|
18
|
+
@ss << segment
|
19
|
+
assert_equal 0.1, @ss.total_time
|
20
|
+
assert_equal 0.1, @ss.exclusive_time
|
21
|
+
assert_equal 1, @ss.call_count
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_insert_error
|
25
|
+
segment = mock('segment')
|
26
|
+
segment.expects(:metric_name).returns('Controller/bar').twice
|
27
|
+
assert_raise(ArgumentError) do
|
28
|
+
@ss << segment
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_average_time
|
33
|
+
@ss.total_time = 0.1
|
34
|
+
@ss.call_count = 2
|
35
|
+
assert_equal 0.05, @ss.average_time
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_average_exclusive_time
|
39
|
+
@ss.exclusive_time = 0.1
|
40
|
+
@ss.call_count = 2
|
41
|
+
assert_equal 0.05, @ss.average_exclusive_time
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_exclusive_time_percentage_nil
|
45
|
+
@ss.exclusive_time = nil
|
46
|
+
assert_equal 0, @ss.exclusive_time_percentage
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_exclusive_time_percentage
|
50
|
+
@ss.exclusive_time = 0.05
|
51
|
+
@sample.expects(:duration).returns(0.1).times(3)
|
52
|
+
assert_equal 0.5, @ss.exclusive_time_percentage
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_total_time_percentage_nil
|
56
|
+
@ss.total_time = nil
|
57
|
+
assert_equal 0, @ss.total_time_percentage
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_total_time_percentage
|
61
|
+
@ss.total_time = 0.05
|
62
|
+
@sample.expects(:duration).returns(0.1).times(3)
|
63
|
+
assert_equal 0.5, @ss.total_time_percentage
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_ui_name_default
|
67
|
+
@ss.metric_name = 'Remainder'
|
68
|
+
assert_equal 'Remainder', @ss.ui_name
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_ui_name_lookup
|
72
|
+
mocked_object = mock('metric parser obj')
|
73
|
+
mocked_object.expects(:developer_name).returns('Developer Name')
|
74
|
+
NewRelic::MetricParser::MetricParser.expects(:parse).with('Controller/foo').returns(mocked_object)
|
75
|
+
assert_equal 'Developer Name', @ss.ui_name
|
76
|
+
end
|
77
|
+
end
|