You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2007/12/25 20:06:04 UTC

svn commit: r606798 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java xdocs/changes.xml

Author: oheger
Date: Tue Dec 25 11:05:58 2007
New Revision: 606798

URL: http://svn.apache.org/viewvc?rev=606798&view=rev
Log:
CONFIGURATION-302: FileChangedReloadingStrategy.reloadingRequired() now returns true until reloadingPerformed() has been called.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java?rev=606798&r1=606797&r2=606798&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/reloading/FileChangedReloadingStrategy.java Tue Dec 25 11:05:58 2007
@@ -61,6 +61,9 @@
     /** The minimum delay in milliseconds between checks. */
     protected long refreshDelay = DEFAULT_REFRESH_DELAY;
 
+    /** A flag whether a reload is required.*/
+    private boolean reloading;
+
     public void setConfiguration(FileConfiguration configuration)
     {
         this.configuration = configuration;
@@ -73,16 +76,17 @@
 
     public boolean reloadingRequired()
     {
-        boolean reloading = false;
-
-        long now = System.currentTimeMillis();
-
-        if (now > lastChecked + refreshDelay)
+        if (!reloading)
         {
-            lastChecked = now;
-            if (hasChanged())
+            long now = System.currentTimeMillis();
+
+            if (now > lastChecked + refreshDelay)
             {
-                reloading = true;
+                lastChecked = now;
+                if (hasChanged())
+                {
+                    reloading = true;
+                }
             }
         }
 
@@ -124,6 +128,7 @@
         {
             lastModified = file.lastModified();
         }
+        reloading = false;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java?rev=606798&r1=606797&r2=606798&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestFileChangedReloadingStrategy.java Tue Dec 25 11:05:58 2007
@@ -22,6 +22,8 @@
 import java.net.URL;
 
 import junit.framework.TestCase;
+
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.configuration.XMLConfiguration;
 
@@ -33,6 +35,9 @@
  */
 public class TestFileChangedReloadingStrategy extends TestCase
 {
+    /** Constant for the name of a test properties file.*/
+    private static final String TEST_FILE = "test.properties";
+
     public void testAutomaticReloading() throws Exception
     {
         // create a new configuration
@@ -111,14 +116,14 @@
     public void testFromClassPath() throws Exception
     {
         PropertiesConfiguration config = new PropertiesConfiguration();
-        config.setFileName("test.properties");
+        config.setFileName(TEST_FILE);
         config.load();
         assertTrue(config.getBoolean("configuration.loaded"));
         FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
         config.setReloadingStrategy(strategy);
         assertEquals(config.getURL(), strategy.getFile().toURL());
     }
-    
+
     /**
      * Tests to watch a configuration file in a jar. In this case the jar file
      * itself should be monitored.
@@ -133,5 +138,29 @@
         File file = strategy.getFile();
         assertNotNull("Strategy's file is null", file);
         assertEquals("Strategy does not monitor the jar file", "resources.jar", file.getName());
+    }
+
+    /**
+     * Tests calling reloadingRequired() multiple times before a reload actually
+     * happens. This test is related to CONFIGURATION-302.
+     */
+    public void testReloadingRequiredMultipleTimes()
+            throws ConfigurationException
+    {
+        FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy()
+        {
+            protected boolean hasChanged()
+            {
+                // signal always a change
+                return true;
+            }
+        };
+        strategy.setRefreshDelay(100000);
+        PropertiesConfiguration config = new PropertiesConfiguration(TEST_FILE);
+        config.setReloadingStrategy(strategy);
+        assertTrue("Reloading not required", strategy.reloadingRequired());
+        assertTrue("Reloading no more required", strategy.reloadingRequired());
+        strategy.reloadingPerformed();
+        assertFalse("Reloading still required", strategy.reloadingRequired());
     }
 }

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=606798&r1=606797&r2=606798&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Tue Dec 25 11:05:58 2007
@@ -23,6 +23,11 @@
 
   <body>
     <release version="1.6" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-302">
+        If a change has been detected by FileChangedReloadingStrategy, the
+        reloadingRequired() method will now return true until
+        reloadingPerformed() has been called.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-301">
         Fixed a NullPointerException that could be thrown under certain
         circumstances when saving an XMLConfiguration that was created using