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 org.apache.hadoop.hbase.HBaseClassTestRule;
021import org.apache.hadoop.hbase.HBaseTestingUtility;
022import org.apache.hadoop.hbase.testclassification.LargeTests;
023import org.apache.hadoop.hbase.testclassification.MapReduceTests;
024import org.junit.ClassRule;
025import org.junit.Test;
026import org.junit.experimental.categories.Category;
027
028import java.io.IOException;
029import java.util.HashMap;
030import java.util.Map;
031
032import static org.junit.Assert.assertFalse;
033import static org.junit.Assert.assertTrue;
034
035@Category({MapReduceTests.class, LargeTests.class})
036public class TestHBaseMRTestingUtility {
037  @ClassRule
038  public static final HBaseClassTestRule CLASS_RULE =
039      HBaseClassTestRule.forClass(TestHBaseMRTestingUtility.class);
040
041  @Test
042  public void testMRYarnConfigsPopulation() throws IOException {
043    Map<String, String> dummyProps = new HashMap<>();
044    dummyProps.put("mapreduce.jobtracker.address", "dummyhost:11234");
045    dummyProps.put("yarn.resourcemanager.address", "dummyhost:11235");
046    dummyProps.put("mapreduce.jobhistory.address", "dummyhost:11236");
047    dummyProps.put("yarn.resourcemanager.scheduler.address", "dummyhost:11237");
048    dummyProps.put("mapreduce.jobhistory.webapp.address", "dummyhost:11238");
049    dummyProps.put("yarn.resourcemanager.webapp.address", "dummyhost:11239");
050
051    HBaseTestingUtility hbt = new HBaseTestingUtility();
052
053    // populate the mr props to the Configuration instance
054    for (Map.Entry<String, String> entry : dummyProps.entrySet()) {
055      hbt.getConfiguration().set(entry.getKey(), entry.getValue());
056    }
057
058    for (Map.Entry<String,String> entry : dummyProps.entrySet()) {
059      assertTrue("The Configuration for key " + entry.getKey() +" and value: " + entry.getValue() +
060          " is not populated correctly", hbt.getConfiguration().get(entry.getKey()).equals(entry.getValue()));
061    }
062
063    hbt.startMiniMapReduceCluster();
064
065    // Confirm that MiniMapReduceCluster overwrites the mr properties and updates the Configuration
066    for (Map.Entry<String,String> entry : dummyProps.entrySet()) {
067      assertFalse("The MR prop: " + entry.getValue() + " is not overwritten when map reduce mini"+
068          "cluster is started", hbt.getConfiguration().get(entry.getKey()).equals(entry.getValue()));
069    }
070
071    hbt.shutdownMiniMapReduceCluster();
072  }
073}