From 67363e4a24e35c6f47e6b8bed6244c5b305b7ea2 Mon Sep 17 00:00:00 2001 From: Jon Guymon Date: Fri, 24 Jun 2011 15:40:26 -0700 Subject: [PATCH] Story ID:14990921 data spool file respects custom log location --- lib/new_relic/control/configuration.rb | 4 ++++ lib/new_relic/data_serialization.rb | 6 ++---- test/new_relic/control/configuration_test.rb | 10 +++++++++- test/new_relic/data_serialization_test.rb | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/new_relic/control/configuration.rb b/lib/new_relic/control/configuration.rb index b092b949e3..38c062c797 100644 --- a/lib/new_relic/control/configuration.rb +++ b/lib/new_relic/control/configuration.rb @@ -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 diff --git a/lib/new_relic/data_serialization.rb b/lib/new_relic/data_serialization.rb index a199896e07..1ecb90bb6e 100644 --- a/lib/new_relic/data_serialization.rb +++ b/lib/new_relic/data_serialization.rb @@ -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 diff --git a/test/new_relic/control/configuration_test.rb b/test/new_relic/control/configuration_test.rb index 1a6683965c..0fc43cf13a 100644 --- a/test/new_relic/control/configuration_test.rb +++ b/test/new_relic/control/configuration_test.rb @@ -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 diff --git a/test/new_relic/data_serialization_test.rb b/test/new_relic/data_serialization_test.rb index 42066a5321..66ef639288 100644 --- a/test/new_relic/data_serialization_test.rb +++ b/test/new_relic/data_serialization_test.rb @@ -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 @@ -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| @@ -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