honkster-newrelic_rpm 2.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/CHANGELOG +462 -0
  2. data/LICENSE +37 -0
  3. data/README.rdoc +172 -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 +34 -0
  8. data/install.rb +9 -0
  9. data/lib/new_relic/agent.rb +382 -0
  10. data/lib/new_relic/agent/agent.rb +741 -0
  11. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  12. data/lib/new_relic/agent/chained_call.rb +13 -0
  13. data/lib/new_relic/agent/error_collector.rb +131 -0
  14. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  15. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
  16. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
  17. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +409 -0
  19. data/lib/new_relic/agent/instrumentation/data_mapper.rb +58 -0
  20. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  21. data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
  22. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  23. data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
  24. data/lib/new_relic/agent/instrumentation/metric_frame.rb +319 -0
  25. data/lib/new_relic/agent/instrumentation/net.rb +17 -0
  26. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  28. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  29. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  30. data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
  31. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
  32. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
  33. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  34. data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
  35. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
  36. data/lib/new_relic/agent/method_tracer.rb +350 -0
  37. data/lib/new_relic/agent/sampler.rb +50 -0
  38. data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
  39. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  40. data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
  41. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  42. data/lib/new_relic/agent/shim_agent.rb +25 -0
  43. data/lib/new_relic/agent/stats_engine.rb +24 -0
  44. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  45. data/lib/new_relic/agent/stats_engine/samplers.rb +83 -0
  46. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  47. data/lib/new_relic/agent/transaction_sampler.rb +330 -0
  48. data/lib/new_relic/agent/worker_loop.rb +81 -0
  49. data/lib/new_relic/collection_helper.rb +71 -0
  50. data/lib/new_relic/command.rb +85 -0
  51. data/lib/new_relic/commands/deployments.rb +105 -0
  52. data/lib/new_relic/commands/install.rb +81 -0
  53. data/lib/new_relic/control.rb +203 -0
  54. data/lib/new_relic/control/configuration.rb +149 -0
  55. data/lib/new_relic/control/frameworks/external.rb +13 -0
  56. data/lib/new_relic/control/frameworks/merb.rb +24 -0
  57. data/lib/new_relic/control/frameworks/rails.rb +126 -0
  58. data/lib/new_relic/control/frameworks/rails3.rb +60 -0
  59. data/lib/new_relic/control/frameworks/ruby.rb +36 -0
  60. data/lib/new_relic/control/frameworks/sinatra.rb +18 -0
  61. data/lib/new_relic/control/instrumentation.rb +95 -0
  62. data/lib/new_relic/control/logging_methods.rb +74 -0
  63. data/lib/new_relic/control/profiling.rb +24 -0
  64. data/lib/new_relic/control/server_methods.rb +88 -0
  65. data/lib/new_relic/delayed_job_injection.rb +27 -0
  66. data/lib/new_relic/histogram.rb +91 -0
  67. data/lib/new_relic/local_environment.rb +333 -0
  68. data/lib/new_relic/merbtasks.rb +6 -0
  69. data/lib/new_relic/metric_data.rb +42 -0
  70. data/lib/new_relic/metric_parser.rb +136 -0
  71. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  72. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  73. data/lib/new_relic/metric_parser/active_record.rb +28 -0
  74. data/lib/new_relic/metric_parser/apdex.rb +88 -0
  75. data/lib/new_relic/metric_parser/controller.rb +62 -0
  76. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  77. data/lib/new_relic/metric_parser/errors.rb +6 -0
  78. data/lib/new_relic/metric_parser/external.rb +50 -0
  79. data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
  80. data/lib/new_relic/metric_parser/other_transaction.rb +36 -0
  81. data/lib/new_relic/metric_parser/view.rb +61 -0
  82. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  83. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  84. data/lib/new_relic/metric_spec.rb +67 -0
  85. data/lib/new_relic/metrics.rb +9 -0
  86. data/lib/new_relic/noticed_error.rb +24 -0
  87. data/lib/new_relic/rack/developer_mode.rb +257 -0
  88. data/lib/new_relic/rack/metric_app.rb +64 -0
  89. data/lib/new_relic/rack/mongrel_rpm.ru +26 -0
  90. data/lib/new_relic/rack/newrelic.yml +27 -0
  91. data/lib/new_relic/rack_app.rb +6 -0
  92. data/lib/new_relic/recipes.rb +82 -0
  93. data/lib/new_relic/stats.rb +368 -0
  94. data/lib/new_relic/timer_lib.rb +27 -0
  95. data/lib/new_relic/transaction_analysis.rb +119 -0
  96. data/lib/new_relic/transaction_sample.rb +586 -0
  97. data/lib/new_relic/url_rule.rb +14 -0
  98. data/lib/new_relic/version.rb +55 -0
  99. data/lib/new_relic_api.rb +276 -0
  100. data/lib/newrelic_rpm.rb +49 -0
  101. data/lib/tasks/all.rb +4 -0
  102. data/lib/tasks/install.rake +7 -0
  103. data/lib/tasks/tests.rake +15 -0
  104. data/newrelic.yml +246 -0
  105. data/newrelic_rpm.gemspec +254 -0
  106. data/recipes/newrelic.rb +6 -0
  107. data/test/active_record_fixtures.rb +55 -0
  108. data/test/config/newrelic.yml +48 -0
  109. data/test/config/test_control.rb +36 -0
  110. data/test/new_relic/agent/active_record_instrumentation_test.rb +286 -0
  111. data/test/new_relic/agent/agent_controller_test.rb +294 -0
  112. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  113. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  114. data/test/new_relic/agent/collection_helper_test.rb +125 -0
  115. data/test/new_relic/agent/error_collector_test.rb +163 -0
  116. data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
  117. data/test/new_relic/agent/method_tracer_test.rb +340 -0
  118. data/test/new_relic/agent/metric_data_test.rb +53 -0
  119. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  120. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  121. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  122. data/test/new_relic/agent/rpm_agent_test.rb +142 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  124. data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
  125. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
  126. data/test/new_relic/agent/task_instrumentation_test.rb +188 -0
  127. data/test/new_relic/agent/testable_agent.rb +13 -0
  128. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  129. data/test/new_relic/agent/transaction_sample_test.rb +192 -0
  130. data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
  131. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  132. data/test/new_relic/control_test.rb +127 -0
  133. data/test/new_relic/deployments_api_test.rb +69 -0
  134. data/test/new_relic/environment_test.rb +75 -0
  135. data/test/new_relic/metric_parser_test.rb +226 -0
  136. data/test/new_relic/metric_spec_test.rb +177 -0
  137. data/test/new_relic/rack/episodes_test.rb +318 -0
  138. data/test/new_relic/shim_agent_test.rb +9 -0
  139. data/test/new_relic/stats_test.rb +312 -0
  140. data/test/new_relic/version_number_test.rb +89 -0
  141. data/test/test_contexts.rb +28 -0
  142. data/test/test_helper.rb +72 -0
  143. data/ui/helpers/developer_mode_helper.rb +359 -0
  144. data/ui/helpers/google_pie_chart.rb +49 -0
  145. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  146. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  147. data/ui/views/newrelic/_sample.rhtml +20 -0
  148. data/ui/views/newrelic/_segment.rhtml +29 -0
  149. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  150. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  151. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  152. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  153. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  154. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  155. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  156. data/ui/views/newrelic/_table.rhtml +12 -0
  157. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  158. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  159. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  160. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  161. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  162. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  163. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  164. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  165. data/ui/views/newrelic/file/images/textmate.png +0 -0
  166. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  167. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  168. data/ui/views/newrelic/file/stylesheets/style.css +484 -0
  169. data/ui/views/newrelic/index.rhtml +59 -0
  170. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  171. data/ui/views/newrelic/show_sample.rhtml +79 -0
  172. data/ui/views/newrelic/show_source.rhtml +3 -0
  173. data/ui/views/newrelic/threads.rhtml +52 -0
  174. metadata +307 -0
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
+ # TODO
3
+ class NewRelic::ShimAgentTest < Test::Unit::TestCase
4
+
5
+ def test_shim
6
+ end
7
+
8
+
9
+ end
@@ -0,0 +1,312 @@
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_simple
18
+ stats = NewRelic::MethodTraceStats.new
19
+ validate stats, 0, 0, 0, 0
20
+
21
+ assert_equal stats.call_count,0
22
+ stats.trace_call 10
23
+ stats.trace_call 20
24
+ stats.trace_call 30
25
+
26
+ validate stats, 3, (10+20+30), 10, 30
27
+ end
28
+
29
+ def test_to_s
30
+ s1 = NewRelic::MethodTraceStats.new
31
+ s1.trace_call 10
32
+ assert_equal("[01/01/70 12:00AM UTC, 0.000s; 1 calls 10000 ms]", s1.to_s)
33
+ end
34
+
35
+ def test_time_str
36
+ s1 = NewRelic::MethodTraceStats.new
37
+ assert_equal(s1.time_str(10), "10 ms")
38
+ assert_equal(s1.time_str(4999), "4999 ms")
39
+ assert_equal(s1.time_str(5000), "5.00 s")
40
+ assert_equal(s1.time_str(5010), "5.01 s")
41
+ assert_equal(s1.time_str(9999), "10.00 s")
42
+ assert_equal(s1.time_str(10000), "10.0 s")
43
+ assert_equal(s1.time_str(20000), "20.0 s")
44
+ end
45
+
46
+ def test_fraction_of
47
+ s1 = NewRelic::MethodTraceStats.new
48
+ s2 = NewRelic::MethodTraceStats.new
49
+ s1.trace_call 10
50
+ s2.trace_call 20
51
+ assert_equal(s1.fraction_of(s2).to_s, 'NaN')
52
+ end
53
+
54
+ def test_fraction_of2
55
+ s1 = NewRelic::MethodTraceStats.new
56
+ s1.trace_call 10
57
+ s2 = NewRelic::MethodTraceStats.new
58
+ assert_equal(s1.fraction_of(s2).to_s, 'NaN')
59
+ end
60
+
61
+ def test_multiply_by
62
+ s1 = NewRelic::MethodTraceStats.new
63
+ s1.trace_call 10
64
+ assert_equal("[01/01/70 12:00AM UTC, 0.000s; 10 calls 10000 ms]", s1.multiply_by(10).to_s)
65
+ end
66
+
67
+ def test_get_apdex
68
+ s1 = NewRelic::MethodTraceStats.new
69
+ s1.trace_call 10
70
+ assert_equal(s1.get_apdex, [1, 10, 10])
71
+ end
72
+
73
+ def test_apdex_score
74
+ s1 = NewRelic::MethodTraceStats.new
75
+ s1.trace_call 10
76
+ # FIXME make this test the real logic
77
+ # don't ask me what this means, but it's what's coming out the
78
+ # other end when I actually run it.
79
+ assert_in_delta(s1.apdex_score, 0.285714285714286, 0.0000001)
80
+ end
81
+
82
+ def test_as_percentage
83
+ s1 = NewRelic::MethodTraceStats.new
84
+ s1.trace_call 10
85
+ assert_equal(s1.as_percentage, 1000.0)
86
+ end
87
+
88
+ def test_calls_per_minute
89
+
90
+ s1 = NewRelic::TestObjectForStats.new
91
+ s1.call_count = 1
92
+ s1.begin_time = Time.at(0)
93
+ s1.end_time = Time.at(30)
94
+ assert_equal(s1.calls_per_minute, 2)
95
+ end
96
+
97
+ def test_total_call_time_per_minute
98
+ s1 = NewRelic::TestObjectForStats.new
99
+ s1.begin_time = Time.at(0)
100
+ s1.end_time = Time.at(0)
101
+ assert_equal(0, s1.total_call_time_per_minute)
102
+ s1.begin_time = Time.at(0)
103
+ s1.end_time = Time.at(30)
104
+ s1.total_call_time = 10
105
+ assert_equal(20, s1.total_call_time_per_minute)
106
+ end
107
+
108
+ def test_time_percentage
109
+ s1 = NewRelic::TestObjectForStats.new
110
+ s1.begin_time = Time.at(0)
111
+ s1.end_time = Time.at(0)
112
+ assert_equal(0, s1.time_percentage)
113
+ s1.total_call_time = 10
114
+ s1.begin_time = Time.at(0)
115
+ s1.end_time = Time.at(30)
116
+ assert_equal((1.0 / 3.0), s1.time_percentage)
117
+ s1.total_call_time = 20
118
+ assert_equal((2.0 / 3.0), s1.time_percentage)
119
+ end
120
+
121
+ def test_exclusive_time_percentage
122
+ s1 = NewRelic::TestObjectForStats.new
123
+ s1.begin_time = Time.at(0)
124
+ s1.end_time = Time.at(0)
125
+ assert_equal(0, s1.exclusive_time_percentage)
126
+ s1.total_exclusive_time = 10
127
+ s1.begin_time = Time.at(0)
128
+ s1.end_time = Time.at(30)
129
+ assert_equal((1.0 / 3.0), s1.exclusive_time_percentage)
130
+ s1.total_exclusive_time = 20
131
+ assert_equal((2.0 / 3.0), s1.exclusive_time_percentage)
132
+ end
133
+
134
+ def test_sum_merge
135
+ s1 = NewRelic::MethodTraceStats.new
136
+ s2 = NewRelic::MethodTraceStats.new
137
+ s1.trace_call 10
138
+ s2.trace_call 20
139
+ s2.freeze
140
+
141
+ validate s1, 1, 10, 10, 10
142
+ validate s2, 1, 20, 20, 20
143
+ s1.sum_merge! s2
144
+ validate s1, 1, (10+20), 10 + 20, 20 + 10
145
+ validate s2, 1, 20, 20, 20
146
+ end
147
+
148
+ def test_sum_merge_with_exclusive
149
+ s1 = NewRelic::MethodTraceStats.new
150
+ s2 = NewRelic::MethodTraceStats.new
151
+
152
+ s1.trace_call 10, 5
153
+ s2.trace_call 20, 10
154
+ s2.freeze
155
+
156
+ validate s1, 1, 10, 10, 10, 5
157
+ validate s2, 1, 20, 20, 20, 10
158
+ s1.sum_merge! s2
159
+ validate s1, 1, (10+20), 10 + 20, 20 + 10, (10+5)
160
+ end
161
+
162
+ def test_merge
163
+ s1 = NewRelic::MethodTraceStats.new
164
+ s2 = NewRelic::MethodTraceStats.new
165
+
166
+ s1.trace_call 10
167
+ s2.trace_call 20
168
+ s2.freeze
169
+
170
+ validate s2, 1, 20, 20, 20
171
+ s3 = s1.merge s2
172
+ validate s3, 2, (10+20), 10, 20
173
+ validate s1, 1, 10, 10, 10
174
+ validate s2, 1, 20, 20, 20
175
+
176
+ s1.merge! s2
177
+ validate s1, 2, (10+20), 10, 20
178
+ validate s2, 1, 20, 20, 20
179
+ end
180
+
181
+ def test_merge_with_exclusive
182
+ s1 = NewRelic::MethodTraceStats.new
183
+
184
+ s2 = NewRelic::MethodTraceStats.new
185
+
186
+ s1.trace_call 10, 5
187
+ s2.trace_call 20, 10
188
+ s2.freeze
189
+
190
+ validate s2, 1, 20, 20, 20, 10
191
+ s3 = s1.merge s2
192
+ validate s3, 2, (10+20), 10, 20, (10+5)
193
+ validate s1, 1, 10, 10, 10, 5
194
+ validate s2, 1, 20, 20, 20, 10
195
+
196
+ s1.merge! s2
197
+ validate s1, 2, (10+20), 10, 20, (5+10)
198
+ validate s2, 1, 20, 20, 20, 10
199
+ end
200
+
201
+ def test_merge_array
202
+ s1 = NewRelic::MethodTraceStats.new
203
+ merges = []
204
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
205
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
206
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
207
+
208
+ s1.merge! merges
209
+ validate s1, 3, 3, 1, 1
210
+ end
211
+ def test_round
212
+ stats = NewRelic::MethodTraceStats.new
213
+ stats.record_data_point(0.125222, 0.025)
214
+ stats.record_data_point(0.125222, 0.025)
215
+ stats.record_data_point(0.125222, 0.025)
216
+ assert_equal 0.047041647852, stats.sum_of_squares
217
+ assert_equal 0.375666, stats.total_call_time
218
+ stats.round!
219
+ assert_equal 0.376, stats.total_call_time
220
+ assert_equal 0.047, stats.sum_of_squares
221
+
222
+ end
223
+
224
+ def test_freeze
225
+ s1 = NewRelic::MethodTraceStats.new
226
+
227
+ s1.trace_call 10
228
+ s1.freeze
229
+
230
+ begin
231
+ # the following should throw an exception because s1 is frozen
232
+ s1.trace_call 20
233
+ assert false
234
+ rescue StandardError
235
+ assert s1.frozen?
236
+ validate s1, 1, 10, 10, 10
237
+ end
238
+ end
239
+
240
+ def test_std_dev
241
+ s = NewRelic::MethodTraceStats.new
242
+ s.trace_call 1
243
+ assert s.standard_deviation == 0
244
+
245
+ s = NewRelic::MethodTraceStats.new
246
+ s.trace_call 10
247
+ s.trace_call 10
248
+ s.sum_of_squares = nil
249
+ assert s.standard_deviation == 0
250
+
251
+ s = NewRelic::MethodTraceStats.new
252
+ s.trace_call 0.001
253
+ s.trace_call 0.001
254
+ assert s.standard_deviation == 0
255
+
256
+
257
+ s = NewRelic::MethodTraceStats.new
258
+ s.trace_call 10
259
+ s.trace_call 10
260
+ s.trace_call 10
261
+ s.trace_call 10
262
+ s.trace_call 10
263
+ s.trace_call 10
264
+ assert s.standard_deviation == 0
265
+
266
+ s = NewRelic::MethodTraceStats.new
267
+ s.trace_call 4
268
+ s.trace_call 7
269
+ s.trace_call 13
270
+ s.trace_call 16
271
+ s.trace_call 8
272
+ s.trace_call 4
273
+ assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
274
+
275
+ s.trace_call 9
276
+ s.trace_call 3
277
+ s.trace_call 1000
278
+ s.trace_call 4
279
+
280
+ # calculated stdev (population, not sample) from a spreadsheet.
281
+ assert_in_delta(s.standard_deviation, 297.76, 0.01)
282
+ end
283
+
284
+ def test_std_dev_merge
285
+ s1 = NewRelic::MethodTraceStats.new
286
+ s1.trace_call 4
287
+ s1.trace_call 7
288
+
289
+ s2 = NewRelic::MethodTraceStats.new
290
+ s2.trace_call 13
291
+ s2.trace_call 16
292
+
293
+ s3 = s1.merge(s2)
294
+
295
+ assert(s1.sum_of_squares, 4*4 + 7*7)
296
+ assert_in_delta(s1.standard_deviation, 1.5, 0.01)
297
+
298
+ assert_in_delta(s2.standard_deviation, 1.5, 0.01)
299
+ assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
300
+ assert_in_delta(s3.standard_deviation, 4.743, 0.01)
301
+ end
302
+
303
+ private
304
+ def validate (stats, count, total, min, max, exclusive = nil)
305
+ assert_equal stats.call_count, count
306
+ assert_equal stats.total_call_time, total
307
+ assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
308
+ assert_equal stats.min_call_time, min
309
+ assert_equal stats.max_call_time, max
310
+ assert_equal stats.total_exclusive_time, exclusive if exclusive
311
+ end
312
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+ class NewRelic::VersionNumberTest < Test::Unit::TestCase
3
+
4
+ def test_comparison__first
5
+ versions = %w[1.0.0 0.1.0 0.0.1 10.0.1 1.10.0].map {|s| NewRelic::VersionNumber.new s }
6
+ assert_equal %w[0.0.1 0.1.0 1.0.0 1.10.0 10.0.1], versions.sort.map(&:to_s)
7
+ v0 = NewRelic::VersionNumber.new '1.2.3'
8
+ v1 = NewRelic::VersionNumber.new '1.2.2'
9
+ v3 = NewRelic::VersionNumber.new '1.2.2'
10
+ assert v0 > v1
11
+ assert v1 == v1
12
+ assert v1 == v3
13
+ end
14
+ def test_comparison__second
15
+ v0 = NewRelic::VersionNumber.new '1.2.0'
16
+ v1 = NewRelic::VersionNumber.new '2.2.2'
17
+ v3 = NewRelic::VersionNumber.new '1.1.2'
18
+ assert v0 < v1
19
+ assert v1 > v3
20
+ assert v3 < v0
21
+ end
22
+ def test_bug
23
+ v0 = NewRelic::VersionNumber.new '2.8.999'
24
+ v1 = NewRelic::VersionNumber.new '2.9.10'
25
+ assert v1 > v0
26
+ assert v0 <= v1
27
+ end
28
+ def test_long_version
29
+ v0 = NewRelic::VersionNumber.new '1.2.3.4'
30
+ v1 = NewRelic::VersionNumber.new '1.2.3.3'
31
+ v3 = NewRelic::VersionNumber.new '1.3'
32
+ assert v0 > v1
33
+ assert v0 < '1.2.3.5'
34
+ assert ! (v0 < '1.2.3.4')
35
+ assert v3 > v0
36
+ end
37
+ def test_sort
38
+ values = %w[1.1.1
39
+ 1.1.99
40
+ 1.1.999
41
+ 2.0.6
42
+ 2.6.5
43
+ 2.7
44
+ 2.7.1
45
+ 2.7.2
46
+ 2.7.2.0
47
+ 3
48
+ 999]
49
+ assert_equal values, values.map{|v| NewRelic::VersionNumber.new v}.sort.map(&:to_s)
50
+ end
51
+ def test_prerelease
52
+ v0 = NewRelic::VersionNumber.new '1.2.0.beta'
53
+ assert_equal [1,2,0,'beta'], v0.parts
54
+ assert v0 > '1.1.9.0'
55
+ assert v0 > '1.1.9.alpha'
56
+ assert v0 > '1.2.0.alpha'
57
+ assert v0 == '1.2.0.beta'
58
+ assert v0 < '1.2.1'
59
+ assert v0 < '1.2.0'
60
+ assert v0 < '1.2.0.c'
61
+ assert v0 < '1.2.0.0'
62
+
63
+ end
64
+ def test_compare_string
65
+ v0 = NewRelic::VersionNumber.new '1.2.0'
66
+ v1 = NewRelic::VersionNumber.new '2.2.2'
67
+ v3 = NewRelic::VersionNumber.new '1.1.2'
68
+ assert v0 < '2.2.2'
69
+ assert v1 > '1.1.2'
70
+ assert v3 < '1.2.0'
71
+ assert v0 == '1.2.0'
72
+ end
73
+ def test_4_numbers
74
+ v0 = NewRelic::VersionNumber.new '1.2.0'
75
+ v1 = NewRelic::VersionNumber.new '1.2.0.1'
76
+ v2 = NewRelic::VersionNumber.new '1.2.1.0'
77
+ v3 = NewRelic::VersionNumber.new '1.2.1.1'
78
+ assert v0 < v1
79
+ assert v1 < v2
80
+ assert v2 < v3
81
+ assert v0 < v3
82
+ assert v0 < '1.2.0.1'
83
+ assert v0 > '1.1.0.1'
84
+ end
85
+ def test_string
86
+ assert_equal '1.2.0', NewRelic::VersionNumber.new('1.2.0').to_s
87
+ assert_equal '1.2', NewRelic::VersionNumber.new('1.2').to_s
88
+ end
89
+ end
@@ -0,0 +1,28 @@
1
+
2
+ module TestContexts
3
+ def with_running_agent
4
+
5
+ context 'with running agent' do # this is needed for the nested setups
6
+
7
+ setup do
8
+ @log_data = StringIO.new
9
+ @log = Logger.new(@log_data)
10
+ NewRelic::Agent.manual_start :log => @log
11
+ @agent = NewRelic::Agent.instance
12
+ @agent.transaction_sampler.send :clear_builder
13
+ @agent.transaction_sampler.reset!
14
+ @agent.stats_engine.clear_stats
15
+ end
16
+
17
+ yield
18
+
19
+ def teardown
20
+ NewRelic::Agent.shutdown
21
+ @log_data.reset
22
+ NewRelic::Control.instance['dispatcher']=nil
23
+ NewRelic::Control.instance['dispatcher_instance_id']=nil
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,72 @@
1
+ module NewRelic; TEST = true; end unless defined? NewRelic::TEST
2
+ ENV['RAILS_ENV'] = 'test'
3
+ NEWRELIC_PLUGIN_DIR = File.expand_path(File.join(File.dirname(__FILE__),".."))
4
+ $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"test")
5
+ $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"ui/helpers")
6
+ $LOAD_PATH.uniq!
7
+
8
+ require 'rubygems'
9
+ # We can speed things up in tests that don't need to load rails.
10
+ # You can also run the tests in a mode without rails. Many tests
11
+ # will be skipped.
12
+ if ENV['SKIP_RAILS']
13
+ dirs = File.dirname(__FILE__).split('/')
14
+ while dirs.any? && !File.directory?((dirs+%w[log]).join('/'))
15
+ dirs.pop
16
+ end
17
+ RAILS_ROOT = dirs.any? ? dirs.join("/") : "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
18
+ $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR, "lib")
19
+ require File.join(NEWRELIC_PLUGIN_DIR, "lib/newrelic_rpm")
20
+ else
21
+ begin
22
+ require File.expand_path("../../../config/environment", NEWRELIC_PLUGIN_DIR)
23
+ require 'test_help'
24
+ rescue LoadError
25
+ puts "Unable to load Rails for New Relic tests: try setting the environment variable SKIP_RAILS=false"
26
+ raise
27
+ end
28
+ end
29
+ require 'test/unit'
30
+ require 'mocha'
31
+ require 'shoulda'
32
+ require 'test_contexts'
33
+
34
+ def assert_between(floor, ceiling, value, message = nil)
35
+ assert floor <= value && value <= ceiling,
36
+ message || "expected #{floor} <= #{value} <= #{ceiling}"
37
+ end
38
+
39
+ def compare_metrics expected_list, actual_list
40
+ actual = Set.new actual_list
41
+ actual.delete('GC/cumulative') # in case we are in REE
42
+ expected = Set.new expected_list
43
+ assert_equal expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.join(", ")}; missing: #{(expected - actual).to_a.join(", ")}"
44
+ end
45
+ =begin Enable this to see test names as they run
46
+ Test::Unit::TestCase.class_eval do
47
+ def run_with_info *args, &block
48
+ puts "#{self.class.name.underscore}/#{@method_name}"
49
+ run_without_info *args, &block
50
+ end
51
+ alias_method_chain :run, :info
52
+ end
53
+ =end
54
+ module TransactionSampleTestHelper
55
+ def make_sql_transaction(*sql)
56
+ sampler = NewRelic::Agent::TransactionSampler.new
57
+ sampler.notice_first_scope_push Time.now.to_f
58
+ sampler.notice_transaction '/path', nil, :jim => "cool"
59
+ sampler.notice_push_scope "a"
60
+
61
+ sampler.notice_transaction '/path/2', nil, :jim => "cool"
62
+
63
+ sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "test"}, 0 ) }
64
+
65
+ sleep 1.0
66
+ yield if block_given?
67
+ sampler.notice_pop_scope "a"
68
+ sampler.notice_scope_empty
69
+
70
+ sampler.samples[0]
71
+ end
72
+ end