wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -0
  2. data/LICENSE +64 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/method_tracer.rb +528 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +203 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +312 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,66 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
3
+
4
+ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
5
+ def setup
6
+ @log = ""
7
+ @logger = Logger.new(StringIO.new(@log))
8
+ @worker_loop = NewRelic::Agent::WorkerLoop.new
9
+ @worker_loop.stubs(:log).returns(@logger)
10
+ @test_start_time = Time.now
11
+ end
12
+
13
+ def test_add_task
14
+ @x = false
15
+ @worker_loop.run(0) do
16
+ @worker_loop.stop
17
+ @x = true
18
+ end
19
+ assert @x
20
+ end
21
+
22
+ def test_density
23
+ # This shows how the tasks stay aligned with the period and don't drift.
24
+ count = 0
25
+ start = Time.now
26
+ @worker_loop.run(0.01) do
27
+ count +=1
28
+ if count == 3
29
+ @worker_loop.stop
30
+ next
31
+ end
32
+ end
33
+ elapsed = Time.now - start
34
+ assert_in_delta 0.03, elapsed, 0.02
35
+ end
36
+ def test_task_error__standard
37
+ @logger.expects(:debug)
38
+ @logger.expects(:error)
39
+ # This loop task will run twice
40
+ done = false
41
+ @worker_loop.run(0) do
42
+ @worker_loop.stop
43
+ done = true
44
+ raise "Standard Error Test"
45
+ end
46
+ assert done
47
+ end
48
+ class BadBoy < StandardError; end
49
+
50
+ def test_task_error__exception
51
+ @logger.expects(:error).once
52
+ @logger.expects(:debug).once
53
+ @worker_loop.run(0) do
54
+ @worker_loop.stop
55
+ raise BadBoy, "oops"
56
+ end
57
+ end
58
+ def test_task_error__server
59
+ @logger.expects(:error).never
60
+ @logger.expects(:debug).once
61
+ @worker_loop.run(0) do
62
+ @worker_loop.stop
63
+ raise NewRelic::Agent::ServerError, "Runtime Error Test"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,187 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ module NewRelic
3
+ class MainAgentTest < Test::Unit::TestCase
4
+
5
+ # mostly this module just passes through to the active agent
6
+ # through the agent method or the control instance through
7
+ # NewRelic::Control.instance . But it's nice to make sure.
8
+
9
+ def teardown
10
+ super
11
+ Thread.current[:newrelic_untraced] = nil
12
+ end
13
+
14
+ def test_shutdown
15
+ mock_agent = mocked_agent
16
+ mock_agent.expects(:shutdown).with({})
17
+ NewRelic::Agent.shutdown
18
+ end
19
+
20
+ def test_after_fork
21
+ mock_agent = mocked_agent
22
+ mock_agent.expects(:after_fork).with({})
23
+ NewRelic::Agent.after_fork
24
+ end
25
+
26
+ def test_reset_stats
27
+ mock_agent = mocked_agent
28
+ mock_agent.expects(:reset_stats)
29
+ NewRelic::Agent.reset_stats
30
+ end
31
+
32
+ def test_manual_start_default
33
+ mock_control = mocked_control
34
+ mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => true})
35
+ NewRelic::Agent.manual_start
36
+ end
37
+
38
+ def test_manual_start_with_opts
39
+ mock_control = mocked_control
40
+ mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => false})
41
+ NewRelic::Agent.manual_start(:sync_startup => false)
42
+ end
43
+
44
+ def test_logger
45
+ control = mocked_control
46
+ control.expects(:log)
47
+ NewRelic::Agent.logger
48
+ end
49
+
50
+ def test_browser_timing_header
51
+ agent = mocked_agent
52
+ agent.expects(:browser_timing_header)
53
+ NewRelic::Agent.browser_timing_header
54
+ end
55
+
56
+ def test_browser_timing_footer
57
+ agent = mocked_agent
58
+ agent.expects(:browser_timing_footer)
59
+ NewRelic::Agent.browser_timing_footer
60
+ end
61
+
62
+ def test_get_stats
63
+ agent = mocked_agent
64
+ mock_stats_engine = mock('stats_engine')
65
+ agent.expects(:stats_engine).returns(mock_stats_engine)
66
+ mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
67
+ NewRelic::Agent.get_stats('Custom/test/metric')
68
+ end
69
+
70
+ # note that this is the same as get_stats above, they're just aliases
71
+ def test_get_stats_no_scope
72
+ agent = mocked_agent
73
+ mock_stats_engine = mock('stats_engine')
74
+ agent.expects(:stats_engine).returns(mock_stats_engine)
75
+ mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
76
+ NewRelic::Agent.get_stats_no_scope('Custom/test/metric')
77
+ end
78
+
79
+ def test_agent_not_started
80
+ old_agent = NewRelic::Agent.agent
81
+ NewRelic::Agent.instance_eval { @agent = nil }
82
+ assert_raise(RuntimeError) do
83
+ NewRelic::Agent.agent
84
+ end
85
+ NewRelic::Agent.instance_eval { @agent = old_agent }
86
+ end
87
+
88
+ def test_agent_when_started
89
+ old_agent = NewRelic::Agent.agent
90
+ NewRelic::Agent.instance_eval { @agent = 'not nil' }
91
+ assert_equal('not nil', NewRelic::Agent.agent, "should return the value from @agent")
92
+ NewRelic::Agent.instance_eval { @agent = old_agent }
93
+ end
94
+
95
+ def test_abort_transaction_bang
96
+ NewRelic::Agent::Instrumentation::MetricFrame.expects(:abort_transaction!)
97
+ NewRelic::Agent.abort_transaction!
98
+ end
99
+
100
+ def test_is_transaction_traced_true
101
+ Thread.current[:record_tt] = true
102
+ assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is set')
103
+ end
104
+
105
+ def test_is_transaction_traced_blank
106
+ Thread.current[:record_tt] = nil
107
+ assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is not set')
108
+ end
109
+
110
+ def test_is_transaction_traced_false
111
+ Thread.current[:record_tt] = false
112
+ assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
113
+ end
114
+
115
+ def test_is_sql_recorded_true
116
+ Thread.current[:record_sql] = true
117
+ assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
118
+ end
119
+
120
+ def test_is_sql_recorded_blank
121
+ Thread.current[:record_sql] = nil
122
+ assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is not set')
123
+ end
124
+
125
+ def test_is_sql_recorded_false
126
+ Thread.current[:record_sql] = false
127
+ assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
128
+ end
129
+
130
+ def test_is_execution_traced_true
131
+ Thread.current[:newrelic_untraced] = [true, true]
132
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
133
+ end
134
+
135
+ def test_is_execution_traced_blank
136
+ Thread.current[:newrelic_untraced] = nil
137
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is not set')
138
+ end
139
+
140
+ def test_is_execution_traced_empty
141
+ Thread.current[:newrelic_untraced] = []
142
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is an empty array')
143
+ end
144
+
145
+ def test_is_execution_traced_false
146
+ Thread.current[:newrelic_untraced] = [true, false]
147
+ assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
148
+ end
149
+
150
+ def test_instance
151
+ assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
152
+ end
153
+
154
+ def test_load_data_should_disable_serialization_if_an_error_is_encountered
155
+ NewRelic::Control.instance['disable_serialization'] = false
156
+ NewRelic::DataSerialization.stubs(:should_send_data?).returns(false)
157
+ NewRelic::Agent.stubs(:save_data).raises(Errno::EACCES)
158
+ begin
159
+ NewRelic::Agent.instance.send(:save_or_transmit_data)
160
+ rescue Errno::EACCES; end
161
+ # should be true
162
+ assert(NewRelic::Control.instance['disable_serialization'])
163
+ NewRelic::Control.instance['disable_serialization'] = false
164
+ end
165
+
166
+ def test_load_data_should_not_write_files_when_serialization_disabled
167
+ NewRelic::Control.instance['disable_serialization'] = true
168
+ NewRelic::DataSerialization.expects(:read_and_write_to_file).never
169
+ NewRelic::Agent.load_data
170
+ NewRelic::Control.instance['disable_serialization'] = false
171
+ end
172
+
173
+ private
174
+
175
+ def mocked_agent
176
+ agent = mock('agent')
177
+ NewRelic::Agent.stubs(:agent).returns(agent)
178
+ agent
179
+ end
180
+
181
+ def mocked_control
182
+ control = mock('control')
183
+ NewRelic::Control.stubs(:instance).returns(control)
184
+ control
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,149 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'ostruct'
3
+ require 'active_record_fixtures' if defined?(::ActiveRecord)
4
+
5
+ require 'new_relic/collection_helper'
6
+ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ NewRelic::Agent.manual_start
10
+ super
11
+ end
12
+ def teardown
13
+ super
14
+ end
15
+
16
+ include NewRelic::CollectionHelper
17
+ def test_string
18
+ val = (('A'..'Z').to_a.join * 1024).to_s
19
+ assert_equal val[0...16384] + "...", normalize_params(val)
20
+ end
21
+ def test_array
22
+ new_array = normalize_params [ 1000 ] * 2000
23
+ assert_equal 128, new_array.size
24
+ assert_equal '1000', new_array[0]
25
+ end
26
+ def test_boolean
27
+ np = normalize_params(NewRelic::Control.instance.settings)
28
+ assert_equal false, np['monitor_mode']
29
+ end
30
+ def test_string__singleton
31
+ val = "This String"
32
+ def val.hello; end
33
+ assert_equal "This String", normalize_params(val)
34
+ assert val.respond_to?(:hello)
35
+ assert !normalize_params(val).respond_to?(:hello)
36
+ end
37
+ class MyString < String; end
38
+ def test_kind_of_string
39
+ s = MyString.new "This is a string"
40
+ assert_equal "This is a string", s.to_s
41
+ assert_equal MyString, s.class
42
+ assert_equal String, s.to_s.class
43
+ params = normalize_params(:val => [s])
44
+ assert_equal String, params[:val][0].class
45
+ assert_equal String, flatten(s).class
46
+ assert_equal String, truncate(s, 2).class
47
+ end
48
+ def test_number
49
+ np = normalize_params({ 'one' => 1.0, 'two' => '2'})
50
+ end
51
+ def test_nil
52
+ np = normalize_params({ nil => 1.0, 'two' => nil})
53
+ assert_equal "1.0", np['']
54
+ assert_equal nil, np['two']
55
+ end
56
+ def test_hash
57
+ val = ('A'..'Z').to_a.join * 100
58
+ assert_equal Hash[(val[0..63] + "...") => (("0"*16384) + "...")], normalize_params({ val => '0' * (16384*2) })
59
+ end
60
+ class MyHash < Hash
61
+
62
+ end
63
+ # Test to ensure that hash subclasses are properly converted
64
+ def test_hash_subclass
65
+ h = MyHash.new
66
+ h[:mine] = 'mine'
67
+ custom_params = { :one => {:hash => { :a => :b}, :myhash => h }}
68
+ nh = normalize_params(custom_params)
69
+ myhash = custom_params[:one][:myhash]
70
+ assert_equal MyHash, myhash.class
71
+ myhash = nh[:one][:myhash]
72
+ assert_equal Hash, myhash.class
73
+ end
74
+
75
+
76
+
77
+ def test_enumerable
78
+ e = MyEnumerable.new
79
+ custom_params = { :one => {:hash => { :a => :b}, :myenum => e }}
80
+ nh = normalize_params(custom_params)
81
+ myenum = nh[:one][:myenum]
82
+ assert_match /MyEnumerable/, myenum
83
+ end
84
+
85
+ def test_stringio
86
+ # Verify StringIO works like this normally:
87
+ s = StringIO.new "start" + ("foo bar bat " * 1000)
88
+ val = nil
89
+ s.each { | entry | val = entry; break }
90
+ assert_match /^startfoo bar/, val
91
+
92
+ # make sure stringios aren't affected by calling normalize_params:
93
+ s = StringIO.new "start" + ("foo bar bat " * 1000)
94
+ v = normalize_params({ :foo => s.string })
95
+ s.each { | entry | val = entry; break }
96
+ assert_match /^startfoo bar/, val
97
+ end
98
+ class MyEnumerable
99
+ include Enumerable
100
+
101
+ def each
102
+ yield "1"
103
+ end
104
+ end
105
+
106
+ def test_object
107
+ assert_equal ["foo", '#<OpenStruct>'], normalize_params(['foo', OpenStruct.new('z'=>'q')])
108
+ end
109
+
110
+ def test_strip_backtrace
111
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
112
+ assert_equal(0, clean_trace.grep(/newrelic_rpm/).size,
113
+ "should remove all instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
114
+ assert_equal(0, clean_trace.grep(/trace/).size,
115
+ "should remove trace method tags from method names but got: #{clean_trace.join("\n")}")
116
+ assert((clean_trace.grep(/find/).size >= 3),
117
+ "should see at least three frames with 'find' in them: \n#{clean_trace.join("\n")}")
118
+ end
119
+
120
+ def test_disabled_strip_backtrace
121
+ NewRelic::Control.instance['disable_backtrace_cleanup'] = true
122
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
+ assert_equal(1, clean_trace.grep(/new_relic/).size,
124
+ "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
125
+ assert_equal(1, clean_trace.grep(/_trace/).size,
126
+ "should not remove trace method tags from method names but got: #{clean_trace.join("\n")}")
127
+ # assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
128
+ NewRelic::Control.instance['disable_backtrace_cleanup'] = false
129
+ end
130
+
131
+ private
132
+ def mock_backtrace
133
+ [
134
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one_without_trace'},
135
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one'},
136
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1603:in `find_from_ids'},
137
+ %q{./test/new_relic/collection_helper_test.rb:112:in `test_strip_stackdump'},
138
+ %q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `__send__'},
139
+ %q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `run'},
140
+ %q{/home/app/test/unit/testsuite.rb:34:in `run'},
141
+ %q{/home/app/test/unit/testsuite.rb:33:in `each'},
142
+ %q{/home/app/test/unit/testsuite.rb:33:in `run'},
143
+ %q{/home/app/test/unit/testsuite.rb:34:in `run'},
144
+ %q{/home/app/test/unit/testsuite.rb:33:in `each'},
145
+ %q{/home/app/test/unit/testsuite.rb:33:in `run'},
146
+ %q{/home/app/test/unit/ui/testrunnermediator.rb:46:in `run_suite'}
147
+ ]
148
+ end
149
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../test_helper'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../../lib/new_relic/command'))
3
+
4
+ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ NewRelic::Command::Deployments.class_eval do
8
+ attr_accessor :messages, :exit_status, :errors, :revision
9
+ def err(message); @errors = @errors ? @errors + message : message; end
10
+ def info(message); @messages = @messages ? @messages + message : message; end
11
+ def just_exit(status=0); @exit_status ||= status; end
12
+ end
13
+ end
14
+ def teardown
15
+ super
16
+ return unless @deployment
17
+ puts @deployment.errors
18
+ puts @deployment.messages
19
+ puts @deployment.exit_status
20
+ end
21
+ def test_help
22
+ begin
23
+ NewRelic::Command::Deployments.new "-h"
24
+ fail "should have thrown"
25
+ rescue NewRelic::Command::CommandFailure => c
26
+ assert_match /^Usage/, c.message
27
+ end
28
+ end
29
+ def test_bad_command
30
+ assert_raise NewRelic::Command::CommandFailure do
31
+ NewRelic::Command::Deployments.new ["-foo", "bar"]
32
+ end
33
+ end
34
+ def test_interactive
35
+ mock_the_connection
36
+ @deployment = NewRelic::Command::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
37
+ assert_nil @deployment.exit_status
38
+ assert_nil @deployment.errors
39
+ assert_equal '3838', @deployment.revision
40
+ @deployment.run
41
+ @deployment = nil
42
+ end
43
+
44
+ def test_command_line_run
45
+ mock_the_connection
46
+ # @mock_response.expects(:body).returns("<xml>deployment</xml>")
47
+ @deployment = NewRelic::Command::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
48
+ assert_nil @deployment.exit_status
49
+ assert_nil @deployment.errors
50
+ assert_equal '3838', @deployment.revision
51
+ @deployment.run
52
+
53
+ # This should pass because it's a bogus deployment
54
+ #assert_equal 1, @deployment.exit_status
55
+ #assert_match /Unable to upload/, @deployment.errors
56
+
57
+ @deployment = nil
58
+ end
59
+ private
60
+ def mock_the_connection
61
+ mock_connection = mock()
62
+ @mock_response = mock()
63
+ @mock_response.expects(:is_a?).with(Net::HTTPSuccess).returns(true)
64
+ mock_connection.expects(:request).returns(@mock_response)
65
+ NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
66
+ end
67
+
68
+ end