1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
20 # define_test "should do something" do
23 def define_test(name, &block)
24 test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
25 defined = instance_method(test_name) rescue false
26 raise "#{test_name} is already defined in #{self}" if defined
28 define_method(test_name, &block)
30 define_method(test_name) do
31 flunk "No implementation provided for #{name}"
40 require 'hbase_constants'
45 hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
46 @shell = ::Shell::Shell.new(hbase, interactive = false)
53 # This function triggers exactly same path as the users.
54 def command(command, *args)
55 @shell.command(command, *args)
59 @shell.hbase_table(table)
67 @shell.hbase_taskmonitor
71 @shell.hbase_security_admin
75 @shell.hbase_visibility_labels_admin
79 @shell.hbase_quotas_admin
83 @shell.hbase_replication_admin
86 def group_admin(_formatter)
87 @shell.hbase_group_admin
90 def create_test_table(name)
91 # Create the table if needed
92 unless admin.exists?(name)
93 command(:create, name, {'NAME' => 'x', 'VERSIONS' => 5}, 'y')
97 # Enable the table if needed
98 unless admin.enabled?(name)
103 def create_test_table_with_splits(name, splits)
104 # Create the table if needed
105 unless admin.exists?(name)
106 command(:create, name, 'f1', splits)
109 # Enable the table if needed
110 unless admin.enabled?(name)
115 def drop_test_table(name)
116 return unless admin.exists?(name)
118 admin.disable(name) if admin.enabled?(name)
120 puts "IGNORING DISABLE TABLE ERROR: #{e}"
125 puts "IGNORING DROP TABLE ERROR: #{e}"
129 def replication_status(format,type)
130 return admin.status(format,type)
133 def drop_test_snapshot()
135 admin.delete_all_snapshot(".*")
137 puts "IGNORING DELETE ALL SNAPSHOT ERROR: #{e}"
145 $stdout = StringIO.new('','w')
155 # Extend standard unit tests with our helpers
156 Test::Unit::TestCase.extend(Testing::Declarative)
158 # Add the $HBASE_HOME/lib/ruby directory to the ruby
159 # load path so I can load up my HBase ruby modules
160 $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "..", "main", "ruby")