1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.constraint;
19
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.hbase.client.Put;
22
23 /**
24 * Test Constraint to check to make sure the configuration is set
25 */
26 public class CheckConfigurationConstraint extends BaseConstraint {
27
28 private static String key = "testKey";
29 private static String value = "testValue";
30
31 public static Configuration getConfiguration() {
32 Configuration conf = new Configuration(false);
33 conf.set(key, value);
34 return conf;
35 }
36
37 @Override
38 public void check(Put p) {
39 // NOOP
40 }
41
42 @Override
43 public void setConf(Configuration conf) {
44 super.setConf(conf);
45 if (conf != null) {
46 String val = conf.get(key);
47 if (val == null || !val.equals(value))
48 throw new IllegalArgumentException(
49 "Configuration was not passed correctly");
50 // and then check to make sure we got a fresh config by checking for a
51 // hadoop-based config value, and if we don't find it, its fine
52 if (conf.getRaw("fs.file.impl") != null)
53 throw new IllegalArgumentException(
54 "Configuration was created using 'new Configuration()', should be "
55 + "done via 'new Configuration(false) to exclude defaut hadoop "
56 + "configurations values.");
57 }
58 }
59
60 }