Return-Path: Delivered-To: apmail-hadoop-core-commits-archive@www.apache.org Received: (qmail 28198 invoked from network); 26 Mar 2009 10:51:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Mar 2009 10:51:39 -0000 Received: (qmail 5716 invoked by uid 500); 26 Mar 2009 10:51:39 -0000 Delivered-To: apmail-hadoop-core-commits-archive@hadoop.apache.org Received: (qmail 5680 invoked by uid 500); 26 Mar 2009 10:51:39 -0000 Mailing-List: contact core-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: core-dev@hadoop.apache.org Delivered-To: mailing list core-commits@hadoop.apache.org Received: (qmail 5671 invoked by uid 99); 26 Mar 2009 10:51:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Mar 2009 10:51:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Mar 2009 10:51:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F308C23889F6; Thu, 26 Mar 2009 10:51:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r758593 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/conf/Configuration.java src/test/org/apache/hadoop/conf/TestConfigurationSubclass.java src/test/org/apache/hadoop/conf/empty-configuration.xml Date: Thu, 26 Mar 2009 10:51:11 -0000 To: core-commits@hadoop.apache.org From: cdouglas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090326105114.F308C23889F6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + + +