You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rg...@apache.org on 2009/10/10 19:17:45 UTC
svn commit: r823891 [2/2] - in /commons/proper/configuration/trunk: ./ conf/
src/java/org/apache/commons/configuration/
src/java/org/apache/commons/configuration/beanutils/
src/java/org/apache/commons/configuration/reloading/
src/java/org/apache/common...
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestWebdavConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestWebdavConfigurationBuilder.java?rev=823891&r1=823890&r2=823891&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestWebdavConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestWebdavConfigurationBuilder.java Sat Oct 10 17:17:44 2009
@@ -21,7 +21,6 @@
import java.io.Reader;
import java.io.FileReader;
import java.io.Writer;
-import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.util.Collection;
import java.util.HashMap;
@@ -32,7 +31,6 @@
import org.apache.commons.configuration.beanutils.BeanHelper;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
-import org.apache.commons.configuration.reloading.VFSFileMonitorReloadingStrategy;
import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.configuration.event.ConfigurationEvent;
@@ -42,7 +40,6 @@
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileSystemOptions;
-import org.apache.commons.vfs.FileContent;
/**
* Test class for DefaultConfigurationBuilder.
@@ -93,13 +90,13 @@
private static final String MULTI_TENENT_FILE =
"testMultiTenentConfigurationBuilder.xml";
- private static final String FILEMONITOR2_FILE =
- "testFileMonitorConfigurationBuilder2.xml";
+ private static final String FILERELOAD2_FILE =
+ "testFileReloadConfigurationBuilder2.xml";
- private static final String FILEMONITOR_1001_FILE =
+ private static final String FILERELOAD_1001_FILE =
"testwrite/testMultiConfiguration_1001.xml";
- private static final String FILEMONITOR_1002_FILE =
+ private static final String FILERELOAD_1002_FILE =
"testwrite/testMultiConfiguration_1002.xml";
private static final String TEST_PROPERTIES = "test.properties.xml";
@@ -900,16 +897,16 @@
verify("1005", config, 50);
}
- public void testFileMonitor1() throws Exception
+ public void testFileChanged() throws Exception
{
// create a new configuration
File input = new File("target/test-classes/testMultiConfiguration_1001.xml");
- FileObject output = getFile(getBasePath() + FILEMONITOR_1001_FILE);
+ FileObject output = getFile(getBasePath() + FILERELOAD_1001_FILE);
output.delete();
output.getParent().createFolder();
copyFile(input, output);
- factory.setFileName(getBasePath() + FILEMONITOR2_FILE);
+ factory.setFileName(getBasePath() + FILERELOAD2_FILE);
System.getProperties().remove("Id");
CombinedConfiguration config = factory.getConfiguration(true);
@@ -919,7 +916,7 @@
// Allow time for FileMonitor to set up.
Thread.sleep(1000);
- XMLConfiguration x = new XMLConfiguration(getBasePath() + FILEMONITOR_1001_FILE);
+ XMLConfiguration x = new XMLConfiguration(getBasePath() + FILERELOAD_1001_FILE);
x.setProperty("rowsPerPage", "50");
x.save();
// Let FileMonitor detect the change.
@@ -927,17 +924,16 @@
waitForChange();
verify("1001", config, 50);
output.delete();
- VFSFileMonitorReloadingStrategy.stopMonitor();
}
- public void testFileMonitor2() throws Exception
+ public void testFileChanged2() throws Exception
{
// create a new configuration
File input = new File("target/test-classes/testMultiConfiguration_1002.xml");
- FileObject output = getFile(getBasePath() + FILEMONITOR_1002_FILE);
+ FileObject output = getFile(getBasePath() + FILERELOAD_1002_FILE);
output.delete();
- factory.setFileName(getBasePath() + FILEMONITOR2_FILE);
+ factory.setFileName(getBasePath() + FILERELOAD2_FILE);
System.getProperties().remove("Id");
CombinedConfiguration config = factory.getConfiguration(true);
@@ -955,7 +951,6 @@
waitForChange();
verify("1002", config, 25);
output.delete();
- VFSFileMonitorReloadingStrategy.stopMonitor();
}
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=823891&r1=823890&r2=823891&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java Sat Oct 10 17:17:44 2009
@@ -639,6 +639,39 @@
}
}
+ public void testReloadingOOM() throws Exception
+ {
+ assertNotNull(conf.getReloadingStrategy());
+ assertTrue(conf.getReloadingStrategy() instanceof InvariantReloadingStrategy);
+ PrintWriter out = null;
+
+ try
+ {
+ out = new PrintWriter(new FileWriter(testSaveConf));
+ out.println("<?xml version=\"1.0\"?><config><test>1</test></config>");
+ out.close();
+ out = null;
+ conf.setFile(testSaveConf);
+ FileAlwaysReloadingStrategy strategy = new FileAlwaysReloadingStrategy();
+ strategy.setRefreshDelay(100);
+ conf.setReloadingStrategy(strategy);
+ conf.load();
+ assertEquals(1, conf.getInt("test"));
+
+ for (int i = 1; i < 50000; ++i)
+ {
+ assertEquals(1, conf.getInt("test"));
+ }
+ }
+ finally
+ {
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ }
+
/**
* Tests access to tag names with delimiter characters.
*/
@@ -1597,6 +1630,50 @@
}
}
+ public void testConcurrentGetAndReload() throws Exception
+ {
+ //final FileConfiguration config = new PropertiesConfiguration("test.properties");
+ final FileConfiguration config = new XMLConfiguration("test.xml");
+ config.setReloadingStrategy(new FileAlwaysReloadingStrategy());
+
+ assertTrue("Property not found", config.getProperty("test.short") != null);
+
+ Thread testThreads[] = new Thread[5];
+
+ for (int i = 0; i < testThreads.length; ++i)
+ {
+ testThreads[i] = new ReloadThread(config);
+ testThreads[i].start();
+ }
+
+ for (int i = 0; i < 2000; i++)
+ {
+ assertTrue("Property not found", config.getProperty("test.short") != null);
+ }
+
+ for (int i = 0; i < testThreads.length; ++i)
+ {
+ testThreads[i].join();
+ }
+ }
+
+ private class ReloadThread extends Thread
+ {
+ FileConfiguration config;
+
+ ReloadThread(FileConfiguration config)
+ {
+ this.config = config;
+ }
+ public void run()
+ {
+ for (int i = 0; i < 1000; i++)
+ {
+ config.reload();
+ }
+ }
+ }
+
/**
* Prepares a configuration object for testing a reload operation.
*
Copied: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java (from r822131, commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java?p2=commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java&p1=commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java&r1=822131&r2=823891&rev=823891&view=diff
==============================================================================
--- commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/FileRandomReloadingStrategy.java Sat Oct 10 17:17:44 2009
@@ -1,3 +1,19 @@
+/*
+ * 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 org.apache.commons.logging.Log;
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=823891&r1=823890&r2=823891&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 Sat Oct 10 17:17:44 2009
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileWriter;
+import java.io.ByteArrayOutputStream;
import java.net.URL;
import junit.framework.TestCase;
@@ -26,6 +27,12 @@
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Layout;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.Appender;
+import org.apache.log4j.WriterAppender;
+import org.apache.log4j.Level;
/**
* Test case for the ReloadableConfiguration class.
@@ -163,4 +170,46 @@
strategy.reloadingPerformed();
assertFalse("Reloading still required", strategy.reloadingRequired());
}
+
+ public void testFileDeletion() throws Exception
+ {
+ Logger logger = Logger.getLogger(FileChangedReloadingStrategy.class.getName());
+ Layout layout = new PatternLayout("%p - %m%n");
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ Appender appender = new WriterAppender(layout, os);
+ logger.addAppender(appender);
+ logger.setLevel(Level.WARN);
+ logger.setAdditivity(false);
+ // 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);
+
+ // Delete the file.
+ file.delete();
+ //Old value should still be returned.
+ assertEquals("Initial value", "value1", config.getString("string"));
+ logger.removeAppender(appender);
+ String str = os.toString();
+ //System.out.println(str);
+ assertTrue("No error was logged", str != null && str.length() > 0);
+ }
}
Copied: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java (from r822131, commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java?p2=commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java&p1=commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java&r1=822131&r2=823891&rev=823891&view=diff
==============================================================================
--- commons/proper/configuration/branches/CONFIGURATION_390/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/reloading/TestVFSFileChangedReloadingStrategy.java Sat Oct 10 17:17:44 2009
@@ -19,18 +19,13 @@
import java.io.File;
import java.io.FileWriter;
-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;
import org.apache.commons.configuration.FileSystem;
import org.apache.commons.configuration.VFSFileSystem;
-import org.apache.commons.configuration.AbstractFileConfiguration;
-import org.apache.commons.configuration.event.ConfigurationEvent;
-import org.apache.commons.configuration.event.ConfigurationListener;
/**
* Test case for the VFSFileMonitorReloadingStrategy class.
Propchange: commons/proper/configuration/trunk/xdocs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 10 17:17:44 2009
@@ -1 +1,2 @@
+/commons/proper/configuration/branches/CONFIGURATION_390/xdocs:819412-822131
/commons/proper/configuration/branches/configuration2_experimental/xdocs:757105-757112
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=823891&r1=823890&r2=823891&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sat Oct 10 17:17:44 2009
@@ -23,6 +23,13 @@
<body>
<release version="1.7" date="in SVN" description="">
+ <action dev="rgoers" type="fix" issue="CONFIGURATION-397">
+ Schema violation exceptions are now propagated back to the caller.
+ </action>
+ <action dev="rgoers" type="fix" issue="CONFIGURATION-390">
+ XMLConfiguration and CombinedConfiguraton are now synchronized to fix problems
+ caused by reloading in a multithreaded environment.
+ </action>
<action dev="oheger" type="fix" issue="CONFIGURATION-396">
HierarchicalConfiguration.NodeVisitor is now passed the correct key to
its visitAfterChildren() method.
Modified: commons/proper/configuration/trunk/xdocs/userguide/howto_filesystems.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/userguide/howto_filesystems.xml?rev=823891&r1=823890&r2=823891&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/userguide/howto_filesystems.xml (original)
+++ commons/proper/configuration/trunk/xdocs/userguide/howto_filesystems.xml Sat Oct 10 17:17:44 2009
@@ -77,7 +77,7 @@
</xml>
</override>
</configuration>
-]]></source>
+]]></source>
</subsection>
<subsection name="File Options Provider">
<p>
@@ -95,15 +95,11 @@
</subsection>
<subsection name="File Reloading Strategy">
<p>
- The <code><a href="../apidocs/org/apache/commons/configuration/reloading/VFSFileMonitorReloadingStrategy.html">VFSFileMonitorReloadingStrategy</a></code>
+ The <code><a href="../apidocs/org/apache/commons/configuration/reloading/VFSFileChangedReloadingStrategy.html">VFSFileChangedReloadingStrategy</a></code>
can be used to cause Configurations accessed via the <code>VFSFileSystem</code> to be
monitored and reloaded when the files are modified. The example below shows how
<code>DefaultConfigurationBuilder</code> can be configured to use
- <code>VFSFileMonitorReloadingStrategy</code>. While each declaration will result in
- a new reloading strategy object, each instance will share a common <code>FileMonitor</code>.
- The delay setting controls how often the <code>FileMonitor</code> checks for changes
- and since there is only a single <code>FileMonitor</code>, only the largest value
- specified on any <code>VFSFileMonitorReloadingStrategy</code> is used.
+ <code>VFSFilChangedReloadingStrategy</code>.
In the example below both test.properties and settings.xml would be checked for changes
once per minute.
</p>
@@ -117,12 +113,12 @@
</header>
<override>
<properties fileName="test.properties" throwExceptionOnMissing="true">
- <reloadingStrategy delay="60000"
- config-class="org.apache.commons.configuration.reloading.VFSFileMonitorReloadingStrategy"/>
+ <reloadingStrategy refreshDelay="60000"
+ config-class="org.apache.commons.configuration.reloading.VFSFileChangedReloadingStrategy"/>
</properties>
<xml fileName="settings.xml" config-name="xml">
- <reloadingStrategy
- config-class="org.apache.commons.configuration.reloading.VFSFileMonitorReloadingStrategy"/>
+ <reloadingStrategy refreshDelay="60000"
+ config-class="org.apache.commons.configuration.reloading.VFSFileChangedReloadingStrategy"/>
</xml>
</override>
</configuration>
Modified: commons/proper/configuration/trunk/xdocs/userguide/howto_multitenant.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/userguide/howto_multitenant.xml?rev=823891&r1=823890&r2=823891&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/userguide/howto_multitenant.xml (original)
+++ commons/proper/configuration/trunk/xdocs/userguide/howto_multitenant.xml Sat Oct 10 17:17:44 2009
@@ -54,6 +54,14 @@
ReloadingStrategy and listeners will be propogated to each of the
created configurations.
</p>
+ <p>
+ When used in a combined configuration it is often acceptable for a file
+ matching a particular pattern to be missing so, by default, most exceptions
+ encountered when loading files are ignored. To change this behavior
+ call setIgnoreException(false) or configure the attribute to false in
+ DefaultConfigurationBuilder's configuration file. If schema validation
+ is enabled validation exceptions will always cause a failure.
+ </p>
</subsection>
<subsection name="DynamicCombinedConfiguration">
<p>