commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] Commented: (CONFIGURATION-425) FileChangedReloadingStrategy works differently on Unix and Windows
Date Fri, 29 Oct 2010 20:00:45 GMT


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:
    public void testAutomaticReloading() throws Exception
        // create a new configuration
        File file = new File("target/");

        if (file.exists())

        // create the configuration file
        FileWriter out = new FileWriter(file);

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


        // change the file
        out = new FileWriter(file);

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

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:
>             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 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 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,
> 		/*
> 		 * 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.
> 			 */			
>"Sleeping until configuration refresh delay has passed");
> 			sleep(6000L);
>"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
> 		{
>"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.

View raw message