hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject hbase git commit: HBASE-15965 - Testing by executing a command will cover the exact path users will trigger, so its better then directly calling library functions in tests. Changing the tests to use @shell.command(:<command>, args) to execute them like i
Date Tue, 07 Jun 2016 00:50:34 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 3d7840a17 -> 15c03fd1c


HBASE-15965
- Testing by executing a command will cover the exact path users will trigger, so its better then directly calling library functions in tests. Changing the tests to use @shell.command(:<command>, args) to execute them like it's a command coming from shell.

Norm change:
Commands should print the output user would like to see, but in the end, should also return the relevant value. This way:
- Tests can use returned value to check that functionality works
- Tests can capture stdout to assert particular kind of output user should see.
- We do not print the return value in interactive mode and keep the output clean. See Shell.command() function.

Bugs found due to this change:
- Uncovered bug in major_compact.rb with this approach. It was calling admin.majorCompact() which doesn't exist but our tests didn't catch it since they directly tested admin.major_compact()
- Enabled TestReplicationShell. If it's bad, flaky infra will take care of it.

Change-Id: I5d8af16bf477a79a2f526a5bf11c245b02b7d276


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/15c03fd1
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/15c03fd1
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/15c03fd1

Branch: refs/heads/master
Commit: 15c03fd1c97c271aca6dc30feab35ec0c9f8edbe
Parents: 3d7840a
Author: Apekshit Sharma <appy@apache.org>
Authored: Mon Jun 6 13:35:06 2016 -0700
Committer: Apekshit Sharma <appy@apache.org>
Committed: Mon Jun 6 17:50:22 2016 -0700

----------------------------------------------------------------------
 .../replication/ReplicationPeerConfig.java      |   6 +-
 hbase-shell/src/main/ruby/hbase/admin.rb        |  23 +-
 hbase-shell/src/main/ruby/hbase/table.rb        |   1 +
 hbase-shell/src/main/ruby/shell.rb              |  12 +-
 hbase-shell/src/main/ruby/shell/commands.rb     |   2 +
 .../main/ruby/shell/commands/balance_rsgroup.rb |   9 +-
 .../src/main/ruby/shell/commands/create.rb      |   2 +
 .../src/main/ruby/shell/commands/exists.rb      |   4 +-
 .../src/main/ruby/shell/commands/get_auths.rb   |   1 +
 .../main/ruby/shell/commands/get_peer_config.rb |   1 +
 .../src/main/ruby/shell/commands/is_enabled.rb  |   4 +-
 .../shell/commands/list_namespace_tables.rb     |   1 +
 .../ruby/shell/commands/list_peer_configs.rb    |   1 +
 .../src/main/ruby/shell/commands/list_peers.rb  |   1 +
 .../main/ruby/shell/commands/locate_region.rb   |   1 +
 .../main/ruby/shell/commands/major_compact.rb   |   2 +-
 .../ruby/shell/commands/show_peer_tableCFs.rb   |   4 +-
 .../src/main/ruby/shell/commands/truncate.rb    |   3 +-
 .../ruby/shell/commands/truncate_preserve.rb    |   3 +-
 .../hbase/client/TestReplicationShell.java      |   2 +-
 hbase-shell/src/test/ruby/hbase/admin_test.rb   | 229 +++++++++----------
 .../test/ruby/hbase/replication_admin_test.rb   | 110 ++++-----
 .../ruby/hbase/visibility_labels_admin_test.rb  |  20 +-
 hbase-shell/src/test/ruby/test_helper.rb        |  23 +-
 24 files changed, 254 insertions(+), 211 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java
index 7799de6..1d2066c 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java
@@ -96,8 +96,10 @@ public class ReplicationPeerConfig {
   @Override
   public String toString() {
     StringBuilder builder = new StringBuilder("clusterKey=").append(clusterKey).append(",");
-    builder.append("replicationEndpointImpl=").append(replicationEndpointImpl).append(",")
-        .append("tableCFs=").append(tableCFsMap.toString());
+    builder.append("replicationEndpointImpl=").append(replicationEndpointImpl).append(",");
+    if (tableCFsMap != null) {
+      builder.append("tableCFs=").append(tableCFsMap.toString());
+    }
     return builder.toString();
   }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/hbase/admin.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index f32376d..d66c1d6 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -458,16 +458,17 @@ module Hbase
 
     #----------------------------------------------------------------------------------------------
     # Truncates table (deletes all records by recreating the table)
-    def truncate(table_name_str, conf = @conf)
+    def truncate(table_name_str)
+      puts "Truncating '#{table_name_str}' table (it may take a while):"
       table_name = TableName.valueOf(table_name_str)
       table_description = @admin.getTableDescriptor(table_name)
       raise ArgumentError, "Table #{table_name_str} is not enabled. Enable it first." unless
           enabled?(table_name_str)
-      yield 'Disabling table...' if block_given?
+      puts 'Disabling table...'
       @admin.disableTable(table_name)
 
       begin
-        yield 'Truncating table...' if block_given?
+        puts 'Truncating table...'
         @admin.truncateTable(table_name, false)
       rescue => e
         # Handle the compatibility case, where the truncate method doesn't exists on the Master
@@ -475,10 +476,10 @@ module Hbase
         rootCause = e.cause
         if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
           # Handle the compatibility case, where the truncate method doesn't exists on the Master
-          yield 'Dropping table...' if block_given?
+          puts 'Dropping table...'
           @admin.deleteTable(table_name)
 
-          yield 'Creating table...' if block_given?
+          puts 'Creating table...'
           @admin.createTable(table_description)
         else
           raise e
@@ -488,9 +489,9 @@ module Hbase
 
     #----------------------------------------------------------------------------------------------
     # Truncates table while maintaing region boundaries (deletes all records by recreating the table)
-    def truncate_preserve(table_name_str, conf = @conf)
+    def truncate_preserve(table_name_str)
+      puts "Truncating '#{table}' table (it may take a while):"
       table_name = TableName.valueOf(table_name_str)
-      h_table = @connection.getTable(table_name)
       locator = @connection.getRegionLocator(table_name)
       begin
         splits = locator.getAllRegionLocations().
@@ -501,11 +502,11 @@ module Hbase
       end
 
       table_description = @admin.getTableDescriptor(table_name)
-      yield 'Disabling table...' if block_given?
+      puts 'Disabling table...'
       disable(table_name_str)
 
       begin
-        yield 'Truncating table...' if block_given?
+        puts 'Truncating table...'
         @admin.truncateTable(table_name, true)
       rescue => e
         # Handle the compatibility case, where the truncate method doesn't exists on the Master
@@ -513,10 +514,10 @@ module Hbase
         rootCause = e.cause
         if rootCause.kind_of?(org.apache.hadoop.hbase.DoNotRetryIOException) then
           # Handle the compatibility case, where the truncate method doesn't exists on the Master
-          yield 'Dropping table...' if block_given?
+          puts 'Dropping table...'
           @admin.deleteTable(table_name)
 
-          yield 'Creating table with region boundaries...' if block_given?
+          puts 'Creating table with region boundaries...'
           @admin.createTable(table_description, splits)
         else
           raise e

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/hbase/table.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb
index e64b4ee..a90760e 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -719,6 +719,7 @@ EOF
           map{|i| Bytes.toStringBinary(i.getRegionInfo().getStartKey)}.delete_if{|k| k == ""}
       locator.close()
       puts("Total number of splits = %s" % [splits.size + 1])
+      puts splits
       return splits
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index 35626d9..d0cb577 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -134,9 +134,17 @@ module Shell
       ::Shell.commands[command.to_s].new(self)
     end
 
-    #call the method 'command' on the specified command
+    # call the method 'command' on the specified command
+    # If interactive is enabled, then we suppress the return value. The command should have
+    # printed relevant output.
+    # Return value is only useful in non-interactive mode, for e.g. tests.
     def command(command, *args)
-      internal_command(command, :command, *args)
+      ret = internal_command(command, :command, *args)
+      if self.interactive
+        return nil
+      else
+        return ret
+      end
     end
 
     # call a specific internal method in the command instance

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb
index f86904c..98fcf60 100644
--- a/hbase-shell/src/main/ruby/shell/commands.rb
+++ b/hbase-shell/src/main/ruby/shell/commands.rb
@@ -17,6 +17,8 @@
 # limitations under the License.
 #
 
+require 'shell/formatter'
+
 module Shell
   module Commands
     class Command

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb b/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb
index bee139f..c925f28 100644
--- a/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/balance_rsgroup.rb
@@ -30,7 +30,14 @@ EOF
       end
 
       def command(group_name)
-        rsgroup_admin.balance_rs_group(group_name)
+        # Returns true if balancer was run, otherwise false.
+        ret = rsgroup_admin.balance_rs_group(group_name)
+        if ret
+          puts "Ran the balancer."
+        else
+          puts "Couldn't run the balancer."
+        end
+        ret
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/create.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/create.rb b/hbase-shell/src/main/ruby/shell/commands/create.rb
index c237ca9..ee14455 100644
--- a/hbase-shell/src/main/ruby/shell/commands/create.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/create.rb
@@ -64,6 +64,8 @@ EOF
       def command(table, *args)
         admin.create(table, *args)
         @end_time = Time.now
+        puts "Created table " + table.to_s
+
         #and then return the table just created
         table(table)
       end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/exists.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/exists.rb b/hbase-shell/src/main/ruby/shell/commands/exists.rb
index 7a64813..4eb13a4 100644
--- a/hbase-shell/src/main/ruby/shell/commands/exists.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/exists.rb
@@ -29,9 +29,11 @@ EOF
       end
 
       def command(table)
+        exists = admin.exists?(table.to_s)
         formatter.row([
-            "Table #{table} " + (admin.exists?(table.to_s) ? "does exist" : "does not exist")
+            "Table #{table} " + (exists ? "does exist" : "does not exist")
           ])
+        exists
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/get_auths.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/get_auths.rb b/hbase-shell/src/main/ruby/shell/commands/get_auths.rb
index 04b486b..4ea1b2e 100644
--- a/hbase-shell/src/main/ruby/shell/commands/get_auths.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/get_auths.rb
@@ -35,6 +35,7 @@ EOF
         list.each do |auths|
           formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(auths.toByteArray)])
         end
+        list
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
index 3da6bdf..6417980 100644
--- a/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/get_peer_config.rb
@@ -28,6 +28,7 @@ module Shell
         peer_config = replication_admin.get_peer_config(id)
         @start_time = Time.now
         format_peer_config(peer_config)
+        peer_config
       end
 
       def format_peer_config(peer_config)

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb
index d8fb2ab..da9c566 100644
--- a/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/is_enabled.rb
@@ -29,7 +29,9 @@ EOF
       end
 
       def command(table)
-        formatter.row([admin.enabled?(table)? "true" : "false"])
+        enabled = admin.enabled?(table)
+        formatter.row([enabled ? "true" : "false"])
+        enabled
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb b/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb
index 9db090e..30d4db0 100644
--- a/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/list_namespace_tables.rb
@@ -38,6 +38,7 @@ EOF
         end
 
         formatter.footer(list.size)
+        list
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
index 153e0ce..8946e39 100644
--- a/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/list_peer_configs.rb
@@ -35,6 +35,7 @@ module Shell
             formatter.row([" "])
           end
         end
+        peer_configs
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/list_peers.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb
index c5c3397..72a0704 100644
--- a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb
@@ -41,6 +41,7 @@ EOF
         end
 
         formatter.footer()
+        peers
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/locate_region.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/locate_region.rb b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb
index a2815d6..e2487c1 100644
--- a/hbase-shell/src/main/ruby/shell/commands/locate_region.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/locate_region.rb
@@ -36,6 +36,7 @@ EOF
         formatter.header([ "HOST", "REGION" ])
         formatter.row([region_location.getHostnamePort(), hri.toString()])
         formatter.footer(1)
+        region_location
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/major_compact.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/major_compact.rb b/hbase-shell/src/main/ruby/shell/commands/major_compact.rb
index 1af6c64..9b0573c 100644
--- a/hbase-shell/src/main/ruby/shell/commands/major_compact.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/major_compact.rb
@@ -44,7 +44,7 @@ module Shell
       end
 
       def command(table_or_region_name, family = nil, type = "NORMAL")
-        admin.majorCompact(table_or_region_name, family, type)
+        admin.major_compact(table_or_region_name, family, type)
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb
index 3ce3d06..b6b6956 100644
--- a/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/show_peer_tableCFs.rb
@@ -30,7 +30,9 @@ module Shell
       end
 
       def command(id)
