commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r483661 - in /jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration: TestXMLConfiguration.java reloading/FileAlwaysReloadingStrategy.java
Date Thu, 07 Dec 2006 20:58:10 GMT
Author: oheger
Date: Thu Dec  7 12:58:09 2006
New Revision: 483661

URL: http://svn.apache.org/viewvc?view=rev&rev=483661
Log:
Added new FileAlwaysReloadingStrategy under test classes for simplifying reloading tests for
file-based configurations

Added:
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
  (with props)
Modified:
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?view=diff&rev=483661&r1=483660&r2=483661
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Thu Dec  7 12:58:09 2006
@@ -32,6 +32,7 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.apache.commons.configuration.reloading.FileAlwaysReloadingStrategy;
 import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
 import org.apache.commons.configuration.reloading.InvariantReloadingStrategy;
 import org.apache.commons.configuration.tree.ConfigurationNode;
@@ -556,7 +557,7 @@
         conf.load(testSaveConf);
         assertEquals("foo", conf.getString("element3[@name]"));
     }
-    
+
     /**
      * Tests collaboration between XMLConfiguration and a reloading strategy.
      */
@@ -573,27 +574,22 @@
             out.close();
             out = null;
             conf.setFile(testSaveConf);
-            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
+            FileAlwaysReloadingStrategy strategy = new FileAlwaysReloadingStrategy();
             strategy.setRefreshDelay(100);
             conf.setReloadingStrategy(strategy);
             assertEquals(strategy, conf.getReloadingStrategy());
+            assertEquals("Wrong file monitored", testSaveConf.getAbsolutePath(),
+                    strategy.getMonitoredFile().getAbsolutePath());
             conf.load();
             assertEquals(1, conf.getInt("test"));
-            Thread.sleep(1000);
 
             out = new PrintWriter(new FileWriter(testSaveConf));
             out.println("<?xml version=\"1.0\"?><config><test>2</test></config>");
             out.close();
             out = null;
 
-            int trial = 0, value;
-            // repeat multiple times because there are sometimes race conditions
-            do
-            {
-                Thread.sleep(1000);
-                value = conf.getInt("test");
-            } while (value != 2 && ++trial <= 10);
-            assertEquals(2, value);
+            int value = conf.getInt("test");
+            assertEquals("No reloading performed", 2, value);
         }
         finally
         {
@@ -603,7 +599,7 @@
             }
         }
     }
-    
+
     /**
      * Tests access to tag names with delimiter characters.
      */
@@ -612,7 +608,7 @@
         assertEquals("Name with dot", conf.getString("complexNames.my..elem"));
         assertEquals("Another dot", conf.getString("complexNames.my..elem.sub..elem"));
     }
-    
+
     /**
      * Tests setting a custom document builder.
      */
@@ -646,14 +642,14 @@
         {
             //ok
         }
-        
+
         // Try to load a valid document with a validating builder
         conf = new XMLConfiguration();
         conf.setDocumentBuilder(builder);
         conf.load(new File("conf/testValidateValid.xml"));
         assertTrue(conf.containsKey("table.fields.field(1).type"));
     }
-    
+
     /**
      * Tests the clone() method.
      */
@@ -666,13 +662,13 @@
         assertNull(copy.getDocument());
         assertNotNull(conf.getFileName());
         assertNull(copy.getFileName());
-        
+
         copy.setProperty("element3", "clonedValue");
         assertEquals("value", conf.getString("element3"));
         conf.setProperty("element3[@name]", "originalFoo");
         assertEquals("foo", copy.getString("element3[@name]"));
     }
-    
+
     /**
      * Tests the subset() method. There was a bug that calling subset() had
      * undesired side effects.
@@ -683,11 +679,11 @@
         conf.load(new File("conf/testHierarchicalXMLConfiguration.xml"));
         conf.subset("tables.table(0)");
         conf.save(testSaveConf);
-        
+
         conf = new XMLConfiguration(testSaveConf);
         assertEquals("users", conf.getString("tables.table(0).name"));
     }
-    
+
     /**
      * Tests string properties with list delimiters and escaped delimiters.
      */
@@ -700,7 +696,7 @@
         assertEquals(2, conf.getMaxIndex("split.list1"));
         assertEquals("a,b,c", conf.getString("split.list2"));
     }
-    
+
     /**
      * Tests string properties with list delimiters when delimiter parsing
      * is disabled
@@ -728,7 +724,7 @@
         assertEquals("value1", conf.getString("entry(0)"));
         assertEquals("test2", conf.getString("entry(1)[@key]"));
     }
-    
+
     /**
      * Tests DTD validation using the setValidating() method.
      */

Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java?view=auto&rev=483661
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
(added)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
Thu Dec  7 12:58:09 2006
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.reloading;
+
+import java.io.File;
+
+/**
+ * A specialized reloading strategy for files that will always report a change
+ * of the monitored file. Thus it is well suited for testing reloading
+ * operations on file-based configurations.
+ *
+ * @version $Id$
+ */
+public class FileAlwaysReloadingStrategy extends FileChangedReloadingStrategy
+{
+    /**
+     * Checks whether a reload is necessary. This implementation returns always
+     * <b>true</b>.
+     *
+     * @return a flag whether a reload is required
+     */
+    public boolean reloadingRequired()
+    {
+        return true;
+    }
+
+    /**
+     * Returns the file that is watched by this strategy.
+     *
+     * @return the monitored file
+     */
+    public File getMonitoredFile()
+    {
+        return getFile();
+    }
+}

Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileAlwaysReloadingStrategy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message