dolores_rpm 3.2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +559 -0
- data/LICENSE +64 -0
- data/README.rdoc +179 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/dolores_rpm-3.3.4.fork.gem +0 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent/agent.rb +1311 -0
- data/lib/new_relic/agent/beacon_configuration.rb +110 -0
- data/lib/new_relic/agent/browser_monitoring.rb +102 -0
- data/lib/new_relic/agent/busy_calculator.rb +99 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/database.rb +203 -0
- data/lib/new_relic/agent/error_collector.rb +251 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +27 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +424 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +57 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +332 -0
- data/lib/new_relic/agent/instrumentation/net.rb +29 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +36 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +115 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +118 -0
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +122 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +58 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/method_tracer.rb +528 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +144 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/sql_sampler.rb +267 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +208 -0
- data/lib/new_relic/agent/stats_engine.rb +25 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
- data/lib/new_relic/agent/transaction_sampler.rb +397 -0
- data/lib/new_relic/agent/worker_loop.rb +89 -0
- data/lib/new_relic/agent.rb +454 -0
- data/lib/new_relic/collection_helper.rb +75 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control/class_methods.rb +53 -0
- data/lib/new_relic/control/configuration.rb +202 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +31 -0
- data/lib/new_relic/control/frameworks/rails.rb +164 -0
- data/lib/new_relic/control/frameworks/rails3.rb +75 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/instance_methods.rb +179 -0
- data/lib/new_relic/control/instrumentation.rb +100 -0
- data/lib/new_relic/control/logging_methods.rb +143 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +114 -0
- data/lib/new_relic/control.rb +46 -0
- data/lib/new_relic/data_serialization.rb +157 -0
- data/lib/new_relic/delayed_job_injection.rb +46 -0
- data/lib/new_relic/language_support.rb +69 -0
- data/lib/new_relic/local_environment.rb +414 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +51 -0
- data/lib/new_relic/metric_spec.rb +75 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/browser_monitoring.rb +68 -0
- data/lib/new_relic/rack/developer_mode.rb +268 -0
- data/lib/new_relic/recipes.rb +73 -0
- data/lib/new_relic/stats.rb +388 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- 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 +201 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/transaction_sample.rb +245 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +19 -0
- data/newrelic.yml +265 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/new_relic/agent/agent/connect_test.rb +410 -0
- data/test/new_relic/agent/agent/start_test.rb +255 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +139 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +363 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +108 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +278 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/database_test.rb +162 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +175 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +538 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +172 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +387 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- 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/sql_sampler_test.rb +160 -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 +82 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +185 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +955 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/agent_test.rb +175 -0
- data/test/new_relic/collection_helper_test.rb +149 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/configuration_test.rb +72 -0
- data/test/new_relic/control/logging_methods_test.rb +185 -0
- data/test/new_relic/control_test.rb +254 -0
- data/test/new_relic/data_serialization_test.rb +208 -0
- data/test/new_relic/delayed_job_injection_test.rb +16 -0
- data/test/new_relic/local_environment_test.rb +72 -0
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +43 -0
- data/test/new_relic/stats_test.rb +426 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -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 +389 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +164 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +154 -0
- data/ui/helpers/developer_mode_helper.rb +357 -0
- data/ui/helpers/google_pie_chart.rb +48 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +53 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +62 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +122 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- metadata +398 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
ENV['SKIP_RAILS'] = 'true'
|
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
|
3
|
+
##require "new_relic/stats"
|
|
4
|
+
|
|
5
|
+
module NewRelic; class TestObjectForStats
|
|
6
|
+
include Stats
|
|
7
|
+
attr_accessor :total_call_time
|
|
8
|
+
attr_accessor :total_exclusive_time
|
|
9
|
+
attr_accessor :begin_time
|
|
10
|
+
attr_accessor :end_time
|
|
11
|
+
attr_accessor :call_count
|
|
12
|
+
end; end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NewRelic::StatsTest < Test::Unit::TestCase
|
|
16
|
+
|
|
17
|
+
def test_checked_calculation_standard
|
|
18
|
+
obj = NewRelic::TestObjectForStats.new
|
|
19
|
+
|
|
20
|
+
assert_equal(1.0, obj.checked_calculation(1, 1))
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_checked_calculation_with_zero
|
|
25
|
+
obj = NewRelic::TestObjectForStats.new
|
|
26
|
+
assert_equal(0.0, obj.checked_calculation(1, 0))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_checked_calculation_should_return_floats
|
|
30
|
+
obj = NewRelic::TestObjectForStats.new
|
|
31
|
+
assert_equal(0.5, obj.checked_calculation(1, 2))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_sum_attributes
|
|
35
|
+
first = NewRelic::TestObjectForStats.new
|
|
36
|
+
second = mock('other object')
|
|
37
|
+
first.expects(:call_count).returns(6)
|
|
38
|
+
second.expects(:call_count).returns(8)
|
|
39
|
+
first.expects(:update_totals).with(second)
|
|
40
|
+
first.expects(:stack_min_max_from).with(second)
|
|
41
|
+
first.expects(:update_boundaries).with(second)
|
|
42
|
+
first.expects(:call_count=).with(8)
|
|
43
|
+
first.sum_attributes(second)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def mock_plusequals(first, second, method, first_value, second_value)
|
|
47
|
+
first.expects(method).returns(first_value)
|
|
48
|
+
second.expects(method).returns(second_value)
|
|
49
|
+
first.expects("#{method}=".to_sym).with(first_value + second_value)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_stack_min_max_from
|
|
53
|
+
first = NewRelic::TestObjectForStats.new
|
|
54
|
+
second = mock('other object')
|
|
55
|
+
mock_plusequals(first, second, :min_call_time, 1.5, 0.5)
|
|
56
|
+
mock_plusequals(first, second, :max_call_time, 1.0, 3.0)
|
|
57
|
+
|
|
58
|
+
first.stack_min_max_from(second)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_update_boundaries
|
|
62
|
+
first = NewRelic::TestObjectForStats.new
|
|
63
|
+
second = mock('other object')
|
|
64
|
+
|
|
65
|
+
first.expects(:should_replace_begin_time?).with(second).returns(true)
|
|
66
|
+
first.expects(:should_replace_end_time?).with(second).returns(true)
|
|
67
|
+
first.expects(:begin_time=).with('other_begin_time')
|
|
68
|
+
first.expects(:end_time=).with('other_end_time')
|
|
69
|
+
|
|
70
|
+
second.expects(:begin_time).returns('other_begin_time')
|
|
71
|
+
second.expects(:end_time).returns('other_end_time')
|
|
72
|
+
first.update_boundaries(second)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_should_replace_end_time
|
|
76
|
+
first = NewRelic::TestObjectForStats.new
|
|
77
|
+
second = mock('other object')
|
|
78
|
+
|
|
79
|
+
first.expects(:end_time).returns(Time.at(1))
|
|
80
|
+
second.expects(:end_time).returns(Time.at(2))
|
|
81
|
+
assert first.should_replace_end_time?(second), 'should replace end time when the other stat is larger'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_should_replace_begin_time_base
|
|
85
|
+
first = NewRelic::TestObjectForStats.new
|
|
86
|
+
second = mock('other object')
|
|
87
|
+
|
|
88
|
+
first.expects(:begin_time).returns(Time.at(2))
|
|
89
|
+
second.expects(:begin_time).returns(Time.at(1))
|
|
90
|
+
|
|
91
|
+
assert first.should_replace_begin_time?(second), 'should replace the begin time when it is larger'
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_should_replace_begin_time_empty
|
|
95
|
+
first = NewRelic::TestObjectForStats.new
|
|
96
|
+
second = mock('other object')
|
|
97
|
+
|
|
98
|
+
first.expects(:begin_time).returns(Time.at(0))
|
|
99
|
+
second.expects(:begin_time).returns(Time.at(2))
|
|
100
|
+
|
|
101
|
+
first.expects(:begin_time).returns(Time.at(0))
|
|
102
|
+
|
|
103
|
+
assert first.should_replace_begin_time?(second), "should replace the begin time if self.call_count == 0"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_update_totals
|
|
107
|
+
first = NewRelic::TestObjectForStats.new
|
|
108
|
+
second = mock('other object')
|
|
109
|
+
|
|
110
|
+
[:total_call_time, :total_exclusive_time, :sum_of_squares].each do |method|
|
|
111
|
+
mock_plusequals(first, second, method, 2.0, 3.0)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
first.update_totals(second)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_min_time_less
|
|
118
|
+
first = NewRelic::TestObjectForStats.new
|
|
119
|
+
second = mock('other object')
|
|
120
|
+
|
|
121
|
+
second.expects(:min_call_time).returns(1.0)
|
|
122
|
+
first.expects(:min_call_time).returns(2.0)
|
|
123
|
+
second.expects(:call_count).returns(1)
|
|
124
|
+
|
|
125
|
+
first.min_time_less?(second)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_expand_min_max_to
|
|
129
|
+
first = NewRelic::TestObjectForStats.new
|
|
130
|
+
second = mock('other object')
|
|
131
|
+
|
|
132
|
+
first.expects(:min_time_less?).with(second).returns(true)
|
|
133
|
+
first.expects(:max_call_time).returns(3.0)
|
|
134
|
+
|
|
135
|
+
second.expects(:min_call_time).returns(1.0)
|
|
136
|
+
second.expects(:max_call_time).returns(4.0).twice
|
|
137
|
+
|
|
138
|
+
first.expects(:min_call_time=).with(1.0)
|
|
139
|
+
first.expects(:max_call_time=).with(4.0)
|
|
140
|
+
|
|
141
|
+
first.expand_min_max_to(second)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_simple
|
|
147
|
+
stats = NewRelic::MethodTraceStats.new
|
|
148
|
+
validate stats, 0, 0, 0, 0
|
|
149
|
+
|
|
150
|
+
assert_equal stats.call_count,0
|
|
151
|
+
stats.trace_call 10
|
|
152
|
+
stats.trace_call 20
|
|
153
|
+
stats.trace_call 30
|
|
154
|
+
|
|
155
|
+
validate stats, 3, (10+20+30), 10, 30
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_to_s
|
|
159
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
160
|
+
s1.trace_call 10
|
|
161
|
+
assert_equal("[01/01/70 12:00AM UTC, 0.000s; 1 calls 10s]", s1.to_s)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def test_time_str
|
|
165
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
166
|
+
assert_equal(s1.time_str(10), "10 ms")
|
|
167
|
+
assert_equal(s1.time_str(4999), "4999 ms")
|
|
168
|
+
assert_equal(s1.time_str(5000), "5.00 s")
|
|
169
|
+
assert_equal(s1.time_str(5010), "5.01 s")
|
|
170
|
+
assert_equal(s1.time_str(9999), "10.00 s")
|
|
171
|
+
assert_equal(s1.time_str(10000), "10.0 s")
|
|
172
|
+
assert_equal(s1.time_str(20000), "20.0 s")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_fraction_of
|
|
176
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
177
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
178
|
+
s1.trace_call 10
|
|
179
|
+
s2.trace_call 20
|
|
180
|
+
assert_equal(s1.fraction_of(s2).to_s, 'NaN')
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_fraction_of2
|
|
184
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
185
|
+
s1.trace_call 10
|
|
186
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
187
|
+
assert_equal(s1.fraction_of(s2).to_s, 'NaN')
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_multiply_by
|
|
191
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
192
|
+
s1.trace_call 10
|
|
193
|
+
assert_equal("[01/01/70 12:00AM UTC, 0.000s; 10 calls 10s]", s1.multiply_by(10).to_s)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def test_get_apdex
|
|
197
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
198
|
+
s1.trace_call 10
|
|
199
|
+
assert_equal(s1.get_apdex, [1, 10, 10])
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_apdex_score
|
|
203
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
204
|
+
s1.trace_call 10
|
|
205
|
+
assert_in_delta(s1.apdex_score, 0.285714285714286, 0.0000001)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_as_percentage
|
|
209
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
210
|
+
s1.trace_call 10
|
|
211
|
+
assert_equal(s1.as_percentage, 1000.0)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def test_calls_per_minute
|
|
215
|
+
|
|
216
|
+
s1 = NewRelic::TestObjectForStats.new
|
|
217
|
+
s1.call_count = 1
|
|
218
|
+
s1.begin_time = Time.at(0)
|
|
219
|
+
s1.end_time = Time.at(30)
|
|
220
|
+
assert_equal(s1.calls_per_minute, 2)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_total_call_time_per_minute
|
|
224
|
+
s1 = NewRelic::TestObjectForStats.new
|
|
225
|
+
s1.begin_time = Time.at(0)
|
|
226
|
+
s1.end_time = Time.at(0)
|
|
227
|
+
assert_equal(0, s1.total_call_time_per_minute)
|
|
228
|
+
s1.begin_time = Time.at(0)
|
|
229
|
+
s1.end_time = Time.at(30)
|
|
230
|
+
s1.total_call_time = 10
|
|
231
|
+
assert_equal(20, s1.total_call_time_per_minute)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def test_time_percentage
|
|
235
|
+
s1 = NewRelic::TestObjectForStats.new
|
|
236
|
+
s1.begin_time = Time.at(0)
|
|
237
|
+
s1.end_time = Time.at(0)
|
|
238
|
+
assert_equal(0, s1.time_percentage)
|
|
239
|
+
s1.total_call_time = 10
|
|
240
|
+
s1.begin_time = Time.at(0)
|
|
241
|
+
s1.end_time = Time.at(30)
|
|
242
|
+
assert_equal((1.0 / 3.0), s1.time_percentage)
|
|
243
|
+
s1.total_call_time = 20
|
|
244
|
+
assert_equal((2.0 / 3.0), s1.time_percentage)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def test_exclusive_time_percentage
|
|
248
|
+
s1 = NewRelic::TestObjectForStats.new
|
|
249
|
+
s1.begin_time = Time.at(0)
|
|
250
|
+
s1.end_time = Time.at(0)
|
|
251
|
+
assert_equal(0, s1.exclusive_time_percentage)
|
|
252
|
+
s1.total_exclusive_time = 10
|
|
253
|
+
s1.begin_time = Time.at(0)
|
|
254
|
+
s1.end_time = Time.at(30)
|
|
255
|
+
assert_equal((1.0 / 3.0), s1.exclusive_time_percentage)
|
|
256
|
+
s1.total_exclusive_time = 20
|
|
257
|
+
assert_equal((2.0 / 3.0), s1.exclusive_time_percentage)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def test_sum_merge
|
|
261
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
262
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
263
|
+
s1.trace_call 10
|
|
264
|
+
s2.trace_call 20
|
|
265
|
+
s2.freeze
|
|
266
|
+
|
|
267
|
+
validate s1, 1, 10, 10, 10
|
|
268
|
+
validate s2, 1, 20, 20, 20
|
|
269
|
+
s1.sum_merge! s2
|
|
270
|
+
validate s1, 1, (10+20), 10 + 20, 20 + 10
|
|
271
|
+
validate s2, 1, 20, 20, 20
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def test_sum_merge_with_exclusive
|
|
275
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
276
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
277
|
+
|
|
278
|
+
s1.trace_call 10, 5
|
|
279
|
+
s2.trace_call 20, 10
|
|
280
|
+
s2.freeze
|
|
281
|
+
|
|
282
|
+
validate s1, 1, 10, 10, 10, 5
|
|
283
|
+
validate s2, 1, 20, 20, 20, 10
|
|
284
|
+
s1.sum_merge! s2
|
|
285
|
+
validate s1, 1, (10+20), 10 + 20, 20 + 10, (10+5)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def test_merge
|
|
289
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
290
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
291
|
+
|
|
292
|
+
s1.trace_call 10
|
|
293
|
+
s2.trace_call 20
|
|
294
|
+
s2.freeze
|
|
295
|
+
|
|
296
|
+
validate s2, 1, 20, 20, 20
|
|
297
|
+
s3 = s1.merge s2
|
|
298
|
+
validate s3, 2, (10+20), 10, 20
|
|
299
|
+
validate s1, 1, 10, 10, 10
|
|
300
|
+
validate s2, 1, 20, 20, 20
|
|
301
|
+
|
|
302
|
+
s1.merge! s2
|
|
303
|
+
validate s1, 2, (10+20), 10, 20
|
|
304
|
+
validate s2, 1, 20, 20, 20
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def test_merge_with_exclusive
|
|
308
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
309
|
+
|
|
310
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
311
|
+
|
|
312
|
+
s1.trace_call 10, 5
|
|
313
|
+
s2.trace_call 20, 10
|
|
314
|
+
s2.freeze
|
|
315
|
+
|
|
316
|
+
validate s2, 1, 20, 20, 20, 10
|
|
317
|
+
s3 = s1.merge s2
|
|
318
|
+
validate s3, 2, (10+20), 10, 20, (10+5)
|
|
319
|
+
validate s1, 1, 10, 10, 10, 5
|
|
320
|
+
validate s2, 1, 20, 20, 20, 10
|
|
321
|
+
|
|
322
|
+
s1.merge! s2
|
|
323
|
+
validate s1, 2, (10+20), 10, 20, (5+10)
|
|
324
|
+
validate s2, 1, 20, 20, 20, 10
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def test_merge_array
|
|
328
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
329
|
+
merges = []
|
|
330
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
|
331
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
|
332
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
|
333
|
+
|
|
334
|
+
s1.merge! merges
|
|
335
|
+
validate s1, 3, 3, 1, 1
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def test_freeze
|
|
339
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
340
|
+
|
|
341
|
+
s1.trace_call 10
|
|
342
|
+
s1.freeze
|
|
343
|
+
|
|
344
|
+
begin
|
|
345
|
+
# the following should throw an exception because s1 is frozen
|
|
346
|
+
s1.trace_call 20
|
|
347
|
+
assert false
|
|
348
|
+
rescue StandardError
|
|
349
|
+
assert s1.frozen?
|
|
350
|
+
validate s1, 1, 10, 10, 10
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def test_std_dev
|
|
355
|
+
s = NewRelic::MethodTraceStats.new
|
|
356
|
+
s.trace_call 1
|
|
357
|
+
assert s.standard_deviation == 0
|
|
358
|
+
|
|
359
|
+
s = NewRelic::MethodTraceStats.new
|
|
360
|
+
s.trace_call 10
|
|
361
|
+
s.trace_call 10
|
|
362
|
+
s.sum_of_squares = nil
|
|
363
|
+
assert s.standard_deviation == 0
|
|
364
|
+
|
|
365
|
+
s = NewRelic::MethodTraceStats.new
|
|
366
|
+
s.trace_call 0.001
|
|
367
|
+
s.trace_call 0.001
|
|
368
|
+
assert s.standard_deviation == 0
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
s = NewRelic::MethodTraceStats.new
|
|
372
|
+
s.trace_call 10
|
|
373
|
+
s.trace_call 10
|
|
374
|
+
s.trace_call 10
|
|
375
|
+
s.trace_call 10
|
|
376
|
+
s.trace_call 10
|
|
377
|
+
s.trace_call 10
|
|
378
|
+
assert s.standard_deviation == 0
|
|
379
|
+
|
|
380
|
+
s = NewRelic::MethodTraceStats.new
|
|
381
|
+
s.trace_call 4
|
|
382
|
+
s.trace_call 7
|
|
383
|
+
s.trace_call 13
|
|
384
|
+
s.trace_call 16
|
|
385
|
+
s.trace_call 8
|
|
386
|
+
s.trace_call 4
|
|
387
|
+
assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
|
|
388
|
+
|
|
389
|
+
s.trace_call 9
|
|
390
|
+
s.trace_call 3
|
|
391
|
+
s.trace_call 1000
|
|
392
|
+
s.trace_call 4
|
|
393
|
+
|
|
394
|
+
# calculated stdev (population, not sample) from a spreadsheet.
|
|
395
|
+
assert_in_delta(s.standard_deviation, 297.76, 0.01)
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def test_std_dev_merge
|
|
399
|
+
s1 = NewRelic::MethodTraceStats.new
|
|
400
|
+
s1.trace_call 4
|
|
401
|
+
s1.trace_call 7
|
|
402
|
+
|
|
403
|
+
s2 = NewRelic::MethodTraceStats.new
|
|
404
|
+
s2.trace_call 13
|
|
405
|
+
s2.trace_call 16
|
|
406
|
+
|
|
407
|
+
s3 = s1.merge(s2)
|
|
408
|
+
|
|
409
|
+
assert_equal(s1.sum_of_squares, 4*4 + 7*7)
|
|
410
|
+
assert_in_delta(s1.standard_deviation, 1.5, 0.01)
|
|
411
|
+
|
|
412
|
+
assert_in_delta(s2.standard_deviation, 1.5, 0.01)
|
|
413
|
+
assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
|
|
414
|
+
assert_in_delta(s3.standard_deviation, 4.743, 0.01)
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
private
|
|
418
|
+
def validate (stats, count, total, min, max, exclusive = nil)
|
|
419
|
+
assert_equal stats.call_count, count
|
|
420
|
+
assert_equal stats.total_call_time, total
|
|
421
|
+
assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
|
|
422
|
+
assert_equal stats.min_call_time, min
|
|
423
|
+
assert_equal stats.max_call_time, max
|
|
424
|
+
assert_equal stats.total_exclusive_time, exclusive if exclusive
|
|
425
|
+
end
|
|
426
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
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_nesting_total_time
|
|
67
|
+
segment = mock('segment')
|
|
68
|
+
segment.expects(:metric_name).twice.returns('Controller/foo')
|
|
69
|
+
segment.expects(:duration).returns(0.1)
|
|
70
|
+
segment.expects(:exclusive_duration).returns(0)
|
|
71
|
+
@ss << segment
|
|
72
|
+
segment.expects(:exclusive_duration).returns(0.1)
|
|
73
|
+
@ss.current_nest_count += 1
|
|
74
|
+
@ss << segment
|
|
75
|
+
assert_equal 0.1, @ss.total_time
|
|
76
|
+
assert_equal 0.1, @ss.exclusive_time
|
|
77
|
+
assert_equal 2, @ss.call_count
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_ui_name_default
|
|
81
|
+
@ss.metric_name = 'Remainder'
|
|
82
|
+
assert_equal 'Remainder', @ss.ui_name
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_ui_name_lookup
|
|
86
|
+
mocked_object = mock('metric parser obj')
|
|
87
|
+
mocked_object.expects(:developer_name).returns('Developer Name')
|
|
88
|
+
NewRelic::MetricParser::MetricParser.expects(:parse).with('Controller/foo').returns(mocked_object)
|
|
89
|
+
assert_equal 'Developer Name', @ss.ui_name
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
|
2
|
+
require 'new_relic/transaction_analysis'
|
|
3
|
+
class NewRelic::TransactionAnalysisTest < Test::Unit::TestCase
|
|
4
|
+
include NewRelic::TransactionAnalysis
|
|
5
|
+
|
|
6
|
+
# these are mostly stub tests just making sure that the API doesn't
|
|
7
|
+
# change if anyone ever needs to modify it.
|
|
8
|
+
|
|
9
|
+
def test_database_time
|
|
10
|
+
self.expects(:time_percentage).with(/^Database\/.*/)
|
|
11
|
+
database_time
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_render_time
|
|
15
|
+
self.expects(:time_percentage).with(/^View\/.*/)
|
|
16
|
+
render_time
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_breakdown_data_default
|
|
20
|
+
root_segment = mock('root_segment')
|
|
21
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
22
|
+
# #to_a on it - which is fun and exciting
|
|
23
|
+
root_segment.stubs(:to_a).returns([root_segment])
|
|
24
|
+
other_segment = mock('other_segment')
|
|
25
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
26
|
+
# #to_a on it - which is fun and exciting
|
|
27
|
+
other_segment.stubs(:to_a).returns([other_segment])
|
|
28
|
+
other_segment.expects(:metric_name).twice.returns('Controller/foo')
|
|
29
|
+
other_segment.expects(:duration).returns(0.1)
|
|
30
|
+
other_segment.expects(:exclusive_duration).returns(0.1)
|
|
31
|
+
self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
|
|
32
|
+
self.expects(:root_segment).twice.returns(root_segment)
|
|
33
|
+
self.expects(:duration).returns(0.1)
|
|
34
|
+
data = breakdown_data
|
|
35
|
+
assert_equal 'Controller/foo', data[0].metric_name
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# kind of a hairy test, we're making sure that the data is truncated
|
|
39
|
+
# to one element by the limit
|
|
40
|
+
def test_breakdown_data_limit_one
|
|
41
|
+
root_segment = mock('root_segment')
|
|
42
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
43
|
+
# #to_a on it - which is fun and exciting
|
|
44
|
+
root_segment.stubs(:to_a).returns([root_segment])
|
|
45
|
+
other_segment = mock('other_segment')
|
|
46
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
47
|
+
# #to_a on it - which is fun and exciting
|
|
48
|
+
other_segment.stubs(:to_a).returns([other_segment])
|
|
49
|
+
other_segment.expects(:metric_name).twice.returns('Controller/foo')
|
|
50
|
+
other_segment.expects(:duration).returns(0.1)
|
|
51
|
+
other_segment.expects(:exclusive_duration).returns(0.1)
|
|
52
|
+
yet_another = mock('another segment')
|
|
53
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
54
|
+
# #to_a on it - which is fun and exciting
|
|
55
|
+
yet_another.stubs(:to_a).returns([yet_another])
|
|
56
|
+
yet_another.expects(:metric_name).twice.returns('Controller/bar')
|
|
57
|
+
yet_another.expects(:duration).returns(0.2)
|
|
58
|
+
yet_another.expects(:exclusive_duration).returns(0.2)
|
|
59
|
+
self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment, yet_another)
|
|
60
|
+
self.expects(:root_segment).times(3).returns(root_segment)
|
|
61
|
+
self.expects(:duration).returns(0.1)
|
|
62
|
+
data = breakdown_data(1)
|
|
63
|
+
assert_equal 1, data.size
|
|
64
|
+
assert_equal 'Controller/bar', data[0].metric_name
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_breakdown_data_remainder
|
|
68
|
+
root_segment = mock('root_segment')
|
|
69
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
70
|
+
# #to_a on it - which is fun and exciting
|
|
71
|
+
root_segment.stubs(:to_a).returns([root_segment])
|
|
72
|
+
other_segment = mock('other_segment')
|
|
73
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
74
|
+
# #to_a on it - which is fun and exciting
|
|
75
|
+
other_segment.stubs(:to_a).returns([other_segment])
|
|
76
|
+
other_segment.expects(:metric_name).twice.returns('Controller/foo')
|
|
77
|
+
other_segment.expects(:duration).returns(0.1)
|
|
78
|
+
other_segment.expects(:exclusive_duration).returns(0.1)
|
|
79
|
+
self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
|
|
80
|
+
self.expects(:root_segment).twice.returns(root_segment)
|
|
81
|
+
self.expects(:duration).returns(0.2)
|
|
82
|
+
data = breakdown_data
|
|
83
|
+
assert_equal 2, data.size
|
|
84
|
+
assert_equal 'Controller/foo', data[0].metric_name
|
|
85
|
+
assert_equal 'Remainder', data[1].metric_name
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_sql_segments_default
|
|
89
|
+
root_segment = mock('root_segment') # a segment with no data
|
|
90
|
+
root_segment.expects(:[]).with(:sql).returns(false)
|
|
91
|
+
root_segment.expects(:[]).with(:sql_obfuscated).returns(false)
|
|
92
|
+
root_segment.expects(:[]).with(:key).returns(nil)
|
|
93
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
94
|
+
# #to_a on it - which is fun and exciting
|
|
95
|
+
root_segment.stubs(:to_a).returns([root_segment])
|
|
96
|
+
other_segment = mock('other_segment') # a sql segment
|
|
97
|
+
other_segment.expects(:[]).with(:sql).returns(true)
|
|
98
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
99
|
+
# #to_a on it - which is fun and exciting
|
|
100
|
+
other_segment.stubs(:to_a).returns([other_segment])
|
|
101
|
+
self.expects(:each_segment).multiple_yields(root_segment, other_segment)
|
|
102
|
+
assert_equal [other_segment], sql_segments
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_time_percentage_default
|
|
106
|
+
root_segment = mock('root_segment')
|
|
107
|
+
root_segment.expects(:metric_name).returns('ROOT')
|
|
108
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
109
|
+
# #to_a on it - which is fun and exciting
|
|
110
|
+
root_segment.stubs(:to_a).returns([root_segment])
|
|
111
|
+
other_segment = mock('other_segment')
|
|
112
|
+
other_segment.expects(:metric_name).returns('Controller/foo')
|
|
113
|
+
other_segment.expects(:duration).returns(0.1)
|
|
114
|
+
# this is for 1.9 compatibility - calling each on something calls
|
|
115
|
+
# #to_a on it - which is fun and exciting
|
|
116
|
+
other_segment.stubs(:to_a).returns([other_segment])
|
|
117
|
+
self.expects(:duration).returns(0.2)
|
|
118
|
+
self.expects(:each_segment).multiple_yields(root_segment, other_segment)
|
|
119
|
+
assert_equal 50.0, time_percentage(/Controller\/.*/)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
|
2
|
+
require 'new_relic/transaction_sample/composite_segment'
|
|
3
|
+
class NewRelic::TransactionSample::CompositeSegmentTest < Test::Unit::TestCase
|
|
4
|
+
def test_composite_segment_creation
|
|
5
|
+
fake_segment = mock_segment
|
|
6
|
+
NewRelic::TransactionSample::CompositeSegment.new([fake_segment])
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def test_detail_segments_equals
|
|
10
|
+
fake_segment = mock_segment
|
|
11
|
+
cs = NewRelic::TransactionSample::CompositeSegment.new([fake_segment])
|
|
12
|
+
|
|
13
|
+
# note that this is a bare mock
|
|
14
|
+
# nothing should be called on it, for now
|
|
15
|
+
other_fake_segment = mock('other segment')
|
|
16
|
+
cs.detail_segments = [other_fake_segment]
|
|
17
|
+
|
|
18
|
+
assert_equal cs.detail_segments, [other_fake_segment]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
@@seg_count = 0
|
|
24
|
+
def mock_segment
|
|
25
|
+
@@seg_count += 1
|
|
26
|
+
segment = mock('segment ' + @@seg_count.to_s)
|
|
27
|
+
segment.expects(:entry_timestamp).returns(Time.now)
|
|
28
|
+
# note the following 'twice' - different than SummarySegment
|
|
29
|
+
segment.expects(:exit_timestamp).returns(Time.now).twice
|
|
30
|
+
segment.expects(:metric_name).returns('Custom/test/metric')
|
|
31
|
+
segment.expects(:called_segments).returns([])
|
|
32
|
+
segment
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
|
2
|
+
require 'new_relic/transaction_sample/fake_segment'
|
|
3
|
+
class NewRelic::TransactionSample::FakeSegmentTest < Test::Unit::TestCase
|
|
4
|
+
def test_fake_segment_creation
|
|
5
|
+
assert_nothing_raised do
|
|
6
|
+
NewRelic::TransactionSample::FakeSegment.new(0.1, 'Custom/test/metric', nil)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_parent_segment
|
|
11
|
+
# should be public in this class, but not in the parent class
|
|
12
|
+
s = NewRelic::TransactionSample::FakeSegment.new(0.1, 'Custom/test/metric', nil)
|
|
13
|
+
s.parent_segment = 'foo'
|
|
14
|
+
assert_equal('foo', s.instance_eval { @parent_segment } )
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|