View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.mapreduce;
20  
21  import static org.junit.Assert.assertTrue;
22  import static org.junit.Assume.assumeTrue;
23  
24  import org.apache.hadoop.conf.Configurable;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.HBaseConfiguration;
27  import org.apache.hadoop.hbase.IntegrationTestingUtility;
28  import org.apache.hadoop.hbase.testclassification.IntegrationTests;
29  import org.apache.hadoop.mapreduce.Job;
30  import org.apache.hadoop.util.Tool;
31  import org.apache.hadoop.util.ToolRunner;
32  import org.junit.Before;
33  import org.junit.BeforeClass;
34  import org.junit.Test;
35  import org.junit.experimental.categories.Category;
36  
37  /**
38   * Test that we add tmpjars correctly including the named dependencies. Runs
39   * as an integration test so that classpath is realistic.
40   */
41  @Category(IntegrationTests.class)
42  public class IntegrationTestTableMapReduceUtil implements Configurable, Tool {
43  
44    private static IntegrationTestingUtility util;
45  
46    @BeforeClass
47    public static void provisionCluster() throws Exception {
48      if (null == util) {
49        util = new IntegrationTestingUtility();
50      }
51    }
52  
53    @Before
54    public void skipMiniCluster() {
55      // test probably also works with a local cluster, but
56      // IntegrationTestingUtility doesn't support this concept.
57      assumeTrue("test requires a distributed cluster.", util.isDistributedCluster());
58    }
59  
60    /**
61     * Look for jars we expect to be on the classpath by name.
62     */
63    @Test
64    public void testAddDependencyJars() throws Exception {
65      Job job = new Job();
66      TableMapReduceUtil.addDependencyJars(job);
67      String tmpjars = job.getConfiguration().get("tmpjars");
68  
69      // verify presence of modules
70      assertTrue(tmpjars.contains("hbase-common"));
71      assertTrue(tmpjars.contains("hbase-protocol"));
72      assertTrue(tmpjars.contains("hbase-client"));
73      assertTrue(tmpjars.contains("hbase-hadoop-compat"));
74      assertTrue(tmpjars.contains("hbase-server"));
75  
76      // verify presence of 3rd party dependencies.
77      assertTrue(tmpjars.contains("zookeeper"));
78      assertTrue(tmpjars.contains("netty"));
79      assertTrue(tmpjars.contains("protobuf"));
80      assertTrue(tmpjars.contains("guava"));
81      assertTrue(tmpjars.contains("htrace"));
82    }
83  
84    @Override
85    public int run(String[] args) throws Exception {
86      provisionCluster();
87      skipMiniCluster();
88      testAddDependencyJars();
89      return 0;
90    }
91  
92    public void setConf(Configuration conf) {
93      if (util != null) {
94        throw new IllegalArgumentException(
95            "setConf not supported after the test has been initialized.");
96      }
97      util = new IntegrationTestingUtility(conf);
98    }
99  
100   @Override
101   public Configuration getConf() {
102     return util.getConfiguration();
103   }
104 
105   public static void main(String[] args) throws Exception {
106     Configuration conf = HBaseConfiguration.create();
107     IntegrationTestingUtility.setUseDistributedCluster(conf);
108     int status = ToolRunner.run(conf, new IntegrationTestTableMapReduceUtil(), args);
109     System.exit(status);
110   }
111 }