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; 019 020import java.io.IOException; 021import java.util.ArrayList; 022import java.util.Collections; 023import java.util.List; 024import java.util.Map; 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.hbase.HBaseTestingUtility; 027import org.apache.hadoop.hbase.HConstants; 028import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; 029import org.apache.hadoop.hbase.security.access.SecureTestUtil; 030import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; 031import org.jruby.embed.PathType; 032import org.jruby.embed.ScriptingContainer; 033import org.junit.AfterClass; 034import org.junit.BeforeClass; 035import org.junit.Test; 036import org.slf4j.Logger; 037import org.slf4j.LoggerFactory; 038 039public abstract class AbstractTestShell { 040 041 private static final Logger LOG = LoggerFactory.getLogger(AbstractTestShell.class); 042 043 protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 044 protected final static ScriptingContainer jruby = new ScriptingContainer(); 045 046 protected static void setUpConfig() throws IOException { 047 Configuration conf = TEST_UTIL.getConfiguration(); 048 conf.setInt("hbase.regionserver.msginterval", 100); 049 conf.setInt("hbase.client.pause", 250); 050 conf.setBoolean("hbase.quota.enabled", true); 051 conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); 052 conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); 053 conf.setInt("hfile.format.version", 3); 054 055 // Below settings are necessary for task monitor test. 056 conf.setInt(HConstants.MASTER_INFO_PORT, 0); 057 conf.setInt(HConstants.REGIONSERVER_INFO_PORT, 0); 058 conf.setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, true); 059 // Security setup configuration 060 SecureTestUtil.enableSecurity(conf); 061 VisibilityTestUtil.enableVisiblityLabels(conf); 062 } 063 064 protected static void setUpJRubyRuntime() { 065 setUpJRubyRuntime(Collections.emptyMap()); 066 } 067 068 protected static void setUpJRubyRuntime(Map<String, Object> extraVars) { 069 LOG.debug("Configure jruby runtime, cluster set to {}", TEST_UTIL); 070 List<String> loadPaths = new ArrayList<>(2); 071 loadPaths.add("src/test/ruby"); 072 jruby.setLoadPaths(loadPaths); 073 jruby.put("$TEST_CLUSTER", TEST_UTIL); 074 for (Map.Entry<String, Object> entry : extraVars.entrySet()) { 075 jruby.put(entry.getKey(), entry.getValue()); 076 } 077 System.setProperty("jruby.jit.logging.verbose", "true"); 078 System.setProperty("jruby.jit.logging", "true"); 079 System.setProperty("jruby.native.verbose", "true"); 080 } 081 082 /** Returns comma separated list of ruby script names for tests */ 083 protected String getIncludeList() { 084 return ""; 085 } 086 087 /** Returns comma separated list of ruby script names for tests to skip */ 088 protected String getExcludeList() { 089 return ""; 090 } 091 092 @Test 093 public void testRunShellTests() throws IOException { 094 final String tests = getIncludeList(); 095 final String excludes = getExcludeList(); 096 if (!tests.isEmpty()) { 097 System.setProperty("shell.test.include", tests); 098 } 099 if (!excludes.isEmpty()) { 100 System.setProperty("shell.test.exclude", excludes); 101 } 102 LOG.info("Starting ruby tests. includes: {} excludes: {}", tests, excludes); 103 jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); 104 } 105 106 @BeforeClass 107 public static void setUpBeforeClass() throws Exception { 108 setUpConfig(); 109 110 // Start mini cluster 111 TEST_UTIL.startMiniCluster(1); 112 113 setUpJRubyRuntime(); 114 } 115 116 @AfterClass 117 public static void tearDownAfterClass() throws Exception { 118 TEST_UTIL.shutdownMiniCluster(); 119 } 120}