[ 
https://issues.apache.org/jira/browse/CONFIGURATION-425?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12926434#action_12926434
 ] 

Oliver Heger commented on CONFIGURATION-425:
--------------------------------------------

Unfortunately I am no expert on Linux file systems either.

However, in the test class for {{FileChangedReloadingStrategy}} we have a test 
which basically does the same as you describe:
* A properties file is created which assigns a value to a property.
* A PropertiesConfiguration object is created which loads this properties file.
* A FileChangedReloadingStrategy object is created and associated with the 
configuration.
* Then a file operation is performed which changes the content of the 
properties file.
* The current thread sleeps a while to ensure that the refresh interval is 
reached.
* Finally we check whether the configuration object sees the changed value to 
verify that the reload actually happened.

Below is the complete code of this test method:
{code}
    public void testAutomaticReloading() throws Exception
    {
        // create a new configuration
        File file = new File("target/testReload.properties");

        if (file.exists())
        {
            file.delete();
        }

        // create the configuration file
        FileWriter out = new FileWriter(file);
        out.write("string=value1");
        out.flush();
        out.close();

        // load the configuration
        PropertiesConfiguration config = new 
PropertiesConfiguration("target/testReload.properties");
        FileChangedReloadingStrategy strategy = new 
FileChangedReloadingStrategy();
        strategy.setRefreshDelay(500);
        config.setReloadingStrategy(strategy);
        assertEquals("Initial value", "value1", config.getString("string"));

        Thread.sleep(2000);

        // change the file
        out = new FileWriter(file);
        out.write("string=value2");
        out.flush();
        out.close();

        // test the automatic reloading
        assertEquals("Modified value with enabled reloading", "value2", 
config.getString("string"));
    }
{code}

This test executes successfully for me under Ubuntu 10 (actually it is a 
virtual machine running under Windows 7, but this should not make a difference).

Can you verify that this basic test works for you? If so, the problem seems to 
be somewhere else, maybe in the configuration manager?

> FileChangedReloadingStrategy works differently on Unix and Windows
> ------------------------------------------------------------------
>
>                 Key: CONFIGURATION-425
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-425
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: File reloading
>    Affects Versions: 1.6
>         Environment: Windows 7 x64 and Ubuntu 10.04 Server
>            Reporter: Dan Haynes
>            Priority: Minor
>
> I created a unit test for a configuration class that uses commons 
> configuration. It loads both a set of static properties and a set of dynamic 
> properties, the latter uses FilechangeReloadingStragegy. The unit test copies 
> a file containing an initial set of of dynamic properties (using commons-io 
> FileUtils.copy()) , verifies the values are as expected and then copies an 
> updated set of properties, sleeps longer than the refresh delay and then 
> verifies the new values are in place. 
> On WIndows it works as expected. It recognizes that FileUtils.copy() has 
> replaced the dynamic.properties file with an updated version and it loads the 
> new property values. 
> On Linux, nothing I do makes it recognize that the file has been replaced 
> except by actually opening a shell and editing the dynamic.properties values. 
> Then it works as expected.
> This may well be my lack of understanding of some Unix filesystem behavior 
> but it seems like FilechangeReloadingStrategy should notice the change to the 
> file one way or the other.
> The unit test looks like so:
> {code}
>               final ConfigurationManager cm = new 
> StandardConfigurationManager(staticTestPropertiesFileName, 
> dynamicTestPropertiesFileName);
>               /*
>                * Initialize the configuration manager. This should read all 
> the initial values.
>                */
>               cm.init();
>               Assert.assertEquals(System.getProperty("java.user"), 
> cm.retrieveUserName());
>               /*
>                * Verify that the static properties were read.
>                */
>               Assert.assertEquals("1.00", cm.retrieveVersionId());
>               /*
>                * Verify that the initial values for the dynamic properties 
> were read.
>                */
>               Assert.assertEquals(100, cm.retrieveMaxConcurrentLogons());
>               if (copyFile(updatedConfigFileName, 
> dynamicTestPropertiesFileName))
>               {
>                       /*
>                        * The default update window for Apache commons 
> configuration file reload strategy is 5 seconds
>                        * so wait more than 5 seconds to ensure the new value 
> will be read.
>                        */                     
>                       log.info("Sleeping until configuration refresh delay 
> has passed");
>                       sleep(6000L);
>                       log.info("Woke, resuming test, maxConcurrentLogons = " 
> + cm.retrieveMaxConcurrentLogons());
>                               
>                       /*
>                        * Verify that the property was updated to the expected 
> new value.
>                        */
> >>> this fails every time on Linux:   Assert.assertEquals(1, 
> >>> cm.retrieveMaxConcurrentLogons());
>               }
>               else
>               {
>                       Assert.fail("Couldn't copy updated test properties 
> file");
>               }
> {code}
> I've tried everything I could think of to trigger the reload strategy. After 
> calling FileUtils.copy() on the file I added a FileUtils.touch() on the 
> destination file. That didn't work so I added a "Process process = 
> runtime.exec("touch " + destFile.getAbsolutePath());" to be absolutely 100% 
> certain the file timestamp is being updated. It gets updated, but the 
> reloading strategy never recognizes it. 
> I googled and searched the JIRA incidents and the only thing I can find that 
> looks similar are some references to a problem in V1.1 that was fixed long 
> ago.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to