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