newrelic_rpm 3.1.0.beta2 → 3.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

@@ -210,15 +210,20 @@ module NewRelic
210
210
  end
211
211
 
212
212
  def save_data
213
- NewRelic::DataSerialization.dump_to_file do |old_data|
213
+ NewRelic::DataSerialization.read_and_write_to_file do |old_data|
214
214
  agent.merge_data_from(old_data)
215
215
  agent.serialize
216
216
  end
217
217
  end
218
218
 
219
219
  def load_data
220
- agent.merge_data_from(NewRelic::DataSerialization.load_from_file)
221
- {:metrics => agent.stats_engine.metrics.length, :traces => agent.unsent_traces_size, :errors => agent.unsent_errors_size}
220
+ value = nil
221
+ NewRelic::DataSerialization.read_and_write_to_file do |old_data|
222
+ agent.merge_data_from(old_data)
223
+ value = {:metrics => agent.stats_engine.metrics.length, :traces => agent.unsent_traces_size, :errors => agent.unsent_errors_size}
224
+ nil # return nil so nothing is written to the file
225
+ end
226
+ value
222
227
  end
223
228
 
224
229
  # Add instrumentation files to the agent. The argument should be
@@ -996,10 +996,16 @@ module NewRelic
996
996
  if @connected
997
997
  begin
998
998
  @request_timeout = 10
999
- # log.debug "Flushing unsent metric data to server"
1000
- # harvest_and_send_timeslice_data
1001
- log.debug "Serializing agent data to disk"
1002
- NewRelic::Agent.save_data
999
+ if NewRelic::DataSerialization.should_send_data?
1000
+ log.debug "Sending data to New Relic Service"
1001
+ NewRelic::Agent.load_data
1002
+ harvest_and_send_errors
1003
+ harvest_and_send_slowest_sample
1004
+ harvest_and_send_timeslice_data
1005
+ else
1006
+ log.debug "Serializing agent data to disk"
1007
+ NewRelic::Agent.save_data
1008
+ end
1003
1009
  if @connected_pid == $$
1004
1010
  log.debug "Sending New Relic service agent run shutdown message"
1005
1011
  invoke_remote :shutdown, @agent_id, Time.now.to_f
@@ -9,7 +9,7 @@ module NewRelic
9
9
  attr_reader :rum_enabled
10
10
  attr_reader :license_bytes
11
11
 
12
- JS_HEADER = "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
12
+ JS_HEADER = "<script type=\"text/javascript\">var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
13
13
 
14
14
  def initialize(connect_data)
15
15
  @browser_monitoring_key = connect_data['browser_key']
@@ -17,8 +17,11 @@ module NewRelic
17
17
  @beacon = connect_data['beacon']
18
18
  @rum_enabled = connect_data['rum.enabled']
19
19
  @rum_enabled = true if @rum_enabled.nil?
20
+ NewRelic::Control.instance.log.warn("Real User Monitoring is disabled for this agent. Edit your configuration to change this.") unless @rum_enabled
20
21
  @browser_timing_header = build_browser_timing_header
21
- @browser_timing_static_footer = build_load_file_js(connect_data)
22
+ NewRelic::Control.instance.log.debug("Browser timing header: #{@browser_timing_header.inspect}")
23
+ @browser_timing_static_footer = build_load_file_js(connect_data)
24
+ NewRelic::Control.instance.log.debug("Browser timing static footer: #{@browser_timing_static_footer.inspect}")
22
25
  end
23
26
 
24
27
  def license_bytes
@@ -33,7 +36,7 @@ module NewRelic
33
36
  return "" unless connect_data.fetch('rum.load_episodes_file', true)
34
37
 
35
38
  episodes_url = connect_data.fetch('episodes_url', '')
36
- "(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"#{episodes_url}\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();"
39
+ "(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"#{episodes_url}\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();"
37
40
  end
38
41
 
39
42
  def javascript_header
@@ -56,7 +56,7 @@ module NewRelic
56
56
 
57
57
  def footer_js_string(beacon, license_key, application_id)
58
58
  obfuscated_transaction_name = obfuscate(browser_monitoring_transaction_name)
59
- html_safe_if_needed("<script>#{NewRelic::Agent.instance.beacon_configuration.browser_timing_static_footer}NREUMQ.push([\"nrf2\",\"#{beacon}\",\"#{license_key}\",#{application_id},\"#{obfuscated_transaction_name}\",#{browser_monitoring_queue_time},#{browser_monitoring_app_time},new Date().getTime()])</script>")
59
+ html_safe_if_needed("<script type=\"text/javascript\">#{NewRelic::Agent.instance.beacon_configuration.browser_timing_static_footer}NREUMQ.push([\"nrf2\",\"#{beacon}\",\"#{license_key}\",#{application_id},\"#{obfuscated_transaction_name}\",#{browser_monitoring_queue_time},#{browser_monitoring_app_time},new Date().getTime()])</script>")
60
60
  end
