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