You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2006/08/31 23:01:06 UTC
svn commit: r439046 - in /lucene/hadoop/trunk: CHANGES.txt
src/java/org/apache/hadoop/conf/Configuration.java
src/test/org/apache/hadoop/conf/TestConfiguration.java
Author: cutting
Date: Thu Aug 31 14:01:05 2006
New Revision: 439046
URL: http://svn.apache.org/viewvc?rev=439046&view=rev
Log:
HADOOP-196. Fix Configuration(Configuration) constructor to work correctly. Contributed by Sami Siren.
Modified:
lucene/hadoop/trunk/CHANGES.txt
lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java
lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java
Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=439046&r1=439045&r2=439046&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Thu Aug 31 14:01:05 2006
@@ -104,6 +104,9 @@
25. HADOOP-460. Fix contrib/smallJobsBenchmark to use Text instead of
UTF8. (Sanjay Dahiya via cutting)
+26. HADOOP-196. Fix Configuration(Configuration) constructor to work
+ correctly. (Sami Siren via cutting)
+
Release 0.5.0 - 2006-08-04
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=439046&r1=439045&r2=439046&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java Thu Aug 31 14:01:05 2006
@@ -75,6 +75,7 @@
private ArrayList finalResources = new ArrayList();
private Properties properties;
+ private Properties overlay;
private ClassLoader classLoader;
{
classLoader = Thread.currentThread().getContextClassLoader();
@@ -102,6 +103,8 @@
this.finalResources = (ArrayList)other.finalResources.clone();
if (other.properties != null)
this.properties = (Properties)other.properties.clone();
+ if(other.overlay!=null)
+ this.overlay = (Properties)other.overlay.clone();
}
/** Add a default resource. */
@@ -197,9 +200,17 @@
/** Sets the value of the <code>name</code> property. */
public void set(String name, Object value) {
+ getOverlay().setProperty(name, value.toString());
getProps().setProperty(name, value.toString());
}
+ private synchronized Properties getOverlay() {
+ if(overlay==null){
+ overlay=new Properties();
+ }
+ return overlay;
+ }
+
/** Returns the value of the <code>name</code> property. If no such property
* exists, then <code>defaultValue</code> is returned.
*/
@@ -446,6 +457,8 @@
loadResources(newProps, defaultResources, false, false);
loadResources(newProps, finalResources, true, true);
properties = newProps;
+ if(overlay!=null)
+ properties.putAll(overlay);
}
return properties;
}
Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java?rev=439046&r1=439045&r2=439046&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java Thu Aug 31 14:01:05 2006
@@ -15,28 +15,49 @@
*/
package org.apache.hadoop.conf;
-import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.JobConf;
import junit.framework.TestCase;
public class TestConfiguration extends TestCase {
-
- public void testVariableSubstitution() throws IOException {
- Configuration conf = new Configuration();
- final String CONFIG = new File("./test-config.xml").getAbsolutePath();
- this.out = new BufferedWriter(new FileWriter(CONFIG));
+
+ private Configuration conf;
+ final static String CONFIG = new File("./test-config.xml").getAbsolutePath();
+ final static String CONFIG2 = new File("./test-config2.xml").getAbsolutePath();
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ conf = new Configuration();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ new File(CONFIG).delete();
+ new File(CONFIG2).delete();
+ }
+
+ private void startConfig() throws IOException{
out.write("<?xml version=\"1.0\"?>\n");
out.write("<configuration>\n");
+ }
+
+ private void endConfig() throws IOException{
+ out.write("</configuration>\n");
+ out.close();
+ }
+
+ public void testVariableSubstitution() throws IOException {
+ out=new BufferedWriter(new FileWriter(CONFIG));
+ startConfig();
declareProperty("my.int", "${intvar}", "42");
declareProperty("intvar", "42", "42");
declareProperty("my.base", "/tmp/${user.name}", UNSPEC);
@@ -46,8 +67,7 @@
declareProperty("my.fullfile", "${my.base}/${my.file}${my.suffix}", UNSPEC);
// check that undefined variables are returned as-is
declareProperty("my.failsexpand", "a${my.undefvar}b", "a${my.undefvar}b");
- out.write("</configuration>\n");
- out.close();
+ endConfig();
Path fileResource = new Path(CONFIG);
conf.addDefaultResource(fileResource);
@@ -70,8 +90,6 @@
// check that expansion also occurs for getInt()
assertTrue(conf.getInt("intvar", -1) == 42);
assertTrue(conf.getInt("my.int", -1) == 42);
-
- new File(CONFIG).delete();
}
public static void assertEq(Object a, Object b) {
@@ -107,6 +125,39 @@
out.write(val);
out.write("</value>");
out.write("</property>\n");
+ }
+
+ public void testOverlay() throws IOException{
+ out=new BufferedWriter(new FileWriter(CONFIG));
+ startConfig();
+ appendProperty("a","b");
+ appendProperty("b","c");
+ appendProperty("d","e");
+ endConfig();
+
+ out=new BufferedWriter(new FileWriter(CONFIG2));
+ startConfig();
+ appendProperty("a","b");
+ appendProperty("b","d");
+ endConfig();
+
+
+
+ Path fileResource = new Path(CONFIG);
+ conf.addDefaultResource(fileResource);
+
+ //set dynamically something
+ conf.set("c","d");
+ conf.set("a","d");
+
+ Configuration clone=new Configuration(conf);
+ clone.addFinalResource(new Path(CONFIG2));
+
+ assertEquals(clone.get("a"), "d");
+ assertEquals(clone.get("b"), "d");
+ assertEquals(clone.get("c"), "d");
+ assertEquals(clone.get("d"), "e");
+
}
BufferedWriter out;