61
61
 
62
62
  def html_safe_if_needed(string)
@@ -74,7 +74,7 @@ module NewRelic
74
74
  attr_reader :depth
75
75
 
76
76
  def initialize
77
- @start = Time.now
77
+ Thread.current[:newrelic_start_time] = @start = Time.now
78
78
  @path_stack = [] # stack of [controller, path] elements
79
79
  @jruby_cpu_start = jruby_cpu_time
80
80
  @process_cpu_start = process_cpu
@@ -9,13 +9,6 @@ module NewRelic
9
9
  Thread.current[:newrelic_metric_frame] = nil
10
10
  end
11
11
 
12
- def set_last_start_time!
13
- frame = Thread.current[:newrelic_metric_frame]
14
- if frame && frame.respond_to?(:start)
15
- Thread.current[:newrelic_start_time] = Thread.current[:newrelic_metric_frame].start
16
- end
17
- end
18
-
19
12
  def set_new_scope!(metric)
20
13
  agent.stats_engine.scope_name = metric
21
14
  end
@@ -78,7 +71,6 @@ module NewRelic
78
71
  raise 'path stack not empty' unless @path_stack.empty?
79
72
  notify_transaction_sampler(metric.is_web_transaction?) if traced?
80
73
  end_transaction!
81
- set_last_start_time!
82
74
  clear_thread_metric_frame!
83
75
  end
84
76
 
@@ -84,6 +84,7 @@ module Agent
84
84
  # via controller actions
85
85
  def scope_name=(transaction)
86
86
  Thread::current[:newrelic_scope_name] = transaction
87
+ Thread::current[:newrelic_most_recent_transaction] = transaction
87
88
  end
88
89
 
89
90
  def scope_name
@@ -104,7 +105,6 @@ module Agent
104
105
  stack = scope_stack
105
106
 
106
107
  if stack && stack.empty?
107
- Thread::current[:newrelic_most_recent_transaction] = Thread::current[:newrelic_scope_name]
108
108
  Thread::current[:newrelic_scope_stack] = nil
109
109
  Thread::current[:newrelic_scope_name] = nil
110
110
  end
@@ -11,7 +11,11 @@ module NewRelic
11
11
  @env ||= RAILS_ENV.dup
12
12
  end
13
13
  def root
14
- RAILS_ROOT
14
+ if defined?(RAILS_ROOT) && RAILS_ROOT.to_s != ''
15
+ RAILS_ROOT.to_s
16
+ else
17
+ super
18
+ end
15
19
  end
16
20
 
17
21
  # In versions of Rails prior to 2.0, the rails config was only available to
@@ -66,12 +70,10 @@ module NewRelic
66
70
  end
67
71
 
68
72
  def log!(msg, level=:info)
69
- return unless should_log?
70
- begin
71
- ::RAILS_DEFAULT_LOGGER.send(level, msg)
72
- rescue Exception => e
73
- super
74
- end
73
+ super unless should_log?
74
+ ::RAILS_DEFAULT_LOGGER.send(level, msg)
75
+ rescue Exception => e
76
+ super
75
77
  end
76
78
 
77
79
  def to_stdout(message)
@@ -10,9 +10,18 @@ module NewRelic
10
10
  def env
11
11
  ::Rails.env.to_s
12
12
  end
13
-
13
+
14
+ # Rails can return an empty string from this method, causing
15
+ # the agent not to start even when it is properly in a rails 3
16
+ # application, so we test the value to make sure it actually
17
+ # has contents, and bail to the parent class if it is empty.
14
18
  def root
15
- ::Rails.root.to_s
19
+ value = ::Rails.root.to_s
20
+ if value.empty?
21
+ super
22
+ else
23
+ value
24
+ end
16
25
  end
17
26
 
18
27
  def logger
@@ -21,7 +30,7 @@ module NewRelic
21
30
 
22
31
 
23
32
  def log!(msg, level=:info)
24
- return unless should_log?
33
+ super unless should_log?
25
34
  logger.send(level, msg)
26
35
  rescue Exception => e
27
36
  super
@@ -130,7 +130,7 @@ module NewRelic
130
130
  generated_for_user = ''
131
131
  license_key=''
132
132
  if !File.exists?(newrelic_file)
