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.HBaseTestingUtil;
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.slf4j.Logger;
032import org.slf4j.LoggerFactory;
033
034public interface RubyShellTest {
035  static Logger LOG = LoggerFactory.getLogger(RubyShellTest.class);
036
037  HBaseTestingUtil getTEST_UTIL();
038
039  ScriptingContainer getJRuby();
040
041  /** Returns comma separated list of ruby script names for tests */
042  default String getIncludeList() {
043    return "";
044  }
045
046  /** Returns comma separated list of ruby script names for tests to skip */
047  default String getExcludeList() {
048    return "";
049  }
050
051  String getSuitePattern();
052
053  static void setUpConfig(RubyShellTest test) throws IOException {
054    Configuration conf = test.getTEST_UTIL().getConfiguration();
055    conf.setInt("hbase.regionserver.msginterval", 100);
056    conf.setInt("hbase.client.pause", 250);
057    conf.setBoolean("hbase.quota.enabled", true);
058    conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
059    conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false);
060    conf.setInt("hfile.format.version", 3);
061
062    // Below settings are necessary for task monitor test.
063    conf.setInt(HConstants.MASTER_INFO_PORT, 0);
064    conf.setInt(HConstants.REGIONSERVER_INFO_PORT, 0);
065    conf.setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, true);
066    // Security setup configuration
067    SecureTestUtil.enableSecurity(conf);
068    VisibilityTestUtil.enableVisiblityLabels(conf);
069  }
070
071  static void setUpJRubyRuntime(RubyShellTest test) {
072    LOG.debug("Configure jruby runtime, cluster set to {}", test.getTEST_UTIL());
073    List<String> loadPaths = new ArrayList<>(2);
074    loadPaths.add("src/test/ruby");
075    test.getJRuby().setLoadPaths(loadPaths);
076    test.getJRuby().put("$TEST_CLUSTER", test.getTEST_UTIL());
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  static void doTestSetup(RubyShellTest test) {
083    System.setProperty("shell.test.suite_name", test.getClass().getSimpleName());
084    System.setProperty("shell.test.suite_pattern", test.getSuitePattern());
085    if (!test.getIncludeList().isEmpty()) {
086      System.setProperty("shell.test.include", test.getIncludeList());
087    }
088    if (!test.getExcludeList().isEmpty()) {
089      System.setProperty("shell.test.exclude", test.getExcludeList());
090    }
091    LOG.info("Starting ruby tests on script: {} includes: {} excludes: {}",
092      test.getClass().getSimpleName(), test.getIncludeList(), test.getExcludeList());
093  }
094
095  static void testRunShellTests(RubyShellTest test) throws IOException {
096    test.getJRuby().runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb");
097  }
098}