hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r922110 [2/2] - in /hadoop/hbase/trunk: ./ bin/ core/src/main/ruby/ core/src/main/ruby/hbase/ core/src/main/ruby/irb/ core/src/main/ruby/shell/ core/src/main/ruby/shell/commands/ core/src/test/java/org/apache/hadoop/hbase/client/ core/src/t...
Date Fri, 12 Mar 2010 01:36:05 GMT
Added: hadoop/hbase/trunk/core/src/main/ruby/shell/formatter.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/ruby/shell/formatter.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/main/ruby/shell/formatter.rb (added)
+++ hadoop/hbase/trunk/core/src/main/ruby/shell/formatter.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,127 @@
+# Results formatter
+module Shell
+  module Formatter
+    # Base abstract class for results formatting.
+    class Base
+      attr_reader :row_count
+
+      def is_valid_io?(obj)
+        obj.instance_of?(IO) || obj == Kernel
+      end
+
+      # Takes an output stream and a print width.
+      def initialize(opts = {})
+        options = {
+          :output_stream => Kernel,
+          :format_width => 100
+        }.merge(opts)
+
+        @out = options[:output_stream]
+        @max_width = options[:format_width]
+        @row_count = 0
+
+        # raise an error if the stream is not valid
+        raise(TypeError, "Type #{@out.class} of parameter #{@out} is not IO") unless is_valid_io?(@out)
+      end
+
+      def header(args = [], widths = [])
+        row(args, false, widths) if args.length > 0
+        @row_count = 0
+      end
+
+      # Output a row.
+      # Inset is whether or not to offset row by a space.
+      def row(args = [], inset = true, widths = [])
+        # Print out nothing
+        return if !args || args.empty?
+
+        # Print a string
+        if args.is_a?(String)
+          output(@max_width, args)
+          @out.puts
+          return
+        end
+
+        # TODO: Look at the type.  Is it RowResult?
+        if args.length == 1
+          splits = split(@max_width, dump(args[0]))
+          for l in splits
+            output(@max_width, l)
+            @out.puts
+          end
+        elsif args.length == 2
+          col1width = (not widths or widths.length == 0) ? @max_width / 4 : @max_width *
widths[0] / 100
+          col2width = (not widths or widths.length < 2) ? @max_width - col1width - 2 :
@max_width * widths[1] / 100 - 2
+          splits1 = split(col1width, dump(args[0]))
+          splits2 = split(col2width, dump(args[1]))
+          biggest = (splits2.length > splits1.length)? splits2.length: splits1.length
+          index = 0
+          while index < biggest
+            # Inset by one space if inset is set.
+            @out.print(" ") if inset
+            output(col1width, splits1[index])
+            # Add extra space so second column lines up w/ second column output
+            @out.print(" ") unless inset
+            @out.print(" ")
+            output(col2width, splits2[index])
+            index += 1
+            @out.puts
+          end
+        else
+          # Print a space to set off multi-column rows
+          print ' '
+          first = true
+          for e in args
+            @out.print " " unless first
+            first = false
+            @out.print e
+          end
+          puts
+        end
+        @row_count += 1
+      end
+
+      def split(width, str)
+        result = []
+        index = 0
+        while index < str.length do
+          result << str.slice(index, width)
+          index += width
+        end
+        result
+      end
+
+      def dump(str)
+        return if str.instance_of?(Fixnum)
+        # Remove double-quotes added by 'dump'.
+        return str
+      end
+
+      def output(width, str)
+        # Make up a spec for printf
+        spec = "%%-%ds" % width
+        @out.printf(spec, str)
+      end
+
+      def footer(start_time = nil, row_count = nil)
+        return unless start_time
+        row_count ||= @row_count
+        # Only output elapsed time and row count if startTime passed
+        @out.puts("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time])
+      end
+    end
+
+
+    class Console < Base
+    end
+
+    class XHTMLFormatter < Base
+      # http://www.germane-software.com/software/rexml/doc/classes/REXML/Document.html
+      # http://www.crummy.com/writing/RubyCookbook/test_results/75942.html
+    end
+
+    class JSON < Base
+    end
+  end
+end
+

Added: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestShell.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestShell.java?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestShell.java (added)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestShell.java Fri
Mar 12 01:36:04 2010
@@ -0,0 +1,72 @@
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.jruby.embed.ScriptingContainer;
+import org.jruby.embed.PathType;
+
+/**
+ *
+ * @author scoundrel
+ */
+public class TestShell {
+  final Log LOG = LogFactory.getLog(getClass());
+  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+  private final static ScriptingContainer jruby = new ScriptingContainer();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    // Start mini cluster
+    TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
+    TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
+    TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 6);
+    TEST_UTIL.startMiniCluster();
+
+    // Configure jruby runtime
+    List<String> loadPaths = new ArrayList();
+    loadPaths.add("src/main/ruby");
+    loadPaths.add("src/test/ruby");
+    jruby.getProvider().setLoadPaths(loadPaths);
+    jruby.put("$TEST_CLUSTER", TEST_UTIL);
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testRunShellTests() throws IOException {
+    // Start all ruby tests
+    jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb");
+  }
+}

Added: hadoop/hbase/trunk/core/src/test/ruby/hbase/admin_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/hbase/admin_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/hbase/admin_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/hbase/admin_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,263 @@
+require 'hbase'
+
+include HBaseConstants
+
+module Hbase
+  class AdminHelpersTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      create_test_table(@test_name)
+    end
+
+    define_test "exists? should return true when a table exists" do
+      assert(admin.exists?('.META.'))
+    end
+
+    define_test "exists? should return false when a table exists" do
+      assert(!admin.exists?('.NOT.EXISTS.'))
+    end
+
+    define_test "enabled? should return true for enabled tables" do
+      admin.enable(@test_name)
+      assert(admin.enabled?(@test_name))
+    end
+
+    define_test "enabled? should return false for disabled tables" do
+      admin.disable(@test_name)
+      assert(!admin.enabled?(@test_name))
+    end
+  end
+
+    # Simple administration methods tests
+  class AdminMethodsTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      create_test_table(@test_name)
+
+      # Create table test table name
+      @create_test_name = 'hbase_create_table_test_table'
+    end
+
+    define_test "list should return a list of tables" do
+      assert(admin.list.member?(@test_name))
+    end
+
+    define_test "list should not return meta tables" do
+      assert(!admin.list.member?('.META.'))
+      assert(!admin.list.member?('-ROOT-'))
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "flush should work" do
+      admin.flush('.META.')
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "compact should work" do
+      admin.compact('.META.')
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "major_compact should work" do
+      admin.major_compact('.META.')
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "split should work" do
+      admin.split('.META.')
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "drop should fail on non-existent tables" do
+      assert_raise(ArgumentError) do
+        admin.drop('.NOT.EXISTS.')
+      end
+    end
+
+    define_test "drop should fail on enabled tables" do
+      assert_raise(ArgumentError) do
+        admin.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))
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "zk_dump should work" do
+      assert_not_nil(admin.zk_dump)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "create should fail with non-string table names" do
+      assert_raise(ArgumentError) do
+        admin.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)
+      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)
+      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')
+      assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
+     end
+
+    define_test "create hould work with hash column args" do
+      drop_test_table(@create_test_name)
+      admin.create(@create_test_name, { NAME => 'a'}, { NAME => 'b'})
+      assert_equal(['a:', 'b:'], table(@create_test_name).get_all_columns.sort)
+    end
+
+    #-------------------------------------------------------------------------------
+
+#    define_test "close should work without region server name" do
+#      if admin.exists?(@create_test_name)
+#        admin.disable(@create_test_name)
+#        admin.drop(@create_test_name)
+#      end
+#      admin.create(@create_test_name, 'foo')
+#      admin.close_region(@create_test_name + ',,0')
+#    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "describe should fail for non-existent tables" do
+      assert_raise(ArgumentError) do
+        admin.describe('.NOT.EXISTS.')
+      end
+    end
+
+    define_test "describe should return a description" do
+      assert_not_nil admin.describe(@test_name)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "truncate should empty a table" do
+      table(@test_name).put(1, "x:a", 1)
+      table(@test_name).put(2, "x:a", 2)
+      assert_equal(2, table(@test_name).count)
+      admin.truncate(@test_name)
+      assert_equal(0, table(@test_name).count)
+    end
+
+    define_test "truncate should yield log records" do
+      logs = []
+      admin.truncate(@test_name) do |log|
+        assert_kind_of(String, log)
+        logs << log
+      end
+      assert(!logs.empty?)
+    end
+  end
+
+ # Simple administration methods tests
+  class AdminAlterTableTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      drop_test_table(@test_name)
+      create_test_table(@test_name)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "alter should fail with non-string table names" do
+      assert_raise(ArgumentError) do
+        admin.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.', METHOD => 'delete', NAME => 'y')
+      end
+    end
+
+    define_test "alter should fail with enabled tables" do
+      assert_raise(ArgumentError) do
+        admin.alter(@test_name, METHOD => 'delete', NAME => 'y')
+      end
+    end
+
+    define_test "alter should be able to delete column families" do
+      assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
+      admin.disable(@test_name)
+      admin.alter(@test_name, METHOD => 'delete', NAME => 'y')
+      admin.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.disable(@test_name)
+      admin.alter(@test_name, NAME => 'z')
+      admin.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.disable(@test_name)
+      admin.alter(@test_name, 'z')
+      admin.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)
+      admin.disable(@test_name)
+      admin.alter(@test_name, { NAME => 'z' }, { METHOD => 'delete', NAME => 'y'
})
+      admin.enable(@test_name)
+      assert_equal(['x:', 'z:'], table(@test_name).get_all_columns.sort)
+    end
+
+    define_test 'alter should support shortcut DELETE alter specs' do
+      assert_equal(['x:', 'y:'], table(@test_name).get_all_columns.sort)
+      admin.disable(@test_name)
+      admin.alter(@test_name, 'delete' => 'y')
+      admin.disable(@test_name)
+      assert_equal(['x:'], table(@test_name).get_all_columns.sort)
+    end
+
+    define_test "alter should be able to change table options" do
+      admin.disable(@test_name)
+      admin.alter(@test_name, METHOD => 'table_att', 'MAX_FILESIZE' => 12345678)
+      admin.disable(@test_name)
+      assert_match(/12345678/, admin.describe(@test_name))
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/hbase/hbase_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/hbase/hbase_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/hbase/hbase_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/hbase/hbase_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,30 @@
+require 'hbase'
+
+module Hbase
+  class HbaseTest < Test::Unit::TestCase
+    def setup
+      @formatter = Shell::Formatter::Console.new(:format_width => 110)
+      @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
+    end
+
+    define_test "Hbase::Hbase constructor should initialize hbase configuration object" do
+      assert_kind_of(org.apache.hadoop.conf.Configuration, @hbase.configuration)
+    end
+
+    define_test "Hbase::Hbase#admin should create a new admin object when called the first
time" do
+      assert_kind_of(::Hbase::Admin, @hbase.admin(@formatter))
+    end
+
+    define_test "Hbase::Hbase#admin should create a new admin object every call" do
+      assert_not_same(@hbase.admin(@formatter), @hbase.admin(@formatter))
+    end
+
+    define_test "Hbase::Hbase#table should create a new table object when called the first
time" do
+      assert_kind_of(::Hbase::Table, @hbase.table('.META.', @formatter))
+    end
+
+    define_test "Hbase::Hbase#table should create a new table object every call" do
+      assert_not_same(@hbase.table('.META.', @formatter), @hbase.table('.META.', @formatter))
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/hbase/table_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/hbase/table_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/hbase/table_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/hbase/table_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,383 @@
+require 'hbase'
+
+include HBaseConstants
+
+module Hbase
+  # Constructor tests
+  class TableConstructorTest < Test::Unit::TestCase
+    include TestHelpers
+    def setup
+      setup_hbase
+    end
+
+    define_test "Hbase::Table constructor should fail for non-existent tables" do
+      assert_raise(NativeException) do
+        table('non-existent-table-name')
+      end
+    end
+
+    define_test "Hbase::Table constructor should not fail for existent tables" do
+      assert_nothing_raised do
+        table('.META.')
+      end
+    end
+  end
+
+  # Helper methods tests
+  class TableHelpersTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      create_test_table(@test_name)
+      @test_table = table(@test_name)
+    end
+
+    define_test "is_meta_table? method should return true for the meta table" do
+      assert(table('.META.').is_meta_table?)
+    end
+
+    define_test "is_meta_table? method should return true for the root table" do
+      assert(table('-ROOT-').is_meta_table?)
+    end
+
+    define_test "is_meta_table? method should return false for a normal table" do
+      assert(!@test_table.is_meta_table?)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "get_all_columns should return columns list" do
+      cols = table('.META.').get_all_columns
+      assert_kind_of(Array, cols)
+      assert(cols.length > 0)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "parse_column_name should not return a qualifier for name-only column specifiers"
do
+      col, qual = table('.META.').parse_column_name('foo')
+      assert_not_nil(col)
+      assert_nil(qual)
+    end
+
+    define_test "parse_column_name should not return a qualifier for family-only column specifiers"
do
+      col, qual = table('.META.').parse_column_name('foo:')
+      assert_not_nil(col)
+      assert_nil(qual)
+    end
+
+    define_test "parse_column_name should return a qualifier for family:qualifier column
specifiers" do
+      col, qual = table('.META.').parse_column_name('foo:bar')
+      assert_not_nil(col)
+      assert_not_nil(qual)
+    end
+  end
+
+  # Simple data management methods tests
+  class TableSimpleMethodsTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      create_test_table(@test_name)
+      @test_table = table(@test_name)
+    end
+
+    define_test "put should work without timestamp" do
+      @test_table.put("123", "x:a", "1")
+    end
+
+    define_test "put should work with timestamp" do
+      @test_table.put("123", "x:a", "2", Time.now.to_i)
+    end
+
+    define_test "put should work with integer keys" do
+      @test_table.put(123, "x:a", "3")
+    end
+
+    define_test "put should work with integer values" do
+      @test_table.put("123", "x:a", 4)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "delete should work without timestamp" do
+      @test_table.delete("123", "x:a")
+    end
+
+    define_test "delete should work with timestamp" do
+      @test_table.delete("123", "x:a", Time.now.to_i)
+    end
+
+    define_test "delete should work with integer keys" do
+      @test_table.delete(123, "x:a")
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "deleteall should work w/o columns and timestamps" do
+      @test_table.deleteall("123")
+    end
+
+    define_test "deleteall should work with integer keys" do
+      @test_table.deleteall(123)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "incr should work w/o value" do
+      @test_table.incr("123", 'x:cnt1')
+    end
+
+    define_test "incr should work with value" do
+      @test_table.incr("123", 'x:cnt2', 10)
+    end
+
+    define_test "incr should work with integer keys" do
+      @test_table.incr(123, 'x:cnt3')
+    end
+  end
+
+  # Complex data management methods tests
+  class TableComplexMethodsTest < Test::Unit::TestCase
+    include TestHelpers
+
+    def setup
+      setup_hbase
+      # Create test table if it does not exist
+      @test_name = "hbase_shell_tests_table"
+      create_test_table(@test_name)
+      @test_table = table(@test_name)
+
+      # Test data
+      @test_ts = 12345678
+      @test_table.put(1, "x:a", 1)
+      @test_table.put(1, "x:b", 2, @test_ts)
+
+      @test_table.put(2, "x:a", 11)
+      @test_table.put(2, "x:b", 12, @test_ts)
+    end
+
+    define_test "count should work w/o a block passed" do
+      assert(@test_table.count > 0)
+    end
+
+    define_test "count should work with a block passed (and yield)" do
+      rows = []
+      cnt = @test_table.count(1) do |cnt, row|
+        rows << row
+      end
+      assert(cnt > 0)
+      assert(!rows.empty?)
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "get should work w/o columns specification" do
+      res = @test_table.get('1')
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with integer keys" do
+      res = @test_table.get(1)
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with hash columns spec and a single string COLUMN parameter"
do
+      res = @test_table.get('1', COLUMN => 'x:a')
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_nil(res['x:b'])
+    end
+
+    define_test "get should work with hash columns spec and a single string COLUMNS parameter"
do
+      res = @test_table.get('1', COLUMNS => 'x:a')
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_nil(res['x:b'])
+    end
+
+    define_test "get should work with hash columns spec and an array of strings COLUMN parameter"
do
+      res = @test_table.get('1', COLUMN => [ 'x:a', 'x:b' ])
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with hash columns spec and an array of strings COLUMNS parameter"
do
+      res = @test_table.get('1', COLUMNS => [ 'x:a', 'x:b' ])
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with hash columns spec and TIMESTAMP only" do
+      res = @test_table.get('1', TIMESTAMP => @test_ts)
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should fail with hash columns spec and strange COLUMN value" do
+      assert_raise(ArgumentError) do
+        @test_table.get('1', COLUMN => {})
+      end
+    end
+
+    define_test "get should fail with hash columns spec and strange COLUMNS value" do
+      assert_raise(ArgumentError) do
+        @test_table.get('1', COLUMN => {})
+      end
+    end
+
+    define_test "get should fail with hash columns spec and no TIMESTAMP or COLUMN[S]" do
+      assert_raise(ArgumentError) do
+        @test_table.get('1', { :foo => :bar })
+      end
+    end
+
+    define_test "get should work with a string column spec" do
+      res = @test_table.get('1', 'x:b')
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with an array columns spec" do
+      res = @test_table.get('1', 'x:a', 'x:b')
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get should work with an array or arrays columns spec (yeah, crazy)" do
+      res = @test_table.get('1', ['x:a'], ['x:b'])
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['x:a'])
+      assert_not_nil(res['x:b'])
+    end
+
+    define_test "get with a block should yield (column, value) pairs" do
+      res = {}
+      @test_table.get('1') { |col, val| res[col] = val }
+      assert_equal(res.keys.sort, [ 'x:a', 'x:b' ])
+    end
+
+    #-------------------------------------------------------------------------------
+
+    define_test "scan should work w/o any params" do
+      res = @test_table.scan
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_not_nil(res['1']['x:a'])
+      assert_not_nil(res['1']['x:b'])
+      assert_not_nil(res['2'])
+      assert_not_nil(res['2']['x:a'])
+      assert_not_nil(res['2']['x:b'])
+    end
+
+    define_test "scan should support STARTROW parameter" do
+      res = @test_table.scan STARTROW => '2'
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_nil(res['1'])
+      assert_not_nil(res['2'])
+      assert_not_nil(res['2']['x:a'])
+      assert_not_nil(res['2']['x:b'])
+    end
+
+    define_test "scan should support STOPROW parameter" do
+      res = @test_table.scan STOPROW => '2'
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_not_nil(res['1']['x:a'])
+      assert_not_nil(res['1']['x:b'])
+      assert_nil(res['2'])
+    end
+
+    define_test "scan should support LIMIT parameter" do
+      res = @test_table.scan LIMIT => 1
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_not_nil(res['1']['x:a'])
+      assert_not_nil(res['1']['x:b'])
+      assert_nil(res['2'])
+    end
+
+    define_test "scan should support TIMESTAMP parameter" do
+      res = @test_table.scan TIMESTAMP => @test_ts
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_nil(res['1']['x:a'])
+      assert_not_nil(res['1']['x:b'])
+      assert_not_nil(res['2'])
+      assert_nil(res['2']['x:a'])
+      assert_not_nil(res['2']['x:b'])
+    end
+
+    define_test "scan should support COLUMNS parameter with an array of columns" do
+      res = @test_table.scan COLUMNS => [ 'x:a', 'x:b' ]
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_not_nil(res['1']['x:a'])
+      assert_not_nil(res['1']['x:b'])
+      assert_not_nil(res['2'])
+      assert_not_nil(res['2']['x:a'])
+      assert_not_nil(res['2']['x:b'])
+    end
+
+    define_test "scan should support COLUMNS parameter with a single column name" do
+      res = @test_table.scan COLUMNS => 'x:a'
+      assert_not_nil(res)
+      assert_kind_of(Hash, res)
+      assert_not_nil(res['1'])
+      assert_not_nil(res['1']['x:a'])
+      assert_nil(res['1']['x:b'])
+      assert_not_nil(res['2'])
+      assert_not_nil(res['2']['x:a'])
+      assert_nil(res['2']['x:b'])
+    end
+
+    define_test "scan should fail on invalid COLUMNS parameter types" do
+      assert_raise(ArgumentError) do
+        @test_table.scan COLUMNS => {}
+      end
+    end
+
+    define_test "scan should fail on non-hash params" do
+      assert_raise(ArgumentError) do
+        @test_table.scan 123
+      end
+    end
+
+    define_test "scan with a block should yield rows and return rows counter" do
+      rows = {}
+      res = @test_table.scan { |row, cells| rows[row] = cells }
+      assert_equal(rows.keys.size, res)
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/shell/commands_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/shell/commands_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/shell/commands_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/shell/commands_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,14 @@
+require 'shell'
+require 'shell/formatter'
+
+class ShellCommandsTest < Test::Unit::TestCase
+  Shell.commands.each do |name, klass|
+    define_test "#{name} command class #{klass} should respond to help" do
+      assert_respond_to(klass.new(nil), :help)
+    end
+
+    define_test "#{name} command class #{klass} should respond to :command" do
+      assert_respond_to(klass.new(nil), :command)
+    end
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/shell/formatter_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/shell/formatter_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/shell/formatter_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/shell/formatter_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,49 @@
+require 'shell/formatter'
+
+class ShellFormatterTest < Test::Unit::TestCase
+  # Helper method to construct a null formatter
+  def formatter
+    Shell::Formatter::Base.new(:output_stream => STDOUT)
+  end
+
+  #
+  # Constructor tests
+  #
+  define_test "Formatter constructor should not raise error valid IO streams" do
+    assert_nothing_raised do
+      Shell::Formatter::Base.new(:output_stream => STDOUT)
+    end
+  end
+
+  define_test "Formatter constructor should not raise error when no IO stream passed" do
+    assert_nothing_raised do
+      Shell::Formatter::Base.new()
+    end
+  end
+
+  define_test "Formatter constructor should raise error on non-IO streams" do
+    assert_raise TypeError do
+      Shell::Formatter::Base.new(:output_stream => 'foostring')
+    end
+  end
+
+  #-------------------------------------------------------------------------------------------------------
+  # Printing methods tests
+  # FIXME: The tests are just checking that the code has no typos, try to figure out a better
way to test
+  #
+  define_test "Formatter#header should work" do
+    formatter.header(['a', 'b'])
+    formatter.header(['a', 'b'], [10, 20])
+  end
+
+  define_test "Formatter#row should work" do
+    formatter.row(['a', 'b'])
+    formatter.row(['xxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxx xxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxx'])
+    formatter.row(['yyyyyy yyyyyy yyyyy yyy', 'xxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx
xxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxx  xxx xx x xx xxx xx xx xx
x xx x x xxx x x xxx x x xx x x x x x x xx '])
+    formatter.row(["NAME => 'table1', FAMILIES => [{NAME => 'fam2', VERSIONS =>
3, COMPRESSION => 'NONE', IN_MEMORY => false, BLOCKCACHE => false, LENGTH => 2147483647,
TTL => FOREVER, BLOOMFILTER => NONE}, {NAME => 'fam1', VERSIONS => 3, COMPRESSION
=> 'NONE', IN_MEMORY => false, BLOCKCACHE => false, LENGTH => 2147483647, TTL
=> FOREVER, BLOOMFILTER => NONE}]"])
+  end
+
+  define_test "Froematter#footer should work" do
+    formatter.footer(Time.now - 5)
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/shell/shell_test.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/shell/shell_test.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/shell/shell_test.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/shell/shell_test.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,50 @@
+require 'hbase'
+require 'shell'
+require 'shell/formatter'
+
+class ShellTest < Test::Unit::TestCase
+  def setup
+    @formatter = ::Shell::Formatter::Console.new(:format_width => 110)
+    @hbase = ::Hbase::Hbase.new
+    @shell = Shell::Shell.new(@hbase, @formatter)
+  end
+
+  define_test "Shell::Shell#hbase_admin should return an admin instance" do
+    assert_kind_of(Hbase::Admin, @shell.hbase_admin)
+  end
+
+  define_test "Shell::Shell#hbase_admin should cache admin instances" do
+    assert_same(@shell.hbase_admin, @shell.hbase_admin)
+  end
+
+  #-------------------------------------------------------------------------------
+
+  define_test "Shell::Shell#hbase_table should return a table instance" do
+    assert_kind_of(Hbase::Table, @shell.hbase_table('.META.'))
+  end
+
+  define_test "Shell::Shell#hbase_table should not cache table instances" do
+    assert_not_same(@shell.hbase_table('.META.'), @shell.hbase_table('.META.'))
+  end
+
+  #-------------------------------------------------------------------------------
+
+  define_test "Shell::Shell#export_commands should export command methods to specified object"
do
+    module Foo; end
+    assert(!Foo.respond_to?(:version))
+    @shell.export_commands(Foo)
+    assert(Foo.respond_to?(:version))
+  end
+
+  #-------------------------------------------------------------------------------
+
+  define_test "Shell::Shell#command_instance should return a command class" do
+    assert_kind_of(Shell::Commands::Command, @shell.command_instance('version'))
+  end
+
+  #-------------------------------------------------------------------------------
+
+  define_test "Shell::Shell#command should execute a command" do
+    @shell.command('version')
+  end
+end

Added: hadoop/hbase/trunk/core/src/test/ruby/test_helper.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/test_helper.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/test_helper.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/test_helper.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,72 @@
+require 'test/unit'
+
+module Testing
+  module Declarative
+    # define_test "should do something" do
+    #   ...
+    # end
+    def define_test(name, &block)
+      test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
+      defined = instance_method(test_name) rescue false
+      raise "#{test_name} is already defined in #{self}" if defined
+      if block_given?
+        define_method(test_name, &block)
+      else
+        define_method(test_name) do
+          flunk "No implementation provided for #{name}"
+        end
+      end
+    end
+  end
+end
+
+module Hbase
+  module TestHelpers
+    def setup_hbase
+      @formatter = Shell::Formatter::Console.new(:format_width => 110)
+      @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
+    end
+
+    def table(table)
+      @hbase.table(table, @formatter)
+    end
+
+    def admin
+      @hbase.admin(@formatter)
+    end
+
+    def create_test_table(name)
+      # Create the table if needed
+      unless admin.exists?(name)
+        admin.create name, [{'NAME' => 'x', 'VERSIONS' => 5}, 'y']
+        return
+      end
+
+      # Enable the table if needed
+      unless admin.enabled?(name)
+        admin.enable(name)
+      end
+    end
+
+    def drop_test_table(name)
+      return unless admin.exists?(name)
+      begin
+        admin.disable(name) if admin.enabled?(name)
+      rescue => e
+        puts "IGNORING DISABLE TABLE ERROR: #{e}"
+      end
+      begin
+        admin.drop(name)
+      rescue => e
+        puts "IGNORING DROP TABLE ERROR: #{e}"
+      end
+    end
+  end
+end
+
+# Extend standard unit tests with our helpers
+Test::Unit::TestCase.extend(Testing::Declarative)
+
+# Add the $HBASE_HOME/lib/ruby directory to the ruby
+# load path so I can load up my HBase ruby modules
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "..", "main", "ruby")

Added: hadoop/hbase/trunk/core/src/test/ruby/tests_runner.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/ruby/tests_runner.rb?rev=922110&view=auto
==============================================================================
--- hadoop/hbase/trunk/core/src/test/ruby/tests_runner.rb (added)
+++ hadoop/hbase/trunk/core/src/test/ruby/tests_runner.rb Fri Mar 12 01:36:04 2010
@@ -0,0 +1,18 @@
+require 'rubygems'
+require 'rake'
+
+require 'test_helper'
+
+puts "Running tests..."
+
+files = Dir[ File.dirname(__FILE__) + "/**/*_test.rb" ]
+files.each do |file|
+  begin
+    load(file)
+  rescue => e
+    puts "ERROR: #{e}"
+    raise
+  end
+end
+
+puts "Done with tests!"

Modified: hadoop/hbase/trunk/src/assembly/bin.xml
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/assembly/bin.xml?rev=922110&r1=922109&r2=922110&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/assembly/bin.xml (original)
+++ hadoop/hbase/trunk/src/assembly/bin.xml Fri Mar 12 01:36:04 2010
@@ -102,6 +102,10 @@
       </includes>
     </fileSet>
     <fileSet>
+      <directory>core/src/main/ruby</directory>
+      <outputDirectory>lib/ruby</outputDirectory>
+    </fileSet>
+    <fileSet>
       <directory>contrib/transactional</directory>
       <outputDirectory>contrib/transactional</outputDirectory>
       <includes>



Mime
View raw message