newrelic_rpm 3.11.2.286 → 3.12.0.288

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/.yardopts +2 -0
  4. data/CHANGELOG +39 -4
  5. data/README.md +4 -2
  6. data/lib/new_relic/agent.rb +229 -214
  7. data/lib/new_relic/agent/agent.rb +23 -12
  8. data/lib/new_relic/agent/attribute_filter.rb +242 -0
  9. data/lib/new_relic/agent/attribute_processing.rb +62 -0
  10. data/lib/new_relic/agent/commands/xray_session_collection.rb +4 -1
  11. data/lib/new_relic/agent/configuration/default_source.rb +284 -30
  12. data/lib/new_relic/agent/configuration/high_security_source.rb +0 -8
  13. data/lib/new_relic/agent/configuration/manager.rb +1 -1
  14. data/lib/new_relic/agent/configuration/server_source.rb +86 -31
  15. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -1
  16. data/lib/new_relic/agent/cross_app_monitor.rb +8 -13
  17. data/lib/new_relic/agent/cross_app_tracing.rb +15 -15
  18. data/lib/new_relic/agent/custom_event_aggregator.rb +6 -2
  19. data/lib/new_relic/agent/database.rb +15 -2
  20. data/lib/new_relic/agent/datastores.rb +52 -38
  21. data/lib/new_relic/agent/datastores/metric_helper.rb +2 -1
  22. data/lib/new_relic/agent/encoding_normalizer.rb +82 -0
  23. data/lib/new_relic/agent/error_collector.rb +125 -169
  24. data/lib/new_relic/agent/hash_extensions.rb +26 -0
  25. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +13 -11
  26. data/lib/new_relic/agent/http_clients/uri_util.rb +9 -0
  27. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -3
  28. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +12 -5
  31. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +6 -7
  32. data/lib/new_relic/agent/instrumentation/curb.rb +6 -6
  33. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +4 -4
  34. data/lib/new_relic/agent/instrumentation/grape.rb +4 -3
  35. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -3
  36. data/lib/new_relic/agent/instrumentation/rails/errors.rb +9 -3
  37. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +6 -1
  38. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +9 -7
  39. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +8 -6
  40. data/lib/new_relic/agent/instrumentation/resque.rb +2 -3
  41. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -3
  42. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  43. data/lib/new_relic/agent/javascript_instrumentor.rb +24 -16
  44. data/lib/new_relic/agent/parameter_filtering.rb +8 -1
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -2
  46. data/lib/new_relic/agent/sql_sampler.rb +1 -0
  47. data/lib/new_relic/agent/stats.rb +0 -4
  48. data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -3
  49. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -0
  50. data/lib/new_relic/agent/supported_versions.rb +2 -2
  51. data/lib/new_relic/agent/traced_method_stack.rb +3 -3
  52. data/lib/new_relic/agent/transaction.rb +141 -118
  53. data/lib/new_relic/agent/transaction/attributes.rb +161 -0
  54. data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +4 -4
  55. data/lib/new_relic/agent/transaction/trace.rb +150 -0
  56. data/lib/new_relic/agent/transaction/trace_node.rb +190 -0
  57. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +2 -2
  58. data/lib/new_relic/agent/transaction_event_aggregator.rb +23 -7
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +37 -62
  60. data/lib/new_relic/agent/transaction_sampler.rb +29 -66
  61. data/lib/new_relic/cli/commands/install.rb +2 -2
  62. data/lib/new_relic/coerce.rb +15 -28
  63. data/lib/new_relic/json_wrapper.rb +14 -73
  64. data/lib/new_relic/noticed_error.rb +81 -5
  65. data/lib/new_relic/rack/browser_monitoring.rb +14 -19
  66. data/lib/new_relic/rack/developer_mode.rb +68 -14
  67. data/lib/new_relic/rack/developer_mode/segment_summary.rb +56 -0
  68. data/lib/new_relic/version.rb +2 -2
  69. data/newrelic.yml +19 -196
  70. data/test/agent_helper.rb +42 -36
  71. data/test/config/newrelic.yml +0 -1
  72. data/test/environments/rails40/Gemfile +1 -1
  73. data/test/environments/rails41/Gemfile +1 -1
  74. data/test/environments/rails42/Gemfile +1 -1
  75. data/test/fixtures/cross_agent_tests/attribute_configuration.json +35 -0
  76. data/test/fixtures/cross_agent_tests/sql_obfuscation/README.md +19 -12
  77. data/test/fixtures/cross_agent_tests/sql_obfuscation/sql_obfuscation.json +365 -0
  78. data/test/multiverse/lib/multiverse/suite.rb +5 -1
  79. data/test/multiverse/suites/active_record/active_record_test.rb +8 -8
  80. data/test/multiverse/suites/agent_only/agent_attributes_test.rb +145 -0
  81. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +8 -0
  82. data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +5 -1
  83. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +6 -6
  84. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  85. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +2 -3
  86. data/test/multiverse/suites/agent_only/synthetics_test.rb +3 -3
  87. data/test/multiverse/suites/agent_only/testing_app.rb +4 -0
  88. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -1
  89. data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +9 -7
  90. data/test/multiverse/suites/curb/Envfile +5 -6
  91. data/test/multiverse/suites/curb/curb_test.rb +4 -5
  92. data/test/multiverse/suites/datamapper/datamapper_test.rb +2 -2
  93. data/test/multiverse/suites/excon/Envfile +11 -4
  94. data/test/multiverse/suites/excon/excon_test.rb +5 -5
  95. data/test/multiverse/suites/grape/config/newrelic.yml +1 -0
  96. data/test/multiverse/suites/grape/grape_test.rb +76 -12
  97. data/test/multiverse/suites/grape/grape_test_api.rb +16 -0
  98. data/test/multiverse/suites/high_security/config/newrelic.yml +43 -3
  99. data/test/multiverse/suites/high_security/high_security_test.rb +165 -9
  100. data/test/multiverse/suites/httpclient/Envfile +5 -1
  101. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  102. data/test/multiverse/suites/memcached/Envfile +1 -1
  103. data/test/multiverse/suites/mongo/Envfile +8 -1
  104. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +29 -29
  105. data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +43 -8
  106. data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +13 -3
  107. data/test/multiverse/suites/rails/Envfile +3 -3
  108. data/test/multiverse/suites/rails/error_tracing_test.rb +52 -31
  109. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +1 -1
  110. data/test/multiverse/suites/rails/ignore_test.rb +1 -1
  111. data/test/multiverse/suites/rails/parameter_capture_test.rb +108 -40
  112. data/test/multiverse/suites/rails/request_statistics_test.rb +10 -4
  113. data/test/multiverse/suites/rails/view_instrumentation_test.rb +24 -24
  114. data/test/multiverse/suites/resque/instrumentation_test.rb +46 -12
  115. data/test/multiverse/suites/sequel/sequel_extension_test.rb +8 -8
  116. data/test/multiverse/suites/sequel/sequel_helpers.rb +11 -11
  117. data/test/multiverse/suites/sequel/sequel_plugin_test.rb +11 -11
  118. data/test/multiverse/suites/sidekiq/Envfile +1 -4
  119. data/test/multiverse/suites/sidekiq/after_suite.rb +9 -0
  120. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +49 -16
  121. data/test/multiverse/suites/sidekiq/test_worker.rb +1 -2
  122. data/test/multiverse/suites/sinatra/Envfile +1 -1
  123. data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
  124. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -4
  125. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -4
  126. data/test/multiverse/suites/sinatra/sinatra_parameter_capture_test.rb +65 -0
  127. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -11
  128. data/test/multiverse/suites/typhoeus/Envfile +8 -2
  129. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +4 -4
  130. data/test/new_relic/agent/agent/connect_test.rb +13 -9
  131. data/test/new_relic/agent/agent_test.rb +34 -24
  132. data/test/new_relic/agent/attribute_filter_test.rb +218 -0
  133. data/test/new_relic/agent/attribute_processing_test.rb +160 -0
  134. data/test/new_relic/agent/configuration/default_source_test.rb +88 -0
  135. data/test/new_relic/agent/configuration/manager_test.rb +3 -4
  136. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +3 -1
  137. data/test/new_relic/agent/configuration/server_source_test.rb +39 -0
  138. data/test/new_relic/agent/cross_app_monitor_test.rb +6 -30
  139. data/test/new_relic/agent/cross_app_tracing_test.rb +12 -12
  140. data/test/new_relic/agent/database/sql_obfuscation_test.rb +39 -65
  141. data/test/new_relic/agent/datastores/metric_helper_test.rb +36 -0
  142. data/test/new_relic/agent/encoding_normalizer_test.rb +66 -0
  143. data/test/new_relic/agent/error_collector_test.rb +181 -34
  144. data/test/new_relic/agent/hash_extensions_test.rb +34 -0
  145. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +20 -23
  146. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +12 -12
  147. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +5 -5
  148. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +4 -4
  149. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +21 -11
  150. data/test/new_relic/agent/javascript_instrumentor_test.rb +69 -45
  151. data/test/new_relic/agent/pipe_service_test.rb +2 -2
  152. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
  153. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +8 -7
  154. data/test/new_relic/agent/stats_engine/stats_hash_test.rb +2 -2
  155. data/test/new_relic/agent/threading/backtrace_node_test.rb +2 -2
  156. data/test/new_relic/agent/transaction/attributes_test.rb +276 -0
  157. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +10 -10
  158. data/test/new_relic/agent/transaction/trace_node_test.rb +361 -0
  159. data/test/new_relic/agent/transaction/trace_test.rb +394 -0
  160. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
  161. data/test/new_relic/agent/transaction_event_aggregator_test.rb +127 -57
  162. data/test/new_relic/agent/transaction_sample_builder_test.rb +70 -78
  163. data/test/new_relic/agent/transaction_sampler_test.rb +76 -185
  164. data/test/new_relic/agent/transaction_test.rb +283 -135
  165. data/test/new_relic/agent_test.rb +27 -12
  166. data/test/new_relic/cli/commands/install_test.rb +27 -0
  167. data/test/new_relic/coerce_test.rb +0 -59
  168. data/test/new_relic/data_container_tests.rb +5 -5
  169. data/test/new_relic/fake_collector.rb +27 -9
  170. data/test/new_relic/filtering_test_app.rb +2 -1
  171. data/test/new_relic/http_client_test_cases.rb +16 -16
  172. data/test/new_relic/json_wrapper_test.rb +0 -54
  173. data/test/new_relic/marshalling_test_cases.rb +1 -0
  174. data/test/new_relic/multiverse_helpers.rb +144 -0
  175. data/test/new_relic/noticed_error_test.rb +112 -9
  176. data/test/new_relic/rack/browser_monitoring_test.rb +12 -7
  177. data/test/new_relic/{transaction_analysis → rack/developer_mode}/segment_summary_test.rb +5 -4
  178. data/test/new_relic/rack/developer_mode_test.rb +17 -3
  179. data/test/new_relic/rack/error_collector_test.rb +1 -1
  180. data/test/performance/lib/performance/instrumentation/stackprof.rb +1 -1
  181. data/test/performance/script/runner +2 -2
  182. data/test/performance/suites/active_record.rb +3 -3
  183. data/test/performance/suites/agent_attributes.rb +62 -0
  184. data/test/performance/suites/rack_middleware.rb +78 -28
  185. data/test/performance/suites/transaction_tracing.rb +35 -0
  186. data/test/test_helper.rb +9 -1
  187. data/ui/helpers/developer_mode_helper.rb +16 -23
  188. data/ui/views/newrelic/_sample.rhtml +3 -3
  189. data/ui/views/newrelic/_segment.rhtml +1 -1
  190. data/ui/views/newrelic/_show_sample_summary.rhtml +1 -1
  191. data/ui/views/newrelic/show_sample.rhtml +5 -4
  192. metadata +23 -80
  193. data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +0 -25
  194. data/lib/new_relic/transaction_analysis.rb +0 -80
  195. data/lib/new_relic/transaction_analysis/segment_summary.rb +0 -53
  196. data/lib/new_relic/transaction_sample.rb +0 -207
  197. data/lib/new_relic/transaction_sample/composite_segment.rb +0 -31
  198. data/lib/new_relic/transaction_sample/fake_segment.rb +0 -13
  199. data/lib/new_relic/transaction_sample/segment.rb +0 -197
  200. data/lib/new_relic/transaction_sample/summary_segment.rb +0 -25
  201. data/lib/new_relic/url_rule.rb +0 -18
  202. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.obfuscated +0 -1
  203. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.sql +0 -1
  204. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.obfuscated +0 -1
  205. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.sql +0 -1
  206. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.obfuscated +0 -1
  207. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.sql +0 -1
  208. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.obfuscated +0 -2
  209. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.sql +0 -2
  210. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.obfuscated +0 -1
  211. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.sql +0 -1
  212. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.obfuscated +0 -2
  213. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.sql +0 -2
  214. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.obfuscated +0 -1
  215. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.sql +0 -1
  216. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.obfuscated +0 -1
  217. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.sql +0 -4
  218. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_double_quoted_string.mysql.sql +0 -1
  219. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_single_quoted_string.sql +0 -1
  220. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.obfuscated +0 -1
  221. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.sql +0 -1
  222. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.obfuscated +0 -1
  223. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.sql +0 -1
  224. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.obfuscated +0 -1
  225. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.sql +0 -1
  226. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/README.md +0 -4
  227. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.obfuscated +0 -1
  228. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/end_of_line_comments_with_quotes.sql +0 -2
  229. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.obfuscated +0 -1
  230. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_comments_and_quotes.sql +0 -2
  231. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.obfuscated +0 -1
  232. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_comments_and_newlines.sql +0 -4
  233. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.obfuscated +0 -1
  234. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/mixed_quotes_end_of_line_comments.sql +0 -3
  235. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.obfuscated +0 -1
  236. data/test/fixtures/cross_agent_tests/sql_obfuscation/pathological/quote_delimiters_in_comments.sql +0 -1
  237. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.obfuscated +0 -1
  238. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.sql +0 -1
  239. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.obfuscated +0 -1
  240. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.sql +0 -1
  241. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.obfuscated +0 -1
  242. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.sql +0 -4
  243. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.obfuscated +0 -1
  244. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.sql +0 -1
  245. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.obfuscated +0 -1
  246. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.sql +0 -2
  247. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.obfuscated +0 -1
  248. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.sql +0 -1
  249. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.obfuscated +0 -1
  250. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.sql +0 -1
  251. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.obfuscated +0 -1
  252. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.sql +0 -4
  253. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.obfuscated +0 -1
  254. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.sql +0 -1
  255. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.obfuscated +0 -1
  256. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.sql +0 -1
  257. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.obfuscated +0 -1
  258. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.sql +0 -1
  259. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.obfuscated +0 -1
  260. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.sql +0 -1
  261. data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -261
  262. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +0 -52
  263. data/test/new_relic/transaction_analysis_test.rb +0 -125
  264. data/test/new_relic/transaction_sample/composite_segment_test.rb +0 -38
  265. data/test/new_relic/transaction_sample/fake_segment_test.rb +0 -18
  266. data/test/new_relic/transaction_sample/segment_test.rb +0 -361
  267. data/test/new_relic/transaction_sample/summary_segment_test.rb +0 -34
  268. data/test/new_relic/transaction_sample_subtest_test.rb +0 -41
  269. data/test/new_relic/transaction_sample_test.rb +0 -361
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
-
7
- class NewRelic::Agent::Transaction
8
- class ForcePersistSampleBufferTest < Minitest::Test
9
- def setup
10
- @buffer = ForcePersistSampleBuffer.new
11
- end
12
-
13
- def test_stores_forced_sample
14
- sample = stub(:force_persist => true)
15
- @buffer.store(sample)
16
-
17
- assert_equal([sample], @buffer.samples)
18
- end
19
-
20
- def test_does_not_store_forced_sample
21
- sample = stub(:force_persist => false)
22
- @buffer.store(sample)
23
-
24
- assert(@buffer.samples.empty?)
25
- end
26
-
27
- def test_harvest_samples
28
- sample = stub(:force_persist => true)
29
- @buffer.store(sample)
30
-
31
- result = @buffer.harvest_samples
32
-
33
- assert_equal([sample], result)
34
- end
35
-
36
- def test_harvest_samples_resets
37
- sample = stub(:force_persist => true)
38
- @buffer.store(sample)
39
-
40
- @buffer.harvest_samples
41
-
42
- assert(@buffer.samples.empty?)
43
- end
44
-
45
- def test_intermediate_storage_keeps_N_longest_samples
46
- samples = (1..100).map { |i| stub(i.to_s, :force_persist => true, :duration => i) }
47
- samples.each {|s| @buffer.store(s)}
48
-
49
- assert_equal(samples.last(@buffer.capacity), @buffer.samples)
50
- end
51
- end
52
- end
@@ -1,125 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
6
- require 'new_relic/transaction_analysis'
7
- class NewRelic::TransactionAnalysisTest < Minitest::Test
8
- include NewRelic::TransactionAnalysis
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_database_time
14
- self.expects(:time_percentage).with(/^Database\/.*/)
15
- database_time
16
- end
17
-
18
- def test_render_time
19
- self.expects(:time_percentage).with(/^View\/.*/)
20
- render_time
21
- end
22
-
23
- def test_breakdown_data_default
24
- root_segment = mock('root_segment')
25
- # this is for 1.9 compatibility - calling each on something calls
26
- # #to_a on it - which is fun and exciting
27
- root_segment.stubs(:to_a).returns([root_segment])
28
- other_segment = mock('other_segment')
29
- # this is for 1.9 compatibility - calling each on something calls
30
- # #to_a on it - which is fun and exciting
31
- other_segment.stubs(:to_a).returns([other_segment])
32
- other_segment.expects(:metric_name).twice.returns('Controller/foo')
33
- other_segment.expects(:duration).returns(0.1)
34
- other_segment.expects(:exclusive_duration).returns(0.1)
35
- self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
36
- self.expects(:root_segment).twice.returns(root_segment)
37
- self.expects(:duration).returns(0.1)
38
- data = breakdown_data
39
- assert_equal 'Controller/foo', data[0].metric_name
40
- end
41
-
42
- # kind of a hairy test, we're making sure that the data is truncated
43
- # to one element by the limit
44
- def test_breakdown_data_limit_one
45
- root_segment = mock('root_segment')
46
- # this is for 1.9 compatibility - calling each on something calls
47
- # #to_a on it - which is fun and exciting
48
- root_segment.stubs(:to_a).returns([root_segment])
49
- other_segment = mock('other_segment')
50
- # this is for 1.9 compatibility - calling each on something calls
51
- # #to_a on it - which is fun and exciting
52
- other_segment.stubs(:to_a).returns([other_segment])
53
- other_segment.expects(:metric_name).twice.returns('Controller/foo')
54
- other_segment.expects(:duration).returns(0.1)
55
- other_segment.expects(:exclusive_duration).returns(0.1)
56
- yet_another = mock('another segment')
57
- # this is for 1.9 compatibility - calling each on something calls
58
- # #to_a on it - which is fun and exciting
59
- yet_another.stubs(:to_a).returns([yet_another])
60
- yet_another.expects(:metric_name).twice.returns('Controller/bar')
61
- yet_another.expects(:duration).returns(0.2)
62
- yet_another.expects(:exclusive_duration).returns(0.2)
63
- self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment, yet_another)
64
- self.expects(:root_segment).times(3).returns(root_segment)
65
- self.expects(:duration).returns(0.1)
66
- data = breakdown_data(1)
67
- assert_equal 1, data.size
68
- assert_equal 'Controller/bar', data[0].metric_name
69
- end
70
-
71
- def test_breakdown_data_remainder
72
- root_segment = mock('root_segment')
73
- # this is for 1.9 compatibility - calling each on something calls
74
- # #to_a on it - which is fun and exciting
75
- root_segment.stubs(:to_a).returns([root_segment])
76
- other_segment = mock('other_segment')
77
- # this is for 1.9 compatibility - calling each on something calls
78
- # #to_a on it - which is fun and exciting
79
- other_segment.stubs(:to_a).returns([other_segment])
80
- other_segment.expects(:metric_name).twice.returns('Controller/foo')
81
- other_segment.expects(:duration).returns(0.1)
82
- other_segment.expects(:exclusive_duration).returns(0.1)
83
- self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
84
- self.expects(:root_segment).twice.returns(root_segment)
85
- self.expects(:duration).returns(0.2)
86
- data = breakdown_data
87
- assert_equal 2, data.size
88
- assert_equal 'Controller/foo', data[0].metric_name
89
- assert_equal 'Remainder', data[1].metric_name
90
- end
91
-
92
- def test_sql_segments_default
93
- root_segment = mock('root_segment') # a segment with no data
94
- root_segment.expects(:[]).with(:sql).returns(false)
95
- root_segment.expects(:[]).with(:sql_obfuscated).returns(false)
96
- root_segment.expects(:[]).with(:key).returns(nil)
97
- # this is for 1.9 compatibility - calling each on something calls
98
- # #to_a on it - which is fun and exciting
99
- root_segment.stubs(:to_a).returns([root_segment])
100
- other_segment = mock('other_segment') # a sql segment
101
- other_segment.expects(:[]).with(:sql).returns(true)
102
- # this is for 1.9 compatibility - calling each on something calls
103
- # #to_a on it - which is fun and exciting
104
- other_segment.stubs(:to_a).returns([other_segment])
105
- self.expects(:each_segment).multiple_yields(root_segment, other_segment)
106
- assert_equal [other_segment], sql_segments
107
- end
108
-
109
- def test_time_percentage_default
110
- root_segment = mock('root_segment')
111
- root_segment.expects(:metric_name).returns('ROOT')
112
- # this is for 1.9 compatibility - calling each on something calls
113
- # #to_a on it - which is fun and exciting
114
- root_segment.stubs(:to_a).returns([root_segment])
115
- other_segment = mock('other_segment')
116
- other_segment.expects(:metric_name).returns('Controller/foo')
117
- other_segment.expects(:duration).returns(0.1)
118
- # this is for 1.9 compatibility - calling each on something calls
119
- # #to_a on it - which is fun and exciting
120
- other_segment.stubs(:to_a).returns([other_segment])
121
- self.expects(:duration).returns(0.2)
122
- self.expects(:each_segment).multiple_yields(root_segment, other_segment)
123
- assert_equal 50.0, time_percentage(/Controller\/.*/)
124
- end
125
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
- require 'new_relic/transaction_sample/composite_segment'
7
- class NewRelic::TransactionSample::CompositeSegmentTest < Minitest::Test
8
- def test_composite_segment_creation
9
- fake_segment = mock_segment
10
- NewRelic::TransactionSample::CompositeSegment.new([fake_segment])
11
- end
12
-
13
- def test_detail_segments_equals
14
- fake_segment = mock_segment
15
- cs = NewRelic::TransactionSample::CompositeSegment.new([fake_segment])
16
-
17
- # note that this is a bare mock
18
- # nothing should be called on it, for now
19
- other_fake_segment = mock('other segment')
20
- cs.detail_segments = [other_fake_segment]
21
-
22
- assert_equal cs.detail_segments, [other_fake_segment]
23
- end
24
-
25
- private
26
-
27
- @@seg_count = 0
28
- def mock_segment
29
- @@seg_count += 1
30
- segment = mock('segment ' + @@seg_count.to_s)
31
- segment.expects(:entry_timestamp).returns(Time.now)
32
- # note the following 'twice' - different than SummarySegment
33
- segment.expects(:exit_timestamp).returns(Time.now).twice
34
- segment.expects(:metric_name).returns('Custom/test/metric')
35
- segment.expects(:called_segments).returns([])
36
- segment
37
- end
38
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
- require 'new_relic/transaction_sample/fake_segment'
7
- class NewRelic::TransactionSample::FakeSegmentTest < Minitest::Test
8
- def test_fake_segment_creation
9
- NewRelic::TransactionSample::FakeSegment.new(0.1, 'Custom/test/metric')
10
- end
11
-
12
- def test_parent_segment
13
- # should be public in this class, but not in the parent class
14
- s = NewRelic::TransactionSample::FakeSegment.new(0.1, 'Custom/test/metric')
15
- s.parent_segment = 'foo'
16
- assert_equal('foo', s.instance_eval { @parent_segment } )
17
- end
18
- end
@@ -1,361 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
- require 'new_relic/transaction_sample/segment'
7
- class NewRelic::TransactionSample::SegmentTest < Minitest::Test
8
- def test_segment_creation
9
- # basic smoke test
10
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
11
- assert_equal NewRelic::TransactionSample::Segment, s.class
12
- end
13
-
14
- def test_readers
15
- t = Time.now
16
- s = NewRelic::TransactionSample::Segment.new(t, 'Custom/test/metric')
17
- assert_equal(t, s.entry_timestamp)
18
- assert_equal(nil, s.exit_timestamp)
19
- assert_equal(nil, s.parent_segment)
20
- assert_equal('Custom/test/metric', s.metric_name)
21
- assert_equal(s.object_id, s.segment_id)
22
- end
23
-
24
- def test_end_trace
25
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
26
- t = Time.now
27
- s.end_trace(t)
28
- assert_equal(t, s.exit_timestamp)
29
- end
30
-
31
- def test_add_called_segment
32
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
33
- assert_equal [], s.called_segments
34
- fake_segment = mock('segment')
35
- fake_segment.expects(:parent_segment=).with(s)
36
- s.add_called_segment(fake_segment)
37
- assert_equal([fake_segment], s.called_segments)
38
- end
39
-
40
- def test_to_s
41
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
42
- s.expects(:to_debug_str).with(0)
43
- s.to_s
44
- end
45
-
46
- def test_to_array
47
- parent = NewRelic::TransactionSample::Segment.new(1, 'Custom/test/parent')
48
- parent.params[:test] = 'value'
49
- child = NewRelic::TransactionSample::Segment.new(2, 'Custom/test/child')
50
- child.end_trace(3)
51
- parent.add_called_segment(child)
52
- parent.end_trace(4)
53
- expected_array = [1000, 4000, 'Custom/test/parent', {:test => 'value'},
54
- [[2000, 3000, 'Custom/test/child', {}, []]]]
55
- assert_equal(expected_array, parent.to_array)
56
- end
57
-
58
- def test_to_array_with_bad_values
59
- segment = NewRelic::TransactionSample::Segment.new(nil, nil)
60
- segment.end_trace(Rational(10, 1))
61
- expected = [0, 10_000.0, "<unknown>", {}, []]
62
- assert_equal(expected, segment.to_array)
63
- end
64
-
65
- def test_path_string
66
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
67
- assert_equal("Custom/test/metric[]", s.path_string)
68
-
69
- fake_segment = mock('segment')
70
- fake_segment.expects(:parent_segment=).with(s)
71
- fake_segment.expects(:path_string).returns('Custom/other/metric[]')
72
-
73
-
74
- s.add_called_segment(fake_segment)
75
- assert_equal("Custom/test/metric[Custom/other/metric[]]", s.path_string)
76
- end
77
-
78
- def test_to_s_compact
79
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
80
- assert_equal("Custom/test/metric", s.to_s_compact)
81
-
82
- fake_segment = mock('segment')
83
- fake_segment.expects(:parent_segment=).with(s)
84
- fake_segment.expects(:to_s_compact).returns('Custom/other/metric')
85
- s.add_called_segment(fake_segment)
86
-
87
- assert_equal("Custom/test/metric{Custom/other/metric}", s.to_s_compact)
88
- end
89
-
90
- def test_to_debug_str_basic
91
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
92
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n<< n/a Custom/test/metric\n", s.to_debug_str(0))
93
- end
94
-
95
- def test_to_debug_str_with_params
96
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
97
- s.params = {:whee => 'a param'}
98
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n -whee : a param\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
99
- end
100
-
101
- def test_to_debug_str_closed
102
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
103
- s.end_trace(0.1)
104
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n<< 100 ms Custom/test/metric\n", s.to_debug_str(0))
105
- end
106
-
107
- def test_to_debug_str_closed_with_nonnumeric
108
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
109
- s.end_trace("0.1")
110
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n<< 0.1 Custom/test/metric\n", s.to_debug_str(0))
111
- end
112
-
113
- def test_to_debug_str_one_child
114
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
115
- s.add_called_segment(NewRelic::TransactionSample::Segment.new(0.1, 'Custom/test/other'))
116
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/other \n << n/a Custom/test/other\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
117
- # try closing it
118
- s.called_segments.first.end_trace(0.15)
119
- s.end_trace(0.2)
120
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/other \n << 150 ms Custom/test/other\n<< 200 ms Custom/test/metric\n", s.to_debug_str(0))
121
- end
122
-
123
- def test_to_debug_str_multichild
124
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
125
- s.add_called_segment(NewRelic::TransactionSample::Segment.new(0.1, 'Custom/test/other'))
126
- s.add_called_segment(NewRelic::TransactionSample::Segment.new(0.11, 'Custom/test/extra'))
127
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/other \n << n/a Custom/test/other\n >> 110 ms [Segment] Custom/test/extra \n << n/a Custom/test/extra\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
128
- ending = 0.12
129
- s.called_segments.each { |x| x.end_trace(ending += 0.01) }
130
- s.end_trace(0.2)
131
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/other \n << 130 ms Custom/test/other\n >> 110 ms [Segment] Custom/test/extra \n << 140 ms Custom/test/extra\n<< 200 ms Custom/test/metric\n", s.to_debug_str(0))
132
- end
133
-
134
- def test_to_debug_str_nested
135
- inner = NewRelic::TransactionSample::Segment.new(0.2, 'Custom/test/inner')
136
- middle = NewRelic::TransactionSample::Segment.new(0.1, 'Custom/test/middle')
137
- s = NewRelic::TransactionSample::Segment.new(0.0, 'Custom/test/metric')
138
- middle.add_called_segment(inner)
139
- s.add_called_segment(middle)
140
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/middle \n >> 200 ms [Segment] Custom/test/inner \n << n/a Custom/test/inner\n << n/a Custom/test/middle\n<< n/a Custom/test/metric\n", s.to_debug_str(0))
141
-
142
- # close them
143
- inner.end_trace(0.21)
144
- middle.end_trace(0.22)
145
- s.end_trace(0.23)
146
- assert_equal(">> 0 ms [Segment] Custom/test/metric \n >> 100 ms [Segment] Custom/test/middle \n >> 200 ms [Segment] Custom/test/inner \n << 210 ms Custom/test/inner\n << 220 ms Custom/test/middle\n<< 230 ms Custom/test/metric\n", s.to_debug_str(0))
147
- end
148
-
149
- def test_called_segments_default
150
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
151
- assert_equal([], s.called_segments)
152
- end
153
-
154
- def test_called_segments_with_segments
155
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
156
- fake_segment = mock('segment')
157
- fake_segment.expects(:parent_segment=).with(s)
158
- s.add_called_segment(fake_segment)
159
-
160
- assert_equal([fake_segment], s.called_segments)
161
- end
162
-
163
- def test_duration
164
- fake_entry_timestamp = mock('entry timestamp')
165
- fake_exit_timestamp = mock('exit timestamp')
166
- fake_result = mock('numeric')
167
- fake_exit_timestamp.expects(:-).with(fake_entry_timestamp).returns(fake_result)
168
- fake_result.expects(:to_f).returns(0.5)
169
-
170
- s = NewRelic::TransactionSample::Segment.new(fake_entry_timestamp, 'Custom/test/metric')
171
- s.end_trace(fake_exit_timestamp)
172
- assert_equal(0.5, s.duration)
173
- end
174
-
175
- def test_exclusive_duration_no_children
176
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
177
- s.expects(:duration).returns(0.5)
178
- assert_equal(0.5, s.exclusive_duration)
179
- end
180
-
181
- def test_exclusive_duration_with_children
182
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
183
-
184
- s.expects(:duration).returns(0.5)
185
-
186
- fake_segment = mock('segment')
187
- fake_segment.expects(:parent_segment=).with(s)
188
- fake_segment.expects(:duration).returns(0.1)
189
-
190
- s.add_called_segment(fake_segment)
191
-
192
- assert_equal(0.4, s.exclusive_duration)
193
- end
194
-
195
- def test_count_segments_default
196
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
197
- assert_equal(1, s.count_segments)
198
- end
199
-
200
- def test_count_segments_with_children
201
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
202
-
203
- fake_segment = mock('segment')
204
- fake_segment.expects(:parent_segment=).with(s)
205
- fake_segment.expects(:count_segments).returns(1)
206
-
207
- s.add_called_segment(fake_segment)
208
-
209
- assert_equal(2, s.count_segments)
210
- end
211
-
212
- def test_key_equals
213
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
214
- # doing this to hold the reference to the hash
215
- params = {}
216
- s.params = params
217
- assert_equal(params, s.params)
218
-
219
- # should delegate to the same hash we have above
220
- s[:foo] = 'correct'
221
-
222
- assert_equal('correct', params[:foo])
223
- end
224
-
225
- def test_key
226
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
227
- s.params = {:foo => 'correct'}
228
- assert_equal('correct', s[:foo])
229
- end
230
-
231
- def test_params
232
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
233
-
234
- # should have a default value
235
- assert_equal(nil, s.instance_eval { @params })
236
- assert_equal({}, s.params)
237
-
238
- # should otherwise take the value from the @params var
239
- s.instance_eval { @params = {:foo => 'correct'} }
240
- assert_equal({:foo => 'correct'}, s.params)
241
- end
242
-
243
- def test_each_segment_default
244
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
245
- # in the base case it just yields the block to itself
246
- count = 0
247
- s.each_segment do |x|
248
- count += 1
249
- assert_equal(s, x)
250
- end
251
- # should only run once
252
- assert_equal(1, count)
253
- end
254
-
255
- def test_each_segment_with_children
256
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
257
-
258
- fake_segment = mock('segment')
259
- fake_segment.expects(:parent_segment=).with(s)
260
- fake_segment.expects(:each_segment).yields(fake_segment)
261
-
262
- s.add_called_segment(fake_segment)
263
-
264
- count = 0
265
- s.each_segment do |x|
266
- count += 1
267
- end
268
-
269
- assert_equal(2, count)
270
- end
271
-
272
- def test_each_segment_with_nest_tracking
273
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
274
-
275
- summary = mock('summary')
276
- summary.expects(:current_nest_count).twice.returns(0).then.returns(1)
277
- summary.expects(:current_nest_count=).twice
278
- s.each_segment_with_nest_tracking do |x|
279
- summary
280
- end
281
- end
282
-
283
- def test_find_segment_default
284
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
285
- id_to_find = s.segment_id
286
- # should return itself in the base case
287
- assert_equal(s, s.find_segment(id_to_find))
288
- end
289
-
290
- def test_find_segment_not_found
291
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
292
- assert_equal(nil, s.find_segment(-1))
293
- end
294
-
295
- def test_find_segment_with_children
296
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
297
- id_to_find = s.segment_id
298
- # should return itself in the base case
299
- assert_equal(s, s.find_segment(id_to_find))
300
- end
301
-
302
- def test_explain_sql_raising_an_error
303
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
304
- config = { :adapter => 'mysql' }
305
- statement = NewRelic::Agent::Database::Statement.new('SELECT')
306
- statement.config = config
307
- statement.explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
308
- s.params = {:sql => statement}
309
- NewRelic::Agent::Database.expects(:get_connection).with(config).raises(RuntimeError.new("whee"))
310
- s.explain_sql
311
- end
312
-
313
- def test_explain_sql_can_handle_missing_config
314
- # If TT segment came over from Resque child, might not be a Statement
315
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
316
- s.params = { :sql => "SELECT * FROM galaxy" }
317
- s.explain_sql
318
- end
319
-
320
- def test_explain_sql_can_use_already_existing_plan
321
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
322
- s.params = {
323
- :sql => "SELECT * FROM galaxy",
324
- :explain_plan => "EXPLAIN IT!"
325
- }
326
-
327
- assert_equal("EXPLAIN IT!", s.explain_sql)
328
- end
329
-
330
- def test_params_equal
331
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
332
- assert_equal(nil, s.instance_eval { @params })
333
-
334
- params = {:foo => 'correct'}
335
-
336
- s.params = params
337
- assert_equal(params, s.instance_eval { @params })
338
- end
339
-
340
- def test_obfuscated_sql
341
- sql = 'select * from table where id = 1'
342
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
343
- s[:sql] = sql
344
- assert_equal('select * from table where id = ?', s.obfuscated_sql)
345
- end
346
-
347
- def test_called_segments_equals
348
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
349
- assert_equal(nil, s.instance_eval { @called_segments })
350
- s.called_segments = [1, 2, 3]
351
- assert_equal([1, 2, 3], s.instance_eval { @called_segments })
352
- end
353
-
354
- def test_parent_segment_equals
355
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric')
356
- assert_equal(nil, s.instance_eval { @parent_segment })
357
- fake_segment = mock('segment')
358
- s.send(:parent_segment=, fake_segment)
359
- assert_equal(fake_segment, s.parent_segment)
360
- end
361
- end