HBASE-5348 Constraint configuration loaded with bloat

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1241704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-02-07 23:49:37 +00:00
parent 802d7c8674
commit 38d28bccc6
3 changed files with 12 additions and 4 deletions

View File

@ -365,7 +365,7 @@ public final class Constraints {
private static Configuration readConfiguration(byte[] bytes) private static Configuration readConfiguration(byte[] bytes)
throws IOException { throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(bytes); ByteArrayInputStream is = new ByteArrayInputStream(bytes);
Configuration conf = new Configuration(); Configuration conf = new Configuration(false);
conf.addResource(is); conf.addResource(is);
return conf; return conf;
} }

View File

@ -29,7 +29,7 @@ public class CheckConfigurationConstraint extends BaseConstraint {
private static String value = "testValue"; private static String value = "testValue";
public static Configuration getConfiguration() { public static Configuration getConfiguration() {
Configuration conf = new Configuration(); Configuration conf = new Configuration(false);
conf.set(key, value); conf.set(key, value);
return conf; return conf;
} }
@ -47,6 +47,13 @@ public class CheckConfigurationConstraint extends BaseConstraint {
if (val == null || !val.equals(value)) if (val == null || !val.equals(value))
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Configuration was not passed correctly"); "Configuration was not passed correctly");
// and then check to make sure we got a fresh config by checking for a
// hadoop-based config value, and if we don't find it, its fine
if (conf.getRaw("fs.file.impl") != null)
throw new IllegalArgumentException(
"Configuration was created using 'new Configuration()', should be "
+ "done via 'new Configuration(false) to exclude defaut hadoop "
+ "configurations values.");
} }
} }

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.constraint;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List; import java.util.List;
@ -82,11 +83,11 @@ public class TestConstraints {
// check to make sure that we overwrite configurations // check to make sure that we overwrite configurations
Constraints.add(desc, new Pair<Class<? extends Constraint>, Configuration>( Constraints.add(desc, new Pair<Class<? extends Constraint>, Configuration>(
CheckConfigurationConstraint.class, new Configuration())); CheckConfigurationConstraint.class, new Configuration(false)));
try { try {
Constraints.getConstraints(desc, this.getClass().getClassLoader()); Constraints.getConstraints(desc, this.getClass().getClassLoader());
assertTrue("No exception thrown - configuration not overwritten", false); fail("No exception thrown - configuration not overwritten");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// expect to have the exception, so don't do anything // expect to have the exception, so don't do anything
} }