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.client.rsgroup; 019 020import java.io.IOException; 021import java.util.ArrayList; 022import java.util.List; 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.HBaseTestingUtility; 025import org.apache.hadoop.hbase.HConstants; 026import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; 027import org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint; 028import org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer; 029import org.apache.hadoop.hbase.security.access.SecureTestUtil; 030import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; 031import org.apache.hadoop.hbase.testclassification.ClientTests; 032import org.apache.hadoop.hbase.testclassification.LargeTests; 033import org.jruby.embed.PathType; 034import org.jruby.embed.ScriptingContainer; 035import org.junit.AfterClass; 036import org.junit.BeforeClass; 037import org.junit.ClassRule; 038import org.junit.Test; 039import org.junit.experimental.categories.Category; 040import org.slf4j.Logger; 041import org.slf4j.LoggerFactory; 042 043//Separate Shell test class for Groups 044//Since we need to use a different balancer and run more than 1 RS 045@Category({ClientTests.class, LargeTests.class}) 046public class TestShellRSGroups { 047 048 @ClassRule 049 public static final HBaseClassTestRule CLASS_RULE = 050 HBaseClassTestRule.forClass(TestShellRSGroups.class); 051 052 final Logger LOG = LoggerFactory.getLogger(getClass()); 053 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 054 private final static ScriptingContainer jruby = new ScriptingContainer(); 055 private static String basePath; 056 057 @BeforeClass 058 public static void setUpBeforeClass() throws Exception { 059 basePath = System.getProperty("basedir"); 060 061 // Start mini cluster 062 TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100); 063 TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250); 064 TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); 065 TEST_UTIL.getConfiguration().setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); 066 TEST_UTIL.getConfiguration().setInt("hfile.format.version", 3); 067 // Security setup configuration 068 SecureTestUtil.enableSecurity(TEST_UTIL.getConfiguration()); 069 VisibilityTestUtil.enableVisiblityLabels(TEST_UTIL.getConfiguration()); 070 071 //Setup RegionServer Groups 072 TEST_UTIL.getConfiguration().set( 073 HConstants.HBASE_MASTER_LOADBALANCER_CLASS, 074 RSGroupBasedLoadBalancer.class.getName()); 075 TEST_UTIL.getConfiguration().set( 076 CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, 077 RSGroupAdminEndpoint.class.getName()); 078 079 TEST_UTIL.startMiniCluster(1,4); 080 081 // Configure jruby runtime 082 List<String> loadPaths = new ArrayList<>(2); 083 loadPaths.add(basePath+"/src/main/ruby"); 084 loadPaths.add(basePath+"/src/test/ruby"); 085 jruby.setLoadPaths(loadPaths); 086 jruby.put("$TEST_CLUSTER", TEST_UTIL); 087 System.setProperty("jruby.jit.logging.verbose", "true"); 088 System.setProperty("jruby.jit.logging", "true"); 089 System.setProperty("jruby.native.verbose", "true"); 090 } 091 092 @AfterClass 093 public static void tearDownAfterClass() throws Exception { 094 TEST_UTIL.shutdownMiniCluster(); 095 } 096 097 @Test 098 public void testRunShellTests() throws IOException { 099 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}