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.procedure;
019
020import static org.junit.Assert.assertArrayEquals;
021
022import java.io.IOException;
023import java.util.HashMap;
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.HBaseTestingUtility;
027import org.apache.hadoop.hbase.client.Admin;
028import org.apache.hadoop.hbase.testclassification.MasterTests;
029import org.apache.hadoop.hbase.testclassification.MediumTests;
030import org.junit.AfterClass;
031import org.junit.BeforeClass;
032import org.junit.ClassRule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035
036@Category({ MasterTests.class, MediumTests.class })
037public class TestProcedureManager {
038
039  @ClassRule
040  public static final HBaseClassTestRule CLASS_RULE =
041    HBaseClassTestRule.forClass(TestProcedureManager.class);
042
043  private static final int NUM_RS = 2;
044  private static HBaseTestingUtility util = new HBaseTestingUtility();
045
046  @BeforeClass
047  public static void setupBeforeClass() throws Exception {
048    // set configure to indicate which pm should be loaded
049    Configuration conf = util.getConfiguration();
050
051    conf.set(ProcedureManagerHost.MASTER_PROCEDURE_CONF_KEY,
052      SimpleMasterProcedureManager.class.getName());
053    conf.set(ProcedureManagerHost.REGIONSERVER_PROCEDURE_CONF_KEY,
054      SimpleRSProcedureManager.class.getName());
055
056    util.startMiniCluster(NUM_RS);
057  }
058
059  @AfterClass
060  public static void tearDownAfterClass() throws Exception {
061    util.shutdownMiniCluster();
062  }
063
064  @Test
065  public void testSimpleProcedureManager() throws IOException {
066    Admin admin = util.getAdmin();
067
068    byte[] result = admin.execProcedureWithRet(SimpleMasterProcedureManager.SIMPLE_SIGNATURE,
069      "mytest", new HashMap<>());
070    assertArrayEquals("Incorrect return data from execProcedure",
071      SimpleMasterProcedureManager.SIMPLE_DATA.getBytes(), result);
072  }
073}