133
- log! "Cannot find read #{newrelic_file}."
133
+ puts "Cannot find or read #{newrelic_file}"
134
134
  @yaml = {}
135
135
  else
136
136
  @yaml = YAML.load(ERB.new(File.read(newrelic_file)).result(binding))
@@ -141,6 +141,10 @@ module NewRelic
141
141
  raise "Error reading newrelic.yml file: #{e}"
142
142
  end
143
143
 
144
+ def root
145
+ '.'
146
+ end
147
+
144
148
  def newrelic_root
145
149
  self.class.newrelic_root
146
150
  end
@@ -20,8 +20,8 @@ module NewRelic
20
20
  # The to_stdout may be implemented differently by different config subclasses.
21
21
  # This will NOT print anything if tracers are not enabled
22
22
  def log!(msg, level=:info)
23
- return unless should_log?
24
23
  to_stdout msg
24
+ return unless should_log?
25
25
  log.send level, msg if @log
26
26
  end
27
27
 
@@ -6,29 +6,19 @@ module NewRelic
6
6
  # TODO get configuration from main control
7
7
  (File.size(file_path) >= max_size)
8
8
  end
9
-
10
- def load_from_file
11
- create_file_if_needed
12
- with_locked_store('r+') do |f|
13
- get_data_from_file(f)
14
- end
15
- rescue(EOFError) => e
16
- nil
17
- end
18
-
19
- def dump_to_file
20
- create_file_if_needed
21
- with_locked_store('r+') do |f|
9
+
10
+ def read_and_write_to_file
11
+ with_locked_store do |f|
22
12
  result = (yield get_data_from_file(f))
23
13
  f.rewind
24
- f.write(dump(result))
14
+ f.write(dump(result)) if result
25
15
  end
26
16
  end
27
17
 
28
18
  private
29
19
 
30
- def with_locked_store(mode)
31
- File.open(file_path, mode) do |f|
20
+ def with_locked_store
21
+ File.open(file_path, File::RDWR | File::CREAT) do |f|
32
22
  f.flock(File::LOCK_EX)
33
23
  begin
34
24
  yield(f)
@@ -48,7 +38,7 @@ module NewRelic
48
38
  end
49
39
 
50
40
  def max_size
51
- 100_000
41
+ 10_000
52
42
  end
53
43
 
54
44
  def create_file_if_needed
@@ -4,7 +4,7 @@ module NewRelic
4
4
  MAJOR = 3
5
5
  MINOR = 1
6
6
  TINY = 0
7
- BUILD = 'beta2' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
7
+ BUILD = 'beta3' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{newrelic_rpm}
8
- s.version = "3.1.0.beta2"
8
+ s.version = "3.1.0.beta3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Kayser", "Justin George"]
12
- s.date = %q{2011-05-20}
12
+ s.date = %q{2011-05-26}
13
13
  s.description = %q{New Relic is a performance management system, developed by New Relic,
14
14
  Inc (http://www.newrelic.com). New Relic provides you with deep
15
15
  information about the performance of your web application as it runs
@@ -189,7 +189,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
189
189
  'Middleware/all',
190
190
  'WebFrontend/WebServer/all']
191
191
 
192
- compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
192
+ compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0 || m.index('GC')==0}
193
193
  assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_before_filter_error").call_count
194
194
  assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
195
195
  apdex = engine.get_stats_no_scope("Apdex")
@@ -15,11 +15,11 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
15
15
  def test_initialize_with_real_data
16
16
  connect_data = {'browser_key' => 'a browser monitoring key', 'application_id' => 'an application id', 'beacon' => 'a beacon', 'rum_enabled' => true}
17
17
  bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
18
- assert_equal true, bc.rum_enabled
19
- assert_equal 'a browser monitoring key', bc.browser_monitoring_key
20
- assert_equal 'an application id', bc.application_id
21
- assert_equal 'a beacon', bc.beacon
22
- assert_equal 86, bc.browser_timing_header.size
18
+ assert_equal(true, bc.rum_enabled)
19
+ assert_equal('a browser monitoring key', bc.browser_monitoring_key)
20
+ assert_equal('an application id', bc.application_id)
21
+ assert_equal('a beacon', bc.beacon)
22
+ assert_equal(109, bc.browser_timing_header.size, "should output the javascript with all the data available")
23
23
  end
24
24
 
25
25
  def test_license_bytes_nil
@@ -87,13 +87,13 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
87
87
  def test_build_load_file_js_load_episodes_file_missing
88
88
  connect_data = {}
89
89
  bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
90
- assert_equal(159, bc.build_load_file_js(connect_data).size, "should output the javascript when there is no configuration")
90
+ assert_equal(184, bc.build_load_file_js(connect_data).size, "should output the javascript when there is no configuration")
91
91
  end
