Author: cdouglas
Date: Thu Mar 26 10:50:55 2009
New Revision: 758593
URL: http://svn.apache.org/viewvc?rev=758593&view=rev
Log:
HADOOP-4365. Make Configuration::getProps protected in support of
meaningful subclassing. Contributed by Steve Loughran
Added:
hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java
hadoop/core/trunk/src/test/org/apache/hadoop/conf/empty-configuration.xml
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/core/org/apache/hadoop/conf/Configuration.java
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=758593&r1=758592&r2=758593&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Mar 26 10:50:55 2009
@@ -192,6 +192,9 @@
HADOOP-5331. Add support for KFS appends. (Sriram Rao via cdouglas)
+ HADOOP-4365. Make Configuration::getProps protected in support of
+ meaningful subclassing. (Steve Loughran via cdouglas)
+
OPTIMIZATIONS
BUG FIXES
Modified: hadoop/core/trunk/src/core/org/apache/hadoop/conf/Configuration.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/conf/Configuration.java?rev=758593&r1=758592&r2=758593&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/conf/Configuration.java
(original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/conf/Configuration.java Thu
Mar 26 10:50:55 2009
@@ -973,7 +973,7 @@
}
}
- private synchronized Properties getProps() {
+ protected synchronized Properties getProps() {
if (properties == null) {
properties = new Properties();
loadResources(properties, resources, quietmode);
Added:
hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java?rev=758593&view=auto
==============================================================================
---
hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java
(added)
+++
hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java
Thu Mar 26 10:50:55 2009
@@ -0,0 +1,102 @@
+/**
+ * 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.hadoop.conf;
+
+import junit.framework.TestCase;
+
+import java.util.Properties;
+
+/**
+ * Created 21-Jan-2009 13:42:36
+ */
+
+public class TestConfigurationSubclass extends TestCase {
+ private static final String EMPTY_CONFIGURATION_XML
+ = "/org/apache/hadoop/conf/empty-configuration.xml";
+
+
+ public void testGetProps() {
+ SubConf conf = new SubConf(true);
+ Properties properties = conf.getProperties();
+ assertNotNull("hadoop.tmp.dir is not set",
+ properties.getProperty("hadoop.tmp.dir"));
+ }
+
+ public void testReload() throws Throwable {
+ SubConf conf = new SubConf(true);
+ assertFalse(conf.isReloaded());
+ Configuration.addDefaultResource(EMPTY_CONFIGURATION_XML);
+ assertTrue(conf.isReloaded());
+ Properties properties = conf.getProperties();
+ }
+
+ public void testReloadNotQuiet() throws Throwable {
+ SubConf conf = new SubConf(true);
+ conf.setQuietMode(false);
+ assertFalse(conf.isReloaded());
+ conf.addResource("not-a-valid-resource");
+ assertTrue(conf.isReloaded());
+ try {
+ Properties properties = conf.getProperties();
+ fail("Should not have got here");
+ } catch (RuntimeException e) {
+ assertTrue(e.toString(),e.getMessage().contains("not found"));
+ }
+ }
+
+ private static class SubConf extends Configuration {
+
+ private boolean reloaded;
+
+ /**
+ * A new configuration where the behavior of reading from the default
resources
+ * can be turned off.
+ *
+ * If the parameter {...@code loadDefaults} is false, the new instance
will not
+ * load resources from the default files.
+ *
+ * @param loadDefaults specifies whether to load from the default files
+ */
+ private SubConf(boolean loadDefaults) {
+ super(loadDefaults);
+ }
+
+ public Properties getProperties() {
+ return super.getProps();
+ }
+
+ /**
+ * {...@inheritdoc}.
+ * Sets the reloaded flag.
+ */
+ @Override
+ public void reloadConfiguration() {
+ super.reloadConfiguration();
+ reloaded = true;
+ }
+
+ public boolean isReloaded() {
+ return reloaded;
+ }
+
+ public void setReloaded(boolean reloaded) {
+ this.reloaded = reloaded;
+ }
+ }
+
+}
Added: hadoop/core/trunk/src/test/org/apache/hadoop/conf/empty-configuration.xml
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/conf/empty-configuration.xml?rev=758593&view=auto
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/conf/empty-configuration.xml
(added)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/conf/empty-configuration.xml
Thu Mar 26 10:50:55 2009
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<configuration>
+</configuration>
+