View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.procedure;
19  
20  import static org.junit.Assert.assertArrayEquals;
21  
22  import java.io.IOException;
23  import java.util.HashMap;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.hbase.HBaseTestingUtility;
29  import org.apache.hadoop.hbase.testclassification.SmallTests;
30  import org.apache.hadoop.hbase.client.Admin;
31  import org.junit.AfterClass;
32  import org.junit.BeforeClass;
33  import org.junit.Test;
34  import org.junit.experimental.categories.Category;
35  
36  @Category(SmallTests.class)
37  public class TestProcedureManager {
38  
39    static final Log LOG = LogFactory.getLog(TestProcedureManager.class);
40    private static final int NUM_RS = 2;
41    private static HBaseTestingUtility util = new HBaseTestingUtility();
42  
43    @BeforeClass
44    public static void setupBeforeClass() throws Exception {
45      // set configure to indicate which pm should be loaded
46      Configuration conf = util.getConfiguration();
47  
48      conf.set(ProcedureManagerHost.MASTER_PROCEUDRE_CONF_KEY,
49          SimpleMasterProcedureManager.class.getName());
50      conf.set(ProcedureManagerHost.REGIONSERVER_PROCEDURE_CONF_KEY,
51          SimpleRSProcedureManager.class.getName());
52  
53      util.startMiniCluster(NUM_RS);
54    }
55  
56    @AfterClass
57    public static void tearDownAfterClass() throws Exception {
58      util.shutdownMiniCluster();
59    }
60  
61    @Test
62    public void testSimpleProcedureManager() throws IOException {
63      Admin admin = util.getHBaseAdmin();
64  
65      byte[] result = admin.execProcedureWithRet(SimpleMasterProcedureManager.SIMPLE_SIGNATURE,
66          "mytest", new HashMap<String, String>());
67      assertArrayEquals("Incorrect return data from execProcedure",
68        SimpleMasterProcedureManager.SIMPLE_DATA.getBytes(), result);
69    }
70  }