View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.client.rsgroup;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.hadoop.hbase.HBaseTestingUtility;
24  import org.apache.hadoop.hbase.HConstants;
25  import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
26  import org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint;
27  import org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer;
28  import org.apache.hadoop.hbase.security.access.SecureTestUtil;
29  import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil;
30  import org.apache.hadoop.hbase.testclassification.LargeTests;
31  import org.jruby.embed.PathType;
32  import org.jruby.embed.ScriptingContainer;
33  import org.junit.AfterClass;
34  import org.junit.BeforeClass;
35  import org.junit.Test;
36  import org.junit.experimental.categories.Category;
37  
38  import java.io.IOException;
39  import java.util.ArrayList;
40  import java.util.List;
41  
42  //Separate Shell test class for Groups
43  //Since we need to use a different balancer and run more than 1 RS
44  @Category({LargeTests.class})
45  public class TestShellRSGroups {
46    final Log LOG = LogFactory.getLog(getClass());
47    private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
48    private final static ScriptingContainer jruby = new ScriptingContainer();
49    private static String basePath;
50  
51    @BeforeClass
52    public static void setUpBeforeClass() throws Exception {
53      basePath = System.getProperty("basedir");
54  
55      // Start mini cluster
56      TEST_UTIL.getConfiguration().setBoolean("hbase.online.schema.update.enable", true);
57      TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
58      TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
59      TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
60      TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
61      TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3);
62      TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, -1);
63      TEST_UTIL.getConfiguration().setInt(HConstants.REGIONSERVER_INFO_PORT, -1);
64      // Security setup configuration
65      SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration());
66      VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration());
67  
68      //Setup RegionServer Groups
69      TEST_UTIL.getConfiguration().set(
70          HConstants.HBASE_MASTER_LOADBALANCER_CLASS,
71          RSGroupBasedLoadBalancer.class.getName());
72      TEST_UTIL.getConfiguration().set(
73          CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
74          RSGroupAdminEndpoint.class.getName());
75      TEST_UTIL.getConfiguration().setBoolean(
76          HConstants.ZOOKEEPER_USEMULTI,
77          true);
78  
79      TEST_UTIL.startMiniCluster(1,4);
80  
81      // Configure jruby runtime
82      List<String> loadPaths = new ArrayList();
83      loadPaths.add(basePath+"/src/main/ruby");
84      loadPaths.add(basePath+"/src/test/ruby");
85      jruby.getProvider().setLoadPaths(loadPaths);
86      jruby.put("$TEST_CLUSTER", TEST_UTIL);
87      System.setProperty("jruby.jit.logging.verbose", "true");
88      System.setProperty("jruby.jit.logging", "true");
89      System.setProperty("jruby.native.verbose", "true");
90    }
91  
92    @AfterClass
93    public static void tearDownAfterClass() throws Exception {
94      TEST_UTIL.shutdownMiniCluster();
95    }
96  
97    @Test
98    public void testRunShellTests() throws IOException {
99      try {
100       // Start only GroupShellTest
101       System.setProperty("shell.test", "Hbase::RSGroupShellTest");
102       jruby.runScriptlet(PathType.ABSOLUTE,
103           basePath + "/src/test/ruby/tests_runner.rb");
104     } finally {
105       System.clearProperty("shell.test");
106     }
107   }
108 
109 }
110