92
92
 
93
93
  def test_build_load_file_js_load_episodes_file_present
94
94
  connect_data = {'rum.load_episodes_file' => true}
95
95
  bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
96
- assert_equal(159, bc.build_load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
96
+ assert_equal(184, bc.build_load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
97
97
  end
98
98
 
99
99
  def test_build_load_file_js_load_episodes_file_with_episodes_url
@@ -30,13 +30,13 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
30
30
 
31
31
  def test_browser_timing_header
32
32
  header = browser_timing_header
33
- assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
33
+ assert_equal "<script type=\"text/javascript\">var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
34
34
  end
35
35
 
36
36
  def test_browser_timing_header_with_rum_enabled_not_specified
37
37
  NewRelic::Agent.instance.expects(:beacon_configuration).at_least_once.returns( NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
38
38
  header = browser_timing_header
39
- assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
39
+ assert_equal "<script type=\"text/javascript\">var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
40
40
  end
41
41
 
42
42
  def test_browser_timing_header_with_rum_enabled_false
@@ -68,7 +68,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
68
68
  Thread.current[:newrelic_start_time] = Time.now
69
69
 
70
70
  footer = browser_timing_footer
71
- snippet = "<script>(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
71
+ snippet = "<script type=\"text/javascript\">(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
72
72
  assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
73
73
  end
74
74
 
@@ -101,7 +101,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
101
101
  config.expects(:license_bytes).returns(license_bytes)
102
102
  NewRelic::Agent.instance.expects(:beacon_configuration).returns(config).at_least_once
103
103
  footer = browser_timing_footer
104
- beginning_snippet = "(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
104
+ beginning_snippet = "(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
105
105
  ending_snippet = "])</script>"
106
106
  assert(footer.include?(beginning_snippet), "expected footer to include beginning snippet: #{beginning_snippet}, but was #{footer}")
107
107
  assert(footer.include?(ending_snippet), "expected footer to include ending snippet: #{ending_snippet}, but was #{footer}")
@@ -234,7 +234,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
234
234
  self.expects(:obfuscate).with('most recent transaction').returns('most recent transaction')
235
235
 
236
236
  value = footer_js_string(beacon, license_key, application_id)
237
- assert_equal('<script>(function(){var d=document;var e=d.createElement("script");e.async=true;e.src="this_is_my_file";var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push(["nrf2","","",1,"most recent transaction",0,0,new Date().getTime()])</script>', value, "should return the javascript given some default values")
237
+ assert_equal('<script type="text/javascript">(function(){var d=document;var e=d.createElement("script");e.async=true;e.src="this_is_my_file";e.type="text/javascript";var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push(["nrf2","","",1,"most recent transaction",0,0,new Date().getTime()])</script>', value, "should return the javascript given some default values")
238
238
  end
239
239
 
240
240
  def test_html_safe_if_needed_unsafed
@@ -22,19 +22,6 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
22
22
  assert_equal nil, Thread.current[:newrelic_metric_frame], 'should nil out the thread var'
23
23
  end
24
24
 
25
- def test_set_last_start_time
26
- start_time = Time.now
27
- mock_frame = mock('frame')
28
- mock_frame.expects(:respond_to?).with(:start).returns(true)
29
- mock_frame.expects(:start).returns(start_time)
30
- Thread.current[:newrelic_start_time] = nil
31
- Thread.current[:newrelic_metric_frame] = mock_frame
32
-
33
- set_last_start_time!
34
-
35
- assert_equal(start_time, Thread.current[:newrelic_start_time], "should set the start time correctly: #{start_time.inspect} expected but was #{Thread.current[:newrelic_start_time].inspect}")
36
- end
37
-
38
25
  def test_set_new_scope
39
26
  fakeagent = mock('agent')
40
27
  self.expects(:agent).returns(fakeagent)
@@ -152,7 +139,6 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
152
139
  fakemetric.expects(:is_web_transaction?).returns(true)
153
140
  self.expects(:notify_transaction_sampler).with(true)
154
141
  self.expects(:end_transaction!)
155
- self.expects(:set_last_start_time!)
156
142
  self.expects(:clear_thread_metric_frame!)
157
143
  handle_empty_path_stack(fakemetric)
158
144
  end
@@ -164,7 +150,6 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
164
150
  fakemetric.expects(:is_web_transaction?).returns(false)
165
151
  self.expects(:notify_transaction_sampler).with(false)
166
152
  self.expects(:end_transaction!)
167
- self.expects(:set_last_start_time!)
168
153
  self.expects(:clear_thread_metric_frame!)
169
154
  handle_empty_path_stack(fakemetric)
170
155
  end
@@ -182,7 +167,6 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
182
167
  fakemetric = mock('metric')
183
168
  fakemetric.expects(:is_web_transaction?).never
184
169
  self.expects(:end_transaction!)
185
- self.expects(:set_last_start_time!)
186
170
  self.expects(:clear_thread_metric_frame!)
187
171
  handle_empty_path_stack(fakemetric)
188
172
  end
@@ -23,15 +23,15 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
23
23
  # This shows how the tasks stay aligned with the period and don't drift.
24
24
  count = 0
25
25
  start = Time.now
26
- @worker_loop.run(0.002) do
26
+ @worker_loop.run(0.01) do
27
27
  count +=1
28
- if count == 10
28
+ if count == 3
29
29
  @worker_loop.stop
30
30
  next
31
31
  end
32
32
  end
33
33
  elapsed = Time.now - start
34
- assert_in_delta 0.019, elapsed, 0.02
34
+ assert_in_delta 0.03, elapsed, 0.02
35
35
  end
36
36
  def test_task_error__standard
37
37
  @logger.expects(:debug)
@@ -1,48 +1,55 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
2
  require 'new_relic/data_serialization'
3
3
  class NewRelic::DataSerializationTest < Test::Unit::TestCase
4
- def test_load_from_file
4
+ def test_read_and_write_from_file_read_only
5
5
  file = './log/newrelic_agent_store.db'
6
6
  File.open(file, 'w') do |f|
7
7
  f.write(Marshal.dump('a happy string'))
8
8
  end
9
- assert_equal('a happy string', NewRelic::DataSerialization.load_from_file, "should pull the dumped item from the file")
9
+ NewRelic::DataSerialization.read_and_write_to_file do |data|
10
+ assert_equal('a happy string', data, "should pull the dumped item from the file")
11
+ nil # must explicitly return nil or the return value will be dumped
12
+ end
10
13
  assert_equal(0, File.size(file), "Should not leave any data in the file")
11
14
  end
12
15
 
13
- def test_dump_to_file
16
+ def test_read_and_write_to_file_dumping_contents
14
17
  file = './log/newrelic_agent_store.db'
15
18
  expected_contents = Marshal.dump('a happy string')
16
- NewRelic::DataSerialization.dump_to_file do
19
+ NewRelic::DataSerialization.read_and_write_to_file do
17
20
  'a happy string'
18
21
  end
19
22
  assert_equal(expected_contents, File.read(file), "should have dumped the contents")
20
23
  end
21
24
 
22
- def test_dump_to_file_yields_old_data
25
+ def test_read_and_write_to_file_yields_old_data
23
26
  file = './log/newrelic_agent_store.db'
24
27
  expected_contents = 'a happy string'
25
28
  File.open(file, 'w') do |f|
26
29
  f.write(Marshal.dump(expected_contents))
27
30
  end
28
31
  contents = nil
29
- NewRelic::DataSerialization.dump_to_file do |old_data|
32
+ NewRelic::DataSerialization.read_and_write_to_file do |old_data|
30
33
  contents = old_data
31
34
  'a happy string'
32
35
  end
33
36
  assert_equal(contents, expected_contents, "should have dumped the contents")
34
37
  end
35
38
 
36
- def test_round_trip
37
- NewRelic::DataSerialization.dump_to_file do
39
+ def test_read_and_write_to_file_round_trip
40
+ old_data = nil
41
+ NewRelic::DataSerialization.read_and_write_to_file do |data|
42
+ old_data = data
38
43
  'a' * 30
39
44
  end
40
- assert_equal('a'*30, NewRelic::DataSerialization.load_from_file, "should be the same after serialization")
45
+ NewRelic::DataSerialization.read_and_write_to_file do |data|
46
+ assert_equal('a'*30, data, "should be the same after serialization")
47
+ end
41
48
  end
42
49
 
43
50
  def test_should_send_data
44
51
  NewRelic::DataSerialization.expects(:max_size).returns(20)
45
- NewRelic::DataSerialization.dump_to_file do
52
+ NewRelic::DataSerialization.read_and_write_to_file do
46
53
  "a" * 30
47
54
  end
48
55
  assert(NewRelic::DataSerialization.should_send_data?, 'Should be over limit')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230030
4
+ hash: -1848230029
5
5
  prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
- - beta2
11
- version: 3.1.0.beta2
10
+ - beta3
11
+ version: 3.1.0.beta3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Bill Kayser
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-05-20 00:00:00 -07:00
20
+ date: 2011-05-26 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency