Sha256: ea29391559f378e4fe97f01aff20e8de2334867931da11e794a5812db8bae117

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path('..', __FILE__)
require 'helper'
require 'bigdecimal'

class TestCell < Test::Unit::TestCase
  import org.apache.hadoop.hbase.KeyValue
  Util = HBase::Util

  def test_cell
    ts = Time.now.to_i * 1000
    {
      'value'                        => :string,
      :value                         => :symbol,
      123                            => :fixnum,
      123.456                        => :float,
      true                           => :boolean,
      false                          => :boolean,
      BigDecimal.new("123.456")      => :bigdecimal
    }.each do |value, type|
      kv = KeyValue.new("rowkey".to_java_bytes, "hello".to_java_bytes, "world".to_java_bytes, ts, Util.to_bytes(value))
      cell = HBase::Cell.new(kv)

      assert_equal "rowkey", cell.rowkey
      assert_equal "hello",  cell.cf, cell.family
      assert_equal "world",  cell.cq, cell.qualifier
      assert_equal ts,       cell.ts
      assert_equal value,    cell.send(type)
      assert_equal HBase::ColumnKey.new(:hello, :world), cell.column_key
      assert_instance_of String, cell.inspect
    end
  end
  
  def test_order
    ts = Time.now.to_i * 1000

    val = "val".to_java_bytes
    cells = 
      [
        KeyValue.new("rowkey".to_java_bytes, "apple".to_java_bytes,  "alpha".to_java_bytes, ts, val),
        KeyValue.new("rowkey".to_java_bytes, "apple".to_java_bytes,  "alpha".to_java_bytes, ts - 1000, val),
        KeyValue.new("rowkey".to_java_bytes, "apple".to_java_bytes,  "beta".to_java_bytes,  ts, val),
        KeyValue.new("rowkey".to_java_bytes, "banana".to_java_bytes, "beta".to_java_bytes,  ts, val),
        KeyValue.new("rowkey".to_java_bytes, "banana".to_java_bytes, "gamma".to_java_bytes, ts, val),
      ].map { |kv| HBase::Cell.new kv }

    assert_equal cells, cells.reverse.sort
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hbase-jruby-0.1.6-java test/test_cell.rb
hbase-jruby-0.1.5-java test/test_cell.rb
hbase-jruby-0.1.4-java test/test_cell.rb
hbase-jruby-0.1.3-java test/test_cell.rb
hbase-jruby-0.1.2-java test/test_cell.rb