Skip to content

Commit

Permalink
Story ID:14990921 data spool file respects custom log location
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Guymon committed Jun 24, 2011
1 parent 62332a2 commit 67363e4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/new_relic/control/configuration.rb
Expand Up @@ -149,6 +149,10 @@ def use_ssl?
@use_ssl
end

def log_file_path
fetch('log_file_path', 'log/')
end

# only verify certificates if you're very sure you want this
# level of security, it includes possibly app-crashing dns
# lookups every connection to the server
Expand Down
6 changes: 2 additions & 4 deletions lib/new_relic/data_serialization.rb
Expand Up @@ -140,13 +140,11 @@ def truncate_file
end

def file_path
# TODO get configuration from main control
'./log/newrelic_agent_store.db'
"#{NewRelic::Control.instance.log_file_path}/newrelic_agent_store.db"
end

def semaphore_path
# TODO get configuration from main control
'./log/newrelic_agent_store.age'
"#{NewRelic::Control.instance.log_file_path}/newrelic_agent_store.age"
end
end
extend ClassMethods
Expand Down
10 changes: 9 additions & 1 deletion test/new_relic/control/configuration_test.rb
Expand Up @@ -12,5 +12,13 @@ def test_license_key_defaults_to_env_variable
license_key
end


def test_log_file_path_uses_default_if_not_set
assert_equal(File.join(Rails.root, 'log'),
NewRelic::Control.instance.log_file_path)
end

def test_log_file_path_uses_given_value
NewRelic::Control.instance['log_file_path'] = '/lerg'
assert_equal '/lerg', NewRelic::Control.instance.log_file_path
end
end
18 changes: 18 additions & 0 deletions test/new_relic/data_serialization_test.rb
Expand Up @@ -3,6 +3,7 @@
class NewRelic::DataSerializationTest < Test::Unit::TestCase

def setup
NewRelic::Control.instance['log_file_path'] = './log'
FileUtils.rm_rf('./log/newrelic_agent_store.db')
FileUtils.rm_rf('./log/newrelic_agent_store.age')
end
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_read_until_eoferror
end
assert_equal('a' * 10_001, value, "should retrieve all the contents from the string and not raise EOFerrors")
end

def test_write_contents_nonblockingly
file = './log/newrelic_agent_store.db'
File.open(file, 'w') do |f|
Expand Down Expand Up @@ -103,4 +105,20 @@ def test_should_handle_empty_spool_file
NewRelic::Control.instance.log.expects(:error).never
assert_nil NewRelic::DataSerialization.instance_eval { load('') }
end

def test_spool_file_location_respects_log_file_path_setting
NewRelic::Control.instance['log_file_path'] = "./tmp"
NewRelic::DataSerialization.read_and_write_to_file do |_|
'a' * 30
end
assert(File.exists?('./tmp/newrelic_agent_store.db'),
"Spool file not created at user specified location")
end

def test_age_file_location_respects_log_file_path_setting
NewRelic::Control.instance['log_file_path'] = "./tmp"
NewRelic::DataSerialization.update_last_sent!
assert(File.exists?('./tmp/newrelic_agent_store.age'),
"Age file not created at user specified location")
end
end

0 comments on commit 67363e4

Please sign in to comment.