-        puts replication_admin.show_peer_tableCFs(id)
+        peer_table_cfs = replication_admin.show_peer_tableCFs(id)
+        puts peer_table_cfs
+        peer_table_cfs
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/truncate.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/truncate.rb b/hbase-shell/src/main/ruby/shell/commands/truncate.rb
index 3f888c6..aff51ac 100644
--- a/hbase-shell/src/main/ruby/shell/commands/truncate.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/truncate.rb
@@ -27,8 +27,7 @@ EOF
       end
 
       def command(table)
-        puts "Truncating '#{table}' table (it may take a while):"
-        admin.truncate(table) { |log| puts " - #{log}" }
+        admin.truncate(table)
       end
 
     end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb b/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb
index fcce5e5..8bb3131 100644
--- a/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/truncate_preserve.rb
@@ -27,8 +27,7 @@ EOF
       end
 
       def command(table)
-        puts "Truncating '#{table}' table (it may take a while):"
-        admin.truncate_preserve(table) { |log| puts " - #{log}" }
+        admin.truncate_preserve(table)
       end
 
     end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestReplicationShell.java
----------------------------------------------------------------------
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 3f4af05..04fbc7a 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
@@ -28,7 +28,7 @@ import org.junit.experimental.categories.Category;
 
 @Category({ ClientTests.class, LargeTests.class })
 public class TestReplicationShell extends AbstractTestShell {
-  @Ignore ("Disabled because hangs on occasion.. about 10% of the time") @Test
+  @Test
   public void testRunShellTests() throws IOException {
     System.setProperty("shell.test.include", "replication_admin_test.rb");
     // Start all ruby tests

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/test/ruby/hbase/admin_test.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb b/hbase-shell/src/test/ruby/hbase/admin_test.rb
index e2c3bc0..cf9cf64 100644
--- a/hbase-shell/src/test/ruby/hbase/admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb
@@ -41,21 +41,21 @@ module Hbase
     end
 
     define_test "exists? should return true when a table exists" do
-      assert(admin.exists?('hbase:meta'))
+      assert(command(:exists, 'hbase:meta'))
     end
 
     define_test "exists? should return false when a table exists" do
-      assert(!admin.exists?('NOT.EXISTS'))
+      assert(!command(:exists, 'NOT.EXISTS'))
     end
 
     define_test "enabled? should return true for enabled tables" do
-      admin.enable(@test_name)
-      assert(admin.enabled?(@test_name))
+      command(:enable, @test_name)
+      assert(command(:is_enabled, @test_name))
     end
 
     define_test "enabled? should return false for disabled tables" do
-      admin.disable(@test_name)
-      assert(!admin.enabled?(@test_name))
+      command(:disable, @test_name)
+      assert(!command(:is_enabled, @test_name))
     end
   end
 
@@ -78,63 +78,67 @@ module Hbase
     end
 
     define_test "list should return a list of tables" do
-      assert(admin.list.member?(@test_name))
+      list = command(:list)
+      assert(list.member?(@test_name))
     end
 
     define_test "list should not return meta tables" do
-      assert(!admin.list.member?('hbase:meta'))
+      list = command(:list)
+      assert(!list.member?('hbase:meta'))
     end
 
     define_test "list_namespace_tables for the system namespace should return a list of tables" do
-      assert(admin.list_namespace_tables('hbase').count > 0)
+      list = command(:list_namespace_tables, 'hbase')
+      assert(list.count > 0)
     end
 
     define_test "list_namespace_tables for the default namespace should return a list of tables" do
-      assert(admin.list_namespace_tables('default').count > 0)
+      list = command(:list_namespace_tables, 'default')
+      assert(list.count > 0)
     end
 
     #-------------------------------------------------------------------------------
 
     define_test "flush should work" do
-      admin.flush('hbase:meta')
+      command(:flush, 'hbase:meta')
     end
 
     #-------------------------------------------------------------------------------
 
     define_test "compact should work" do
-      admin.compact('hbase:meta')
+      command(:compact, 'hbase:meta')
     end
 
     #-------------------------------------------------------------------------------
 
     define_test "major_compact should work" do
-      admin.major_compact('hbase:meta')
+      command(:major_compact, 'hbase:meta')
     end
 
     #-------------------------------------------------------------------------------
 
     define_test "split should work" do
-      admin.split('hbase:meta', nil)
+      command(:split, 'hbase:meta', nil)
     end
 
     #-------------------------------------------------------------------------------
 
     define_test "drop should fail on non-existent tables" do
       assert_raise(ArgumentError) do
-        admin.drop('NOT.EXISTS')
+        command(:drop, 'NOT.EXISTS')
       end
     end
 
     define_test "drop should fail on enabled tables" do
       assert_raise(ArgumentError) do
-        admin.drop(@test_name)
+        command(:drop, @test_name)
       end
     end
 
     define_test "drop should drop tables" do
-      admin.disable(@test_name)
-      admin.drop(@test_name)
-      assert(!admin.exists?(@test_name))
+      command(:disable, @test_name)
+      command(:drop, @test_name)
+      assert(!command(:exists, @test_name))
     end
 
     #-------------------------------------------------------------------------------
@@ -147,45 +151,46 @@ module Hbase
 
     define_test "create should fail with non-string table names" do
       assert_raise(ArgumentError) do
-        admin.create(123, 'xxx')
+        command(:create, 123, 'xxx')
       end
     end
 
     define_test "create should fail with non-string/non-hash column args" do
       assert_raise(ArgumentError) do
-        admin.create(@create_test_name, 123)
+        command(:create, @create_test_name, 123)
       end
     end
 
     define_test "create should fail without columns" do
       drop_test_table(@create_test_name)
       assert_raise(ArgumentError) do
-        admin.create(@create_test_name)
+        command(:create, @create_test_name)
       end
     end
     
     define_test "create should fail without columns when called with options" do
       drop_test_table(@create_test_name)
       assert_raise(ArgumentError) do
-        admin.create(@create_test_name, { OWNER => 'a' })
+        command(:create, @create_test_name, { OWNER => 'a' })
       end
     end
 
     define_test "create should work with string column args" do
       drop_test_table(@create_test_name)
-      admin.create(@create_test_name, 'a', 'b')
+      command(:create, @create_test_name, 'a', 'b')
       assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
      end
 
     define_test "create should work with hash column args" do
       drop_test_table(@create_test_name)
-      admin.create(@create_test_name, { NAME => 'a'}, { NAME => 'b'})
+      command(:create, @create_test_name, { NAME => 'a'}, { NAME => 'b'})
       assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
     end
     
     define_test "create should be able to set table options" do
       drop_test_table(@create_test_name)
-      admin.create(@create_test_name, 'a', 'b', 'MAX_FILESIZE' => 12345678, OWNER => '987654321')
+      command(:create, @create_test_name, 'a', 'b', 'MAX_FILESIZE' => 12345678,
+              OWNER => '987654321')
       assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
       assert_match(/12345678/, admin.describe(@create_test_name))
       assert_match(/987654321/, admin.describe(@create_test_name))
@@ -193,14 +198,15 @@ module Hbase
         
     define_test "create should ignore table_att" do
       drop_test_table(@create_test_name)
-      admin.create(@create_test_name, 'a', 'b', METHOD => 'table_att', OWNER => '987654321')
+      command(:create, @create_test_name, 'a', 'b', METHOD => 'table_att', OWNER => '987654321')
       assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
       assert_match(/987654321/, admin.describe(@create_test_name))
     end
     
     define_test "create should work with SPLITALGO" do
       drop_test_table(@create_test_name)
-      admin.create(@create_test_name, 'a', 'b', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
+      command(:create, @create_test_name, 'a', 'b',
+              {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'})
       assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
     end
 
@@ -223,17 +229,13 @@ module Hbase
       table(@test_name).put(2, "x:a", 2)
       assert_equal(2, table(@test_name)._count_internal)
       # This is hacky.  Need to get the configuration into admin instance
-      admin.truncate(@test_name, $TEST_CLUSTER.getConfiguration)
+      command(:truncate, @test_name)
       assert_equal(0, table(@test_name)._count_internal)
     end
 
     define_test "truncate should yield log records" do
-      logs = []
-      admin.truncate(@test_name, $TEST_CLUSTER.getConfiguration) do |log|
-        assert_kind_of(String, log)
-        logs << log
-      end
-      assert(!logs.empty?)
+      output = capture_stdout { command(:truncate, @test_name) }
+      assert(!output.empty?)
     end
   end
 
@@ -253,16 +255,16 @@ module Hbase
     end
 
     define_test "close_region should allow encoded & non-encoded region names" do
-      region = admin.locate_region(@test_name, '')
+      region = command(:locate_region, @test_name, '')
       serverName = region.getServerName().getServerName()
       regionName = region.getRegionInfo().getRegionNameAsString()
       encodedRegionName = region.getRegionInfo().getEncodedName()
 
       # Close region with just region name.
-      admin.close_region(regionName, nil)
+      command(:close_region, regionName, nil)
       # Close region with region name and server.
-      admin.close_region(regionName, serverName)
-      admin.close_region(encodedRegionName, serverName)
+      command(:close_region, regionName, serverName)
+      command(:close_region, encodedRegionName, serverName)
     end
   end
 
@@ -286,77 +288,68 @@ module Hbase
 
     define_test "alter should fail with non-string table names" do
       assert_raise(ArgumentError) do
-        admin.alter(123, true, METHOD => 'delete', NAME => 'y')
+        command(:alter, 123, METHOD => 'delete', NAME => 'y')
       end
     end
 
     define_test "alter should fail with non-existing tables" do
       assert_raise(ArgumentError) do
-        admin.alter('NOT.EXISTS', true, METHOD => 'delete', NAME => 'y')
+        command(:alter, 'NOT.EXISTS', METHOD => 'delete', NAME => 'y')
       end
     end
 
     define_test "alter should not fail with enabled tables" do
-      admin.enable(@test_name)
-      admin.alter(@test_name, true, METHOD => 'delete', NAME => 'y')
+      command(:enable, @test_name)
+      command(:alter, @test_name, METHOD => 'delete', NAME => 'y')
     end
 
     define_test "alter should be able to delete column families" do
       assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
-      admin.alter(@test_name, true, METHOD => 'delete', NAME => 'y')
-      admin.enable(@test_name)
+      command(:alter, @test_name, METHOD => 'delete', NAME => 'y')
+      command(:enable, @test_name)
       assert_equal(['x:'], table(@test_name).get_all_columns.sort)
     end
 
     define_test "alter should be able to add column families" do
       assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
-      admin.alter(@test_name, true, NAME => 'z')
-      admin.enable(@test_name)
+      command(:alter, @test_name, NAME => 'z')
+      command(:enable, @test_name)
       assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort)
     end
 
     define_test "alter should be able to add column families (name-only alter spec)" do
       assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
-      admin.alter(@test_name, true, 'z')
-      admin.enable(@test_name)
+      command(:alter, @test_name, 'z')
+      command(:enable, @test_name)
       assert_equal(['x:', 'y:', 'z:'], table(@test_name).get_all_columns.sort)
     end
 
     define_test "alter should support more than one alteration in one call" do
       assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
-      alterOutput = capture_stdout { admin.alter(@test_name, true, { NAME => 'z' },
-        { METHOD => 'delete', NAME => 'y' }, 'MAX_FILESIZE' => 12345678) }
-      admin.enable(@test_name)
+      alterOutput = capture_stdout {
+        command(:alter, @test_name, { NAME => 'z' }, { METHOD => 'delete', NAME => 'y' },
+                'MAX_FILESIZE' => 12345678) }
+      command(:enable, @test_name)
       assert_equal(1, /Updating all regions/.match(alterOutput).size,
         "HBASE-15641 - Should only perform one table modification per alter.")
       assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort)
       assert_match(/12345678/, admin.describe(@test_name))
     end
 
-    def capture_stdout
-      begin
-        old_stdout = $stdout
-        $stdout = StringIO.new('','w')
-        yield
-        $stdout.string
-      ensure
-        $stdout = old_stdout
-      end
-    end
 
     define_test 'alter should support shortcut DELETE alter specs' do
       assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
-      admin.alter(@test_name, true, 'delete' => 'y')
+      command(:alter, @test_name, 'delete' => 'y')
       assert_equal(['x:'], table(@test_name).get_all_columns.sort)
     end
 
     define_test "alter should be able to change table options" do
-      admin.alter(@test_name, true, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678)
+      command(:alter, @test_name, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678)
       assert_match(/12345678/, admin.describe(@test_name))
     end
 
     define_test "alter should be able to change table options w/o table_att" do
-      admin.alter(@test_name, true, 'MAX_FILESIZE' => 12345678)
+      command(:alter, @test_name, 'MAX_FILESIZE' => 12345678)
       assert_match(/12345678/, admin.describe(@test_name))
     end
     
@@ -372,7 +365,7 @@ module Hbase
       # eval() is used to convert a string to regex
       assert_no_match(eval("/" + class_name + "/"), admin.describe(@test_name))
       assert_no_match(eval("/" + cp_key + "/"), admin.describe(@test_name))
-      admin.alter(@test_name, true, 'METHOD' => 'table_att', cp_key => cp_value)
+      command(:alter, @test_name, 'METHOD' => 'table_att', cp_key => cp_value)
       assert_match(eval("/" + class_name + "/"), admin.describe(@test_name))
       assert_match(eval("/" + cp_key + "\\$(\\d+)/"), admin.describe(@test_name))
     end
@@ -382,12 +375,12 @@ module Hbase
       create_test_table(@test_name)
 
       key = "MAX_FILESIZE"
-      admin.alter(@test_name, true, 'METHOD' => 'table_att', key => 12345678)
+      command(:alter, @test_name, 'METHOD' => 'table_att', key => 12345678)
 
       # eval() is used to convert a string to regex
       assert_match(eval("/" + key + "/"), admin.describe(@test_name))
 
-      admin.alter(@test_name, true, 'METHOD' => 'table_att_unset', 'NAME' => key)
+      command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => key)
       assert_no_match(eval("/" + key + "/"), admin.describe(@test_name))
     end
 
@@ -396,13 +389,13 @@ module Hbase
 
       key_1 = "TestAttr1"
       key_2 = "TestAttr2"
-      admin.create(@test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 })
+      command(:create, @test_name, { NAME => 'i'}, METADATA => { key_1 => 1, key_2 => 2 })
 
       # eval() is used to convert a string to regex
       assert_match(eval("/" + key_1 + "/"), admin.describe(@test_name))
       assert_match(eval("/" + key_2 + "/"), admin.describe(@test_name))
 
-      admin.alter(@test_name, true, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ])
+      command(:alter, @test_name, 'METHOD' => 'table_att_unset', 'NAME' => [ key_1, key_2 ])
       assert_no_match(eval("/" + key_1 + "/"), admin.describe(@test_name))
       assert_no_match(eval("/" + key_2 + "/"), admin.describe(@test_name))
     end
@@ -450,66 +443,66 @@ module Hbase
     #-------------------------------------------------------------------------------
     define_test "Snapshot should fail with non-string table name" do
       assert_raise(ArgumentError) do
-        admin.snapshot(123, 'xxx')
+        command(:snapshot, 123, 'xxx')
       end
     end
 
     define_test "Snapshot should fail with non-string snapshot name" do
       assert_raise(ArgumentError) do
-        admin.snapshot(@test_name, 123)
+        command(:snapshot, @test_name, 123)
       end
     end
 
     define_test "Snapshot should fail without snapshot name" do
       assert_raise(ArgumentError) do
-        admin.snapshot(@test_name)
+        command(:snapshot, @test_name)
       end
     end
 
     define_test "Snapshot should work with string args" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, @create_test_snapshot)
-      list = admin.list_snapshot(@create_test_snapshot)
+      command(:snapshot, @test_name, @create_test_snapshot)
+      list = command(:list_snapshots, @create_test_snapshot)
       assert_equal(1, list.size)
     end
 
     define_test "Snapshot should work when SKIP_FLUSH args" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, @create_test_snapshot, {SKIP_FLUSH => true})
-      list = admin.list_snapshot(@create_test_snapshot)
+      command(:snapshot, @test_name, @create_test_snapshot, {SKIP_FLUSH => true})
+      list = command(:list_snapshots, @create_test_snapshot)
       assert_equal(1, list.size)
     end
 
     define_test "List snapshot without any args" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, @create_test_snapshot)
-      list = admin.list_snapshot()
+      command(:snapshot, @test_name, @create_test_snapshot)
+      list = command(:list_snapshots)
       assert_equal(1, list.size)
     end
 
     define_test "List snapshot for a non-existing snapshot" do
-      list = admin.list_snapshot("xyz")
+      list = command(:list_snapshots, "xyz")
       assert_equal(0, list.size)
     end
 
     define_test "Restore snapshot without any args" do
       assert_raise(ArgumentError) do
-        admin.restore_snapshot()
+        command(:restore_snapshot)
       end
     end
 
     define_test "Restore snapshot should work" do
       drop_test_snapshot()
       restore_table = "test_restore_snapshot_table"
-      admin.create(restore_table, 'f1', 'f2')
+      command(:create, restore_table, 'f1', 'f2')
       assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
       assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
-      admin.snapshot(restore_table, @create_test_snapshot)
-      admin.alter(restore_table, true, METHOD => 'delete', NAME => 'f1')
+      command(:snapshot, restore_table, @create_test_snapshot)
+      command(:alter, restore_table, METHOD => 'delete', NAME => 'f1')
       assert_no_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
       assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
       drop_test_table(restore_table)
-      admin.restore_snapshot(@create_test_snapshot)
+      command(:restore_snapshot, @create_test_snapshot)
       assert_match(eval("/" + "f1" + "/"), admin.describe(restore_table))
       assert_match(eval("/" + "f2" + "/"), admin.describe(restore_table))
       drop_test_table(restore_table)
@@ -517,13 +510,13 @@ module Hbase
 
     define_test "Clone snapshot without any args" do
       assert_raise(ArgumentError) do
-        admin.restore_snapshot()
+        command(:restore_snapshot)
       end
     end
 
     define_test "Clone snapshot without table name args" do
       assert_raise(ArgumentError) do
-        admin.clone_snapshot(@create_test_snapshot)
+        command(:clone_snapshot, @create_test_snapshot)
       end
     end
 
@@ -532,8 +525,8 @@ module Hbase
       clone_table = "test_clone_snapshot_table"
       assert_match(eval("/" + "x" + "/"), admin.describe(@test_name))
       assert_match(eval("/" + "y" + "/"), admin.describe(@test_name))
-      admin.snapshot(@test_name, @create_test_snapshot)
-      admin.clone_snapshot(@create_test_snapshot, clone_table)
+      command(:snapshot, @test_name, @create_test_snapshot)
+      command(:clone_snapshot, @create_test_snapshot, clone_table)
       assert_match(eval("/" + "x" + "/"), admin.describe(clone_table))
       assert_match(eval("/" + "y" + "/"), admin.describe(clone_table))
       drop_test_table(clone_table)
@@ -547,11 +540,11 @@ module Hbase
 
     define_test "Delete snapshot should work" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, @create_test_snapshot)
-      list = admin.list_snapshot()
+      command(:snapshot, @test_name, @create_test_snapshot)
+      list = command(:list_snapshots)
       assert_equal(1, list.size)
       admin.delete_snapshot(@create_test_snapshot)
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(0, list.size)
     end
 
@@ -563,17 +556,17 @@ module Hbase
 
     define_test "Delete all snapshots should work" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, "delete_all_snapshot1")
-      admin.snapshot(@test_name, "delete_all_snapshot2")
-      admin.snapshot(@test_name, "snapshot_delete_all_1")
-      admin.snapshot(@test_name, "snapshot_delete_all_2")
-      list = admin.list_snapshot()
+      command(:snapshot, @test_name, "delete_all_snapshot1")
+      command(:snapshot, @test_name, "delete_all_snapshot2")
+      command(:snapshot, @test_name, "snapshot_delete_all_1")
+      command(:snapshot, @test_name, "snapshot_delete_all_2")
+      list = command(:list_snapshots)
       assert_equal(4, list.size)
       admin.delete_all_snapshot("d.*")
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(2, list.size)
       admin.delete_all_snapshot(".*")
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(0, list.size)
     end
 
@@ -585,48 +578,48 @@ module Hbase
 
     define_test "Delete table snapshots should work" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, "delete_table_snapshot1")
-      admin.snapshot(@test_name, "delete_table_snapshot2")
-      admin.snapshot(@test_name, "snapshot_delete_table1")
+      command(:snapshot, @test_name, "delete_table_snapshot1")
+      command(:snapshot, @test_name, "delete_table_snapshot2")
+      command(:snapshot, @test_name, "snapshot_delete_table1")
       new_table = "test_delete_table_snapshots_table"
-      admin.create(new_table, 'f1')
-      admin.snapshot(new_table, "delete_table_snapshot3")
-      list = admin.list_snapshot()
+      command(:create, new_table, 'f1')
+      command(:snapshot, new_table, "delete_table_snapshot3")
+      list = command(:list_snapshots)
       assert_equal(4, list.size)
       admin.delete_table_snapshots(@test_name, "d.*")
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(2, list.size)
       admin.delete_table_snapshots(@test_name)
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(1, list.size)
       admin.delete_table_snapshots(".*", "d.*")
-      list = admin.list_snapshot()
+      list = command(:list_snapshots)
       assert_equal(0, list.size)
       drop_test_table(new_table)
     end
 
     define_test "List table snapshots without any args" do
       assert_raise(ArgumentError) do
-        admin.list_table_snapshots()
+        command(:list_table_snapshots)
       end
     end
 
     define_test "List table snapshots should work" do
       drop_test_snapshot()
-      admin.snapshot(@test_name, "delete_table_snapshot1")
-      admin.snapshot(@test_name, "delete_table_snapshot2")
-      admin.snapshot(@test_name, "snapshot_delete_table1")
+      command(:snapshot, @test_name, "delete_table_snapshot1")
+      command(:snapshot, @test_name, "delete_table_snapshot2")
+      command(:snapshot, @test_name, "snapshot_delete_table1")
       new_table = "test_list_table_snapshots_table"
-      admin.create(new_table, 'f1')
-      admin.snapshot(new_table, "delete_table_snapshot3")
-      list = admin.list_table_snapshots(".*")
+      command(:create, new_table, 'f1')
+      command(:snapshot, new_table, "delete_table_snapshot3")
+      list = command(:list_table_snapshots, ".*")
       assert_equal(4, list.size)
-      list = admin.list_table_snapshots(@test_name, "d.*")
+      list = command(:list_table_snapshots, @test_name, "d.*")
       assert_equal(2, list.size)
-      list = admin.list_table_snapshots(@test_name)
+      list = command(:list_table_snapshots, @test_name)
       assert_equal(3, list.size)
       admin.delete_table_snapshots(".*")
-      list = admin.list_table_snapshots(".*", ".*")
+      list = command(:list_table_snapshots, ".*", ".*")
       assert_equal(0, list.size)
       drop_test_table(new_table)
     end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
index d00dbc5..cf6eac2 100644
--- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
@@ -33,25 +33,25 @@ module Hbase
 
       setup_hbase
 
-      assert_equal(0, replication_admin.list_peers.length)
+      assert_equal(0, command(:list_peers).length)
     end
 
     def teardown
-      assert_equal(0, replication_admin.list_peers.length)
+      assert_equal(0, command(:list_peers).length)
 
       shutdown
     end
 
     define_test "add_peer: should fail when args isn't specified" do
       assert_raise(ArgumentError) do
-        replication_admin.add_peer(@peer_id, nil)
+        command(:add_peer, @peer_id, nil)
       end
     end
 
     define_test "add_peer: fail when neither CLUSTER_KEY nor ENDPOINT_CLASSNAME are specified" do
       assert_raise(ArgumentError) do
         args = {}
-        replication_admin.add_peer(@peer_id, args)
+        command(:add_peer, @peer_id, args)
       end
     end
 
@@ -59,74 +59,74 @@ module Hbase
       assert_raise(ArgumentError) do
         args = { CLUSTER_KEY => 'zk1,zk2,zk3:2182:/hbase-prod',
                  ENDPOINT_CLASSNAME => 'org.apache.hadoop.hbase.MyReplicationEndpoint' }
-        replication_admin.add_peer(@peer_id, args)
+        command(:add_peer, @peer_id, args)
       end
     end
 
     define_test "add_peer: args must be a hash" do
       assert_raise(ArgumentError) do
-        replication_admin.add_peer(@peer_id, 1)
+        command(:add_peer, @peer_id, 1)
       end
       assert_raise(ArgumentError) do
-        replication_admin.add_peer(@peer_id, ['test'])
+        command(:add_peer, @peer_id, ['test'])
       end
       assert_raise(ArgumentError) do
-        replication_admin.add_peer(@peer_id, 'test')
+        command(:add_peer, @peer_id, 'test')
       end
     end
 
     define_test "add_peer: single zk cluster key" do
       cluster_key = "server1.cie.com:2181:/hbase"
 
-      replication_admin.add_peer(@peer_id, {CLUSTER_KEY => cluster_key})
+      command(:add_peer, @peer_id, {CLUSTER_KEY => cluster_key})
 
-      assert_equal(1, replication_admin.list_peers.length)
-      assert(replication_admin.list_peers.key?(@peer_id))
-      assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id).get_cluster_key)
+      assert_equal(1, command(:list_peers).length)
+      assert(command(:list_peers).key?(@peer_id))
+      assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key)
 
       # cleanup for future tests
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "add_peer: multiple zk cluster key" do
       cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
 
-      replication_admin.add_peer(@peer_id, {CLUSTER_KEY => cluster_key})
+      command(:add_peer, @peer_id, {CLUSTER_KEY => cluster_key})
 
-      assert_equal(1, replication_admin.list_peers.length)
-      assert(replication_admin.list_peers.key?(@peer_id))
-      assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id).get_cluster_key)
+      assert_equal(1, command(:list_peers).length)
+      assert(command(:list_peers).key?(@peer_id))
+      assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key)
 
       # cleanup for future tests
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "add_peer: single zk cluster key - peer config" do
       cluster_key = "server1.cie.com:2181:/hbase"
 
       args = { CLUSTER_KEY => cluster_key }
-      replication_admin.add_peer(@peer_id, args)
+      command(:add_peer, @peer_id, args)
 
-      assert_equal(1, replication_admin.list_peers.length)
-      assert(replication_admin.list_peers.key?(@peer_id))
-      assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id).get_cluster_key)
+      assert_equal(1, command(:list_peers).length)
+      assert(command(:list_peers).key?(@peer_id))
+      assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key)
 
       # cleanup for future tests
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "add_peer: multiple zk cluster key - peer config" do
       cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
 
       args = { CLUSTER_KEY => cluster_key }
-      replication_admin.add_peer(@peer_id, args)
+      command(:add_peer, @peer_id, args)
 
-      assert_equal(1, replication_admin.list_peers.length)
-      assert(replication_admin.list_peers.key?(@peer_id))
-      assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id).get_cluster_key)
+      assert_equal(1, command(:list_peers).length)
+      assert(command(:list_peers).key?(@peer_id))
+      assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key)
 
       # cleanup for future tests
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "add_peer: multiple zk cluster key and table_cfs - peer config" do
@@ -135,15 +135,15 @@ module Hbase
       table_cfs_str = "default.table1;default.table3:cf1,cf2;default.table2:cf1"
 
       args = { CLUSTER_KEY => cluster_key, TABLE_CFS => table_cfs }
-      replication_admin.add_peer(@peer_id, args)
+      command(:add_peer, @peer_id, args)
 
-      assert_equal(1, replication_admin.list_peers.length)
-      assert(replication_admin.list_peers.key?(@peer_id))
-      assert_equal(cluster_key, replication_admin.list_peers.fetch(@peer_id).get_cluster_key)
-      assert_equal(table_cfs_str, replication_admin.show_peer_tableCFs(@peer_id))
+      assert_equal(1, command(:list_peers).length)
+      assert(command(:list_peers).key?(@peer_id))
+      assert_equal(cluster_key, command(:list_peers).fetch(@peer_id).get_cluster_key)
+      assert_equal(table_cfs_str, command(:show_peer_tableCFs, @peer_id))
 
       # cleanup for future tests
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "add_peer: should fail when args is a hash and peer_tableCFs provided" do
@@ -152,51 +152,51 @@ module Hbase
 
       assert_raise(ArgumentError) do
         args = { CLUSTER_KEY => cluster_key }
-        replication_admin.add_peer(@peer_id, args, table_cfs_str)
+        command(:add_peer, @peer_id, args, table_cfs_str)
       end
     end
 
     define_test "get_peer_config: works with simple clusterKey peer" do
       cluster_key = "localhost:2181:/hbase-test"
       args = { CLUSTER_KEY => cluster_key }
-      replication_admin.add_peer(@peer_id, args)
-      peer_config = replication_admin.get_peer_config(@peer_id)
+      command(:add_peer, @peer_id, args)
+      peer_config = command(:get_peer_config, @peer_id)
       assert_equal(cluster_key, peer_config.get_cluster_key)
       #cleanup
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "get_peer_config: works with replicationendpointimpl peer and config params" do
       repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
       config_params = { "config1" => "value1", "config2" => "value2" }
       args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
-      replication_admin.add_peer(@peer_id, args)
-      peer_config = replication_admin.get_peer_config(@peer_id)
+      command(:add_peer, @peer_id, args)
+      peer_config = command(:get_peer_config, @peer_id)
       assert_equal(repl_impl, peer_config.get_replication_endpoint_impl)
       assert_equal(2, peer_config.get_configuration.size)
       assert_equal("value1", peer_config.get_configuration.get("config1"))
       #cleanup
-      replication_admin.remove_peer(@peer_id)
+      command(:remove_peer, @peer_id)
     end
 
     define_test "list_peer_configs: returns all peers' ReplicationPeerConfig objects" do
       cluster_key = "localhost:2181:/hbase-test"
       args = { CLUSTER_KEY => cluster_key }
       peer_id_second = '2'
-      replication_admin.add_peer(@peer_id, args)
+      command(:add_peer, @peer_id, args)
 
       repl_impl = "org.apache.hadoop.hbase.replication.ReplicationEndpointForTest"
       config_params = { "config1" => "value1", "config2" => "value2" }
       args2 = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params}
-      replication_admin.add_peer(peer_id_second, args2)
+      command(:add_peer, peer_id_second, args2)
 
-      peer_configs = replication_admin.list_peer_configs
+      peer_configs = command(:list_peer_configs)
       assert_equal(2, peer_configs.size)
       assert_equal(cluster_key, peer_configs.get(@peer_id).get_cluster_key)
       assert_equal(repl_impl, peer_configs.get(peer_id_second).get_replication_endpoint_impl)
       #cleanup
-      replication_admin.remove_peer(@peer_id)
-      replication_admin.remove_peer(peer_id_second)
+      command(:remove_peer, @peer_id)
+      command(:remove_peer, peer_id_second)
     end
 
     define_test "update_peer_config: can update peer config and data" do
