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