001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.mapreduce; 020 021import static org.junit.Assert.assertTrue; 022import static org.junit.Assume.assumeTrue; 023 024import org.apache.hadoop.conf.Configurable; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.hbase.HBaseConfiguration; 027import org.apache.hadoop.hbase.IntegrationTestingUtility; 028import org.apache.hadoop.hbase.testclassification.IntegrationTests; 029import org.apache.hadoop.mapreduce.Job; 030import org.apache.hadoop.util.Tool; 031import org.apache.hadoop.util.ToolRunner; 032import org.junit.Before; 033import org.junit.BeforeClass; 034import org.junit.Test; 035import org.junit.experimental.categories.Category; 036 037/** 038 * Test that we add tmpjars correctly including the named dependencies. Runs 039 * as an integration test so that classpath is realistic. 040 */ 041@Category(IntegrationTests.class) 042public class IntegrationTestTableMapReduceUtil implements Configurable, Tool { 043 044 private static IntegrationTestingUtility util; 045 046 @BeforeClass 047 public static void provisionCluster() throws Exception { 048 if (null == util) { 049 util = new IntegrationTestingUtility(); 050 } 051 } 052 053 @Before 054 public void skipMiniCluster() { 055 // test probably also works with a local cluster, but 056 // IntegrationTestingUtility doesn't support this concept. 057 assumeTrue("test requires a distributed cluster.", util.isDistributedCluster()); 058 } 059 060 /** 061 * Look for jars we expect to be on the classpath by name. 062 */ 063 @Test 064 public void testAddDependencyJars() throws Exception { 065 Job job = new Job(); 066 TableMapReduceUtil.addDependencyJars(job); 067 String tmpjars = job.getConfiguration().get("tmpjars"); 068 069 // verify presence of modules 070 assertTrue(tmpjars.contains("hbase-common")); 071 assertTrue(tmpjars.contains("hbase-protocol")); 072 assertTrue(tmpjars.contains("hbase-client")); 073 assertTrue(tmpjars.contains("hbase-hadoop-compat")); 074 assertTrue(tmpjars.contains("hbase-server")); 075 076 // verify presence of 3rd party dependencies. 077 assertTrue(tmpjars.contains("zookeeper")); 078 assertTrue(tmpjars.contains("netty")); 079 assertTrue(tmpjars.contains("protobuf")); 080 assertTrue(tmpjars.contains("guava")); 081 assertTrue(tmpjars.contains("htrace")); 082 } 083 084 @Override 085 public int run(String[] args) throws Exception { 086 provisionCluster(); 087 skipMiniCluster(); 088 testAddDependencyJars(); 089 return 0; 090 } 091 092 public void setConf(Configuration conf) { 093 if (util != null) { 094 throw new IllegalArgumentException( 095 "setConf not supported after the test has been initialized."); 096 } 097 util = new IntegrationTestingUtility(conf); 098 } 099 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}