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