@@ -204,7 +204,7 @@ module Hbase
       config_params = { "config1" => "value1", "config2" => "value2" }
       data_params = {"data1" => "value1", "data2" => "value2"}
       args = { ENDPOINT_CLASSNAME => repl_impl, CONFIG => config_params, DATA => data_params}
-      replication_admin.add_peer(@peer_id, args)
+      command(:add_peer, @peer_id, args)
 
       #Normally the ReplicationSourceManager will call ReplicationPeer#peer_added, but here we have to do it ourselves
       replication_admin.peer_added(@peer_id)
@@ -212,12 +212,12 @@ module Hbase
       new_config_params = { "config1" => "new_value1" }
       new_data_params = {"data1" => "new_value1"}
       new_args = {CONFIG => new_config_params, DATA => new_data_params}
-      replication_admin.update_peer_config(@peer_id, new_args)
+      command(:update_peer_config, @peer_id, new_args)
 
       #Make sure the updated key/value pairs in config and data were successfully updated, and that those we didn't
       #update are still there and unchanged
-      peer_config = replication_admin.get_peer_config(@peer_id)
-      replication_admin.remove_peer(@peer_id)
+      peer_config = command(:get_peer_config, @peer_id)
+      command(:remove_peer, @peer_id)
       assert_equal("new_value1", peer_config.get_configuration.get("config1"))
       assert_equal("value2", peer_config.get_configuration.get("config2"))
       assert_equal("new_value1", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data1"))))
@@ -227,17 +227,17 @@ module Hbase
     # assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279
     # Can't catch native Java exception with assert_raise in JRuby 1.6.8 as in the test below.
     # define_test "add_peer: adding a second peer with same id should error" do
-    #   replication_admin.add_peer(@peer_id, '')
-    #   assert_equal(1, replication_admin.list_peers.length)
+    #   command(:add_peer, @peer_id, '')
+    #   assert_equal(1, command(:list_peers).length)
     #
     #   assert_raise(java.lang.IllegalArgumentException) do
-    #     replication_admin.add_peer(@peer_id, '')
+    #     command(:add_peer, @peer_id, '')
     #   end
     #
-    #   assert_equal(1, replication_admin.list_peers.length, 1)
+    #   assert_equal(1, command(:list_peers).length, 1)
     #
     #   # cleanup for future tests
-    #   replication_admin.remove_peer(@peer_id)
+    #   command(:remove_peer, @peer_id)
     # end
   end
 end

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.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.rb
index 0046909..b42290f 100644
--- a/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb
@@ -45,37 +45,37 @@ module Hbase
     define_test "Labels should be created as specified" do
       label = 'TEST_LABELS'
       count = table('hbase:labels')._count_internal
-      visibility_admin.add_labels('test_label')
+      command(:add_labels, 'test_label')
       assert_equal(count + 1, table('hbase:labels')._count_internal)
     end
 
     define_test "The set/clear methods should work with authorizations" do
       label = 'TEST_AUTHS'
       user = org.apache.hadoop.hbase.security.User.getCurrent().getName();
-      visibility_admin.add_labels(label)
+      command(:add_labels, label)
       $TEST_CLUSTER.waitLabelAvailable(10000, label)
-      count = visibility_admin.get_auths(user).length
+      count = command(:get_auths, user).length
 
       # verifying the set functionality
-      visibility_admin.set_auths(user, label)
-      assert_equal(count + 1, visibility_admin.get_auths(user).length)
+      command(:set_auths, user, label)
+      assert_equal(count + 1, command(:get_auths, user).length)
       assert_block do
-        visibility_admin.get_auths(user).any? {
+        command(:get_auths, user).any? {
           |auth| org.apache.hadoop.hbase.util.Bytes::toStringBinary(auth.toByteArray) == label
         }
       end
 
       # verifying the clear functionality
-      visibility_admin.clear_auths(user, label)
-      assert_equal(count, visibility_admin.get_auths(user).length)
+      command(:clear_auths, user, label)
+      assert_equal(count, command(:get_auths, user).length)
     end
 
     define_test "The get/put methods should work for data written with Visibility" do
       label = 'TEST_VISIBILITY'
       user = org.apache.hadoop.hbase.security.User.getCurrent().getName();
-      visibility_admin.add_labels(label)
+      command(:add_labels, label)
       $TEST_CLUSTER.waitLabelAvailable(10000, label)
-      visibility_admin.set_auths(user, label)
+      command(:set_auths, user, label)
 
       # verifying put functionality
       @test_table.put(1, "x:a", 31, {VISIBILITY=>label})

http://git-wip-us.apache.org/repos/asf/hbase/blob/15c03fd1/hbase-shell/src/test/ruby/test_helper.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/test/ruby/test_helper.rb b/hbase-shell/src/test/ruby/test_helper.rb
index 0b3c420..ec6bb6a 100644
--- a/hbase-shell/src/test/ruby/test_helper.rb
+++ b/hbase-shell/src/test/ruby/test_helper.rb
@@ -43,13 +43,18 @@ module Hbase
 
     def setup_hbase
       hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
-      @shell = ::Shell::Shell.new(hbase)
+      @shell = ::Shell::Shell.new(hbase, interactive = false)
     end
     
     def shutdown
       @shell.hbase.shutdown
     end
 
+    # This function triggers exactly same path as the users.
+    def command(command, *args)
+      @shell.command(command, *args)
+    end
+
     def table(table)
       @shell.hbase_table(table)
     end
@@ -85,7 +90,7 @@ module Hbase
     def create_test_table(name)
       # Create the table if needed
       unless admin.exists?(name)
-        admin.create name, [{'NAME' => 'x', 'VERSIONS' => 5}, 'y']
+        command(:create, name, {'NAME' => 'x', 'VERSIONS' => 5}, 'y')
         return
       end
 
@@ -98,7 +103,7 @@ module Hbase
     def create_test_table_with_splits(name, splits)
       # Create the table if needed
       unless admin.exists?(name)
-        admin.create name, 'f1', splits
+        command(:create, name, 'f1', splits)
       end
 
       # Enable the table if needed
@@ -132,6 +137,18 @@ module Hbase
         puts "IGNORING DELETE ALL SNAPSHOT ERROR: #{e}"
       end
     end
+
+
+    def capture_stdout
+      begin
+        old_stdout = $stdout
+        $stdout = StringIO.new('','w')
+        yield
+        $stdout.string
+      ensure
+        $stdout = old_stdout
+      end
+    end
   end
 end
 


Mime
View raw message