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