This is an automated email from the ASF dual-hosted git repository. vjasani pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push: new 5b4efe69953 HBASE-29558: Fix for TestShellNoCluster along with code refactoring and cleanup (#7256) 5b4efe69953 is described below commit 5b4efe69953898750e09008634ef4d584649606e Author: Hari Krishna Dara <harid...@gmail.com> AuthorDate: Thu Sep 4 06:32:09 2025 +0530 HBASE-29558: Fix for TestShellNoCluster along with code refactoring and cleanup (#7256) Signed-off-by: Nihal Jain <nihalj...@apache.org> --- .../hadoop/hbase/client/AbstractTestShell.java | 100 ++++++--------------- .../{TestAdminShell.java => BaseTestShell.java} | 21 ++--- .../{AbstractTestShell.java => RubyShellTest.java} | 85 +++++++----------- .../hadoop/hbase/client/TestAdminShell2.java | 37 -------- .../hadoop/hbase/client/TestChangeSftShell.java | 46 ---------- .../hadoop/hbase/client/TestListTablesShell.java | 12 +-- .../hadoop/hbase/client/TestQuotasShell.java | 5 +- .../hadoop/hbase/client/TestRSGroupShell.java | 15 ++-- .../hadoop/hbase/client/TestReplicationShell.java | 5 +- .../org/apache/hadoop/hbase/client/TestShell.java | 8 +- .../hadoop/hbase/client/TestShellNoCluster.java | 41 +++------ .../apache/hadoop/hbase/client/TestTableShell.java | 5 +- .../{admin2_test.rb => admin2_test_cluster.rb} | 0 .../hbase/{admin_test.rb => admin_test_cluster.rb} | 0 ...tils_test.rb => balancer_utils_test_cluster.rb} | 0 ...no_cluster.rb => connection_test_no_cluster.rb} | 0 .../hbase/{hbase_test.rb => hbase_test_cluster.rb} | 0 ...dmin_test.rb => security_admin_test_cluster.rb} | 0 ...monitor_test.rb => taskmonitor_test_cluster.rb} | 0 ....rb => visibility_labels_admin_test_cluster.rb} | 0 .../src/test/ruby/no_cluster_tests_runner.rb | 94 ------------------- .../{commands_test.rb => commands_test_cluster.rb} | 0 ...converter_test.rb => converter_test_cluster.rb} | 0 ...formatter_test.rb => formatter_test_cluster.rb} | 0 .../{shell_test.rb => general_test_cluster.rb} | 0 ...st_locks_test.rb => list_locks_test_cluster.rb} | 0 ...res_test.rb => list_procedures_test_cluster.rb} | 0 ...tive_test.rb => noninteractive_test_cluster.rb} | 0 ...nge_shell_test.rb => sftchange_test_cluster.rb} | 0 hbase-shell/src/test/ruby/tests_runner.rb | 37 ++------ 30 files changed, 101 insertions(+), 410 deletions(-) diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java index 9270715fd8d..806ce92d0d8 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java @@ -18,100 +18,56 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.HBaseTestingUtil; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; -import org.apache.hadoop.hbase.security.access.SecureTestUtil; -import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; -import org.jruby.embed.PathType; import org.jruby.embed.ScriptingContainer; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public abstract class AbstractTestShell { +public abstract class AbstractTestShell implements RubyShellTest { + protected final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); + protected final ScriptingContainer jruby = new ScriptingContainer(); - private static final Logger LOG = LoggerFactory.getLogger(AbstractTestShell.class); - - protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - protected final static ScriptingContainer jruby = new ScriptingContainer(); - - protected static void setUpConfig() throws IOException { - Configuration conf = TEST_UTIL.getConfiguration(); - conf.setInt("hbase.regionserver.msginterval", 100); - conf.setInt("hbase.client.pause", 250); - conf.setBoolean("hbase.quota.enabled", true); - conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6); - conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); - conf.setInt("hfile.format.version", 3); - - // Below settings are necessary for task monitor test. - conf.setInt(HConstants.MASTER_INFO_PORT, 0); - conf.setInt(HConstants.REGIONSERVER_INFO_PORT, 0); - conf.setBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO, true); - // Security setup configuration - SecureTestUtil.enableSecurity(conf); - VisibilityTestUtil.enableVisiblityLabels(conf); - } - - protected static void setUpJRubyRuntime() { - LOG.debug("Configure jruby runtime, cluster set to {}", TEST_UTIL); - List<String> loadPaths = new ArrayList<>(2); - loadPaths.add("src/test/ruby"); - jruby.setLoadPaths(loadPaths); - jruby.put("$TEST_CLUSTER", TEST_UTIL); - System.setProperty("jruby.jit.logging.verbose", "true"); - System.setProperty("jruby.jit.logging", "true"); - System.setProperty("jruby.native.verbose", "true"); + public HBaseTestingUtil getTEST_UTIL() { + return TEST_UTIL; } - /** Returns comma separated list of ruby script names for tests */ - protected String getIncludeList() { - return ""; + public ScriptingContainer getJRuby() { + return jruby; } - /** Returns comma separated list of ruby script names for tests to skip */ - protected String getExcludeList() { - return ""; - } - - @Test - public void testRunShellTests() throws IOException { - final String tests = getIncludeList(); - final String excludes = getExcludeList(); - if (!tests.isEmpty()) { - System.setProperty("shell.test.include", tests); - } - if (!excludes.isEmpty()) { - System.setProperty("shell.test.exclude", excludes); - } - LOG.info("Starting ruby tests. includes: {} excludes: {}", tests, excludes); - jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); + public String getSuitePattern() { + return "**/*_test.rb"; } - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpConfig(); + @Before + public void setUp() throws Exception { + RubyShellTest.setUpConfig(this); // Start mini cluster // 3 datanodes needed for erasure coding checks TEST_UTIL.startMiniCluster(3); + + RubyShellTest.setUpJRubyRuntime(this); + + RubyShellTest.doTestSetup(this); + } + + protected void setupDFS() throws IOException { DistributedFileSystem dfs = (DistributedFileSystem) FileSystem.get(TEST_UTIL.getConfiguration()); dfs.enableErasureCodingPolicy("XOR-2-1-1024k"); - - setUpJRubyRuntime(); } - @AfterClass - public static void tearDownAfterClass() throws Exception { + @After + public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } + + @Test + public void testRunShellTests() throws IOException { + RubyShellTest.testRunShellTests(this); + } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/BaseTestShell.java similarity index 60% rename from hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java rename to hbase-shell/src/test/java/org/apache/hadoop/hbase/client/BaseTestShell.java index 983d43f9ef8..1cfb06b6bee 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/BaseTestShell.java @@ -17,21 +17,12 @@ */ package org.apache.hadoop.hbase.client; -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.testclassification.ClientTests; -import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.Before; -@Category({ ClientTests.class, LargeTests.class }) -public class TestAdminShell extends AbstractTestShell { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestAdminShell.class); - - @Override - protected String getIncludeList() { - return "admin_test.rb"; +public abstract class BaseTestShell extends AbstractTestShell { + @Before + public void setUp() throws Exception { + super.setUp(); + super.setupDFS(); } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/RubyShellTest.java similarity index 58% copy from hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java copy to hbase-shell/src/test/java/org/apache/hadoop/hbase/client/RubyShellTest.java index 9270715fd8d..9009aebe22a 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/AbstractTestShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/RubyShellTest.java @@ -21,30 +21,37 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.security.access.SecureTestUtil; import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; -import org.apache.hadoop.hdfs.DistributedFileSystem; import org.jruby.embed.PathType; import org.jruby.embed.ScriptingContainer; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractTestShell { +public interface RubyShellTest { + static Logger LOG = LoggerFactory.getLogger(RubyShellTest.class); - private static final Logger LOG = LoggerFactory.getLogger(AbstractTestShell.class); + HBaseTestingUtil getTEST_UTIL(); - protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - protected final static ScriptingContainer jruby = new ScriptingContainer(); + ScriptingContainer getJRuby(); - protected static void setUpConfig() throws IOException { - Configuration conf = TEST_UTIL.getConfiguration(); + /** Returns comma separated list of ruby script names for tests */ + default String getIncludeList() { + return ""; + } + + /** Returns comma separated list of ruby script names for tests to skip */ + default String getExcludeList() { + return ""; + } + + String getSuitePattern(); + + static void setUpConfig(RubyShellTest test) throws IOException { + Configuration conf = test.getTEST_UTIL().getConfiguration(); conf.setInt("hbase.regionserver.msginterval", 100); conf.setInt("hbase.client.pause", 250); conf.setBoolean("hbase.quota.enabled", true); @@ -61,57 +68,31 @@ public abstract class AbstractTestShell { VisibilityTestUtil.enableVisiblityLabels(conf); } - protected static void setUpJRubyRuntime() { - LOG.debug("Configure jruby runtime, cluster set to {}", TEST_UTIL); + static void setUpJRubyRuntime(RubyShellTest test) { + LOG.debug("Configure jruby runtime, cluster set to {}", test.getTEST_UTIL()); List<String> loadPaths = new ArrayList<>(2); loadPaths.add("src/test/ruby"); - jruby.setLoadPaths(loadPaths); - jruby.put("$TEST_CLUSTER", TEST_UTIL); + test.getJRuby().setLoadPaths(loadPaths); + test.getJRuby().put("$TEST_CLUSTER", test.getTEST_UTIL()); System.setProperty("jruby.jit.logging.verbose", "true"); System.setProperty("jruby.jit.logging", "true"); System.setProperty("jruby.native.verbose", "true"); } - /** Returns comma separated list of ruby script names for tests */ - protected String getIncludeList() { - return ""; - } - - /** Returns comma separated list of ruby script names for tests to skip */ - protected String getExcludeList() { - return ""; - } - - @Test - public void testRunShellTests() throws IOException { - final String tests = getIncludeList(); - final String excludes = getExcludeList(); - if (!tests.isEmpty()) { - System.setProperty("shell.test.include", tests); + static void doTestSetup(RubyShellTest test) { + System.setProperty("shell.test.suite_name", test.getClass().getSimpleName()); + System.setProperty("shell.test.suite_pattern", test.getSuitePattern()); + if (!test.getIncludeList().isEmpty()) { + System.setProperty("shell.test.include", test.getIncludeList()); } - if (!excludes.isEmpty()) { - System.setProperty("shell.test.exclude", excludes); + if (!test.getExcludeList().isEmpty()) { + System.setProperty("shell.test.exclude", test.getExcludeList()); } - LOG.info("Starting ruby tests. includes: {} excludes: {}", tests, excludes); - jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); - } - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpConfig(); - - // Start mini cluster - // 3 datanodes needed for erasure coding checks - TEST_UTIL.startMiniCluster(3); - DistributedFileSystem dfs = - (DistributedFileSystem) FileSystem.get(TEST_UTIL.getConfiguration()); - dfs.enableErasureCodingPolicy("XOR-2-1-1024k"); - - setUpJRubyRuntime(); + LOG.info("Starting ruby tests on script: {} includes: {} excludes: {}", + test.getClass().getSimpleName(), test.getIncludeList(), test.getExcludeList()); } - @AfterClass - public static void tearDownAfterClass() throws Exception { - TEST_UTIL.shutdownMiniCluster(); + static void testRunShellTests(RubyShellTest test) throws IOException { + test.getJRuby().runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell2.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell2.java deleted file mode 100644 index 0bf67cdc8b4..00000000000 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestAdminShell2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.client; - -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.testclassification.ClientTests; -import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; - -@Category({ ClientTests.class, LargeTests.class }) -public class TestAdminShell2 extends AbstractTestShell { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestAdminShell2.class); - - @Override - protected String getIncludeList() { - return "admin2_test.rb"; - } -} diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestChangeSftShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestChangeSftShell.java deleted file mode 100644 index e8127afcc70..00000000000 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestChangeSftShell.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.client; - -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.testclassification.ClientTests; -import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; - -@Category({ ClientTests.class, LargeTests.class }) -public class TestChangeSftShell extends AbstractTestShell { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestChangeSftShell.class); - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpConfig(); - - TEST_UTIL.startMiniCluster(3); - - setUpJRubyRuntime(); - } - - @Override - protected String getIncludeList() { - return "sftchange_shell_test.rb"; - } -} diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestListTablesShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestListTablesShell.java index b823b6fc3aa..ffd80f91a38 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestListTablesShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestListTablesShell.java @@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.client; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.experimental.categories.Category; @@ -30,17 +29,8 @@ public class TestListTablesShell extends AbstractTestShell { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestListTablesShell.class); - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpConfig(); - - TEST_UTIL.startMiniCluster(3); - - setUpJRubyRuntime(); - } - @Override - protected String getIncludeList() { + public String getIncludeList() { return "list_tables_test.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestQuotasShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestQuotasShell.java index d7b9fab42a3..b4e513daaff 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestQuotasShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestQuotasShell.java @@ -24,14 +24,13 @@ import org.junit.ClassRule; import org.junit.experimental.categories.Category; @Category({ ClientTests.class, LargeTests.class }) -public class TestQuotasShell extends AbstractTestShell { - +public class TestQuotasShell extends BaseTestShell { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestQuotasShell.class); @Override - protected String getIncludeList() { + public String getIncludeList() { return "quotas_test.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestRSGroupShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestRSGroupShell.java index 3570f4ac94a..e15892fd16c 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestRSGroupShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestRSGroupShell.java @@ -21,7 +21,7 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.rsgroup.RSGroupUtil; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.ClassRule; import org.junit.experimental.categories.Category; @@ -32,20 +32,15 @@ public class TestRSGroupShell extends AbstractTestShell { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestRSGroupShell.class); - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpConfig(); - + @Before + public void setUp() throws Exception { // enable rs group RSGroupUtil.enableRSGroup(TEST_UTIL.getConfiguration()); - - TEST_UTIL.startMiniCluster(3); - - setUpJRubyRuntime(); + super.setUp(); } @Override - protected String getIncludeList() { + public String getIncludeList() { return "rsgroup_shell_test.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestReplicationShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestReplicationShell.java index ced1e7adda1..9a9ea1d7e97 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestReplicationShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestReplicationShell.java @@ -24,14 +24,13 @@ import org.junit.ClassRule; import org.junit.experimental.categories.Category; @Category({ ClientTests.class, LargeTests.class }) -public class TestReplicationShell extends AbstractTestShell { - +public class TestReplicationShell extends BaseTestShell { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestReplicationShell.class); @Override - protected String getIncludeList() { + public String getIncludeList() { return "replication_admin_test.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java index 47918f68019..999681a0ca2 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java @@ -24,14 +24,12 @@ import org.junit.ClassRule; import org.junit.experimental.categories.Category; @Category({ ClientTests.class, LargeTests.class }) -public class TestShell extends AbstractTestShell { - +public class TestShell extends BaseTestShell { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestShell.class); @Override - protected String getExcludeList() { - return "replication_admin_test.rb,rsgroup_shell_test.rb,admin_test.rb,table_test.rb," - + "quotas_test.rb,admin2_test.rb,list_tables_test.rb"; + public String getSuitePattern() { + return "**/*_test_cluster.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShellNoCluster.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShellNoCluster.java index c8685f34d19..5c312ec1dac 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShellNoCluster.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShellNoCluster.java @@ -17,51 +17,38 @@ */ package org.apache.hadoop.hbase.client; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.jruby.embed.PathType; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.ClassRule; -import org.junit.Test; import org.junit.experimental.categories.Category; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Category({ ClientTests.class, MediumTests.class }) public class TestShellNoCluster extends AbstractTestShell { - private static final Logger LOG = LoggerFactory.getLogger(TestShellNoCluster.class); - @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestShellNoCluster.class); - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @Before + public void setUp() throws Exception { + RubyShellTest.setUpConfig(this); + // no cluster - List<String> loadPaths = new ArrayList<>(2); - loadPaths.add("src/test/ruby"); - jruby.setLoadPaths(loadPaths); - jruby.put("$TEST_CLUSTER", TEST_UTIL); - System.setProperty("jruby.jit.logging.verbose", "true"); - System.setProperty("jruby.jit.logging", "true"); - System.setProperty("jruby.native.verbose", "true"); + + RubyShellTest.setUpJRubyRuntime(this); + + RubyShellTest.doTestSetup(this); } - @AfterClass - public static void tearDownAfterClass() throws Exception { + @After + public void tearDown() throws Exception { // no cluster } - // Keep the same name so we override the with-a-cluster test @Override - @Test - public void testRunShellTests() throws IOException { - LOG.info("Start ruby tests without cluster"); - jruby.runScriptlet(PathType.CLASSPATH, "no_cluster_tests_runner.rb"); + public String getSuitePattern() { + return "**/*_test_no_cluster.rb"; } } diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestTableShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestTableShell.java index 1ae56ac669b..e4b27a97835 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestTableShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestTableShell.java @@ -24,14 +24,13 @@ import org.junit.ClassRule; import org.junit.experimental.categories.Category; @Category({ ClientTests.class, MediumTests.class }) -public class TestTableShell extends AbstractTestShell { - +public class TestTableShell extends BaseTestShell { @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestTableShell.class); @Override - protected String getIncludeList() { + public String getIncludeList() { return "table_test.rb"; } } diff --git a/hbase-shell/src/test/ruby/hbase/admin2_test.rb b/hbase-shell/src/test/ruby/hbase/admin2_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/admin2_test.rb rename to hbase-shell/src/test/ruby/hbase/admin2_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/admin_test.rb rename to hbase-shell/src/test/ruby/hbase/admin_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/balancer_utils_test.rb b/hbase-shell/src/test/ruby/hbase/balancer_utils_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/balancer_utils_test.rb rename to hbase-shell/src/test/ruby/hbase/balancer_utils_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/test_connection_no_cluster.rb b/hbase-shell/src/test/ruby/hbase/connection_test_no_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/test_connection_no_cluster.rb rename to hbase-shell/src/test/ruby/hbase/connection_test_no_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/hbase_test.rb b/hbase-shell/src/test/ruby/hbase/hbase_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/hbase_test.rb rename to hbase-shell/src/test/ruby/hbase/hbase_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/security_admin_test.rb b/hbase-shell/src/test/ruby/hbase/security_admin_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/security_admin_test.rb rename to hbase-shell/src/test/ruby/hbase/security_admin_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/taskmonitor_test.rb b/hbase-shell/src/test/ruby/hbase/taskmonitor_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/taskmonitor_test.rb rename to hbase-shell/src/test/ruby/hbase/taskmonitor_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb b/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb rename to hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/no_cluster_tests_runner.rb b/hbase-shell/src/test/ruby/no_cluster_tests_runner.rb deleted file mode 100644 index 0d2f1901438..00000000000 --- a/hbase-shell/src/test/ruby/no_cluster_tests_runner.rb +++ /dev/null @@ -1,94 +0,0 @@ -# -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require 'rubygems' -require 'rake' -require 'set' - - -# This runner will only launch shell tests that don't require a HBase cluster running. - -unless defined?($TEST_CLUSTER) - include Java - - # Set logging level to avoid verboseness - log_level = 'OFF' - org.apache.hadoop.hbase.logging.Log4jUtils.setRootLevel(log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.zookeeper', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.hadoop.hdfs', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.hadoop.hbase', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils - .setAllLevels('org.apache.hadoop.ipc.HBaseServer', log_level) - - java_import org.apache.hadoop.hbase.HBaseTestingUtility - - $TEST_CLUSTER = HBaseTestingUtility.new - $TEST_CLUSTER.configuration.setInt("hbase.regionserver.msginterval", 100) - $TEST_CLUSTER.configuration.setInt("hbase.client.pause", 250) - $TEST_CLUSTER.configuration.setInt(org.apache.hadoop.hbase.HConstants::HBASE_CLIENT_RETRIES_NUMBER, 6) -end - -require 'test_helper' - -puts "Running tests without a cluster..." - -if java.lang.System.get_property('shell.test.include') - includes = Set.new(java.lang.System.get_property('shell.test.include').split(',')) -end - -if java.lang.System.get_property('shell.test.exclude') - excludes = Set.new(java.lang.System.get_property('shell.test.exclude').split(',')) -end - -files = Dir[ File.dirname(__FILE__) + "/**/*_no_cluster.rb" ] -files.each do |file| - filename = File.basename(file) - if includes != nil && !includes.include?(filename) - puts "Skip #{filename} because of not included" - next - end - if excludes != nil && excludes.include?(filename) - puts "Skip #{filename} because of excluded" - next - end - begin - load(file) - rescue => e - puts "ERROR: #{e}" - raise - end -end - -# If this system property is set, we'll use it to filter the test cases. -runner_args = [] -if java.lang.System.get_property('shell.test') - shell_test_pattern = java.lang.System.get_property('shell.test') - puts "Only running tests that match #{shell_test_pattern}" - runner_args << "--testcase=#{shell_test_pattern}" -end -# first couple of args are to match the defaults, so we can pass options to limit the tests run -if !(Test::Unit::AutoRunner.run(false, nil, runner_args)) - raise "Shell unit tests failed. Check output file for details." -end - -puts "Done with tests! Shutting down the cluster..." -if @own_cluster - $TEST_CLUSTER.shutdownMiniCluster - java.lang.System.exit(0) -end diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb b/hbase-shell/src/test/ruby/shell/commands_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/commands_test.rb rename to hbase-shell/src/test/ruby/shell/commands_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/converter_test.rb b/hbase-shell/src/test/ruby/shell/converter_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/converter_test.rb rename to hbase-shell/src/test/ruby/shell/converter_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/formatter_test.rb b/hbase-shell/src/test/ruby/shell/formatter_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/formatter_test.rb rename to hbase-shell/src/test/ruby/shell/formatter_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/shell_test.rb b/hbase-shell/src/test/ruby/shell/general_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/shell_test.rb rename to hbase-shell/src/test/ruby/shell/general_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/list_locks_test.rb b/hbase-shell/src/test/ruby/shell/list_locks_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/list_locks_test.rb rename to hbase-shell/src/test/ruby/shell/list_locks_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/list_procedures_test.rb b/hbase-shell/src/test/ruby/shell/list_procedures_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/list_procedures_test.rb rename to hbase-shell/src/test/ruby/shell/list_procedures_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/noninteractive_test.rb b/hbase-shell/src/test/ruby/shell/noninteractive_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/noninteractive_test.rb rename to hbase-shell/src/test/ruby/shell/noninteractive_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/shell/sftchange_shell_test.rb b/hbase-shell/src/test/ruby/shell/sftchange_test_cluster.rb similarity index 100% rename from hbase-shell/src/test/ruby/shell/sftchange_shell_test.rb rename to hbase-shell/src/test/ruby/shell/sftchange_test_cluster.rb diff --git a/hbase-shell/src/test/ruby/tests_runner.rb b/hbase-shell/src/test/ruby/tests_runner.rb index e05d11117e5..4e31b81535a 100644 --- a/hbase-shell/src/test/ruby/tests_runner.rb +++ b/hbase-shell/src/test/ruby/tests_runner.rb @@ -23,34 +23,13 @@ require 'set' puts "Ruby description: #{RUBY_DESCRIPTION}" -unless defined?($TEST_CLUSTER) - include Java - - # Set logging level to avoid verboseness - log_level = 'OFF' - org.apache.hadoop.hbase.logging.Log4jUtils.setRootLevel(log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.zookeeper', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.hadoop.hdfs', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils.setAllLevels('org.apache.hadoop.hbase', log_level) - org.apache.hadoop.hbase.logging.Log4jUtils - .setAllLevels('org.apache.hadoop.ipc.HBaseServer', log_level) +require 'test_helper' - java_import org.apache.hadoop.hbase.HBaseTestingUtility +test_suite_name = java.lang.System.get_property('shell.test.suite_name') - $TEST_CLUSTER = HBaseTestingUtility.new - $TEST_CLUSTER.configuration.setInt("hbase.regionserver.msginterval", 100) - $TEST_CLUSTER.configuration.setInt("hbase.client.pause", 250) - $TEST_CLUSTER.configuration.set("hbase.quota.enabled", "true") - $TEST_CLUSTER.configuration.set('hbase.master.quotas.snapshot.chore.period', 5000) - $TEST_CLUSTER.configuration.set('hbase.master.quotas.snapshot.chore.delay', 5000) - $TEST_CLUSTER.configuration.setInt(org.apache.hadoop.hbase.HConstants::HBASE_CLIENT_RETRIES_NUMBER, 6) - $TEST_CLUSTER.startMiniCluster - @own_cluster = true -end +test_suite_pattern = java.lang.System.get_property('shell.test.suite_pattern') -require 'test_helper' - -puts "Running tests..." +puts "Running tests for #{test_suite_name} with pattern: #{test_suite_pattern} ..." if java.lang.System.get_property('shell.test.include') includes = Set.new(java.lang.System.get_property('shell.test.include').split(',')) @@ -60,7 +39,7 @@ if java.lang.System.get_property('shell.test.exclude') excludes = Set.new(java.lang.System.get_property('shell.test.exclude').split(',')) end -files = Dir[ File.dirname(__FILE__) + "/**/*_test.rb" ] +files = Dir[ File.dirname(__FILE__) + "/" + test_suite_pattern ] files.each do |file| filename = File.basename(file) if includes != nil && !includes.include?(filename) @@ -96,9 +75,3 @@ rescue SystemExit => e # Unit tests should not raise uncaught SystemExit exceptions. This could cause tests to be ignored. raise 'Caught SystemExit during unit test execution! Check output file for details.' end - -puts "Done with tests! Shutting down the cluster..." -if @own_cluster - $TEST_CLUSTER.shutdownMiniCluster - java.lang.System.exit(0) -end