This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
forked from c4pt0r/go-hbase
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathput_test.go
97 lines (77 loc) · 2.24 KB
/
put_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package hbase
import (
"bytes"
. "github.com/pingcap/check"
"github.com/pingcap/go-hbase/proto"
)
type HBasePutTestSuit struct {
cli HBaseClient
tableName string
}
var _ = Suite(&HBasePutTestSuit{})
func (s *HBasePutTestSuit) SetUpTest(c *C) {
var err error
s.cli, err = NewClient(getTestZkHosts(), "/hbase")
c.Assert(err, IsNil)
s.tableName = "t2"
tblDesc := NewTableDesciptor(s.tableName)
cf := NewColumnFamilyDescriptor("cf")
tblDesc.AddColumnDesc(cf)
err = s.cli.CreateTable(tblDesc, nil)
c.Assert(err, IsNil)
}
func (s *HBasePutTestSuit) TearDownTest(c *C) {
err := s.cli.DisableTable(s.tableName)
c.Assert(err, IsNil)
err = s.cli.DropTable(s.tableName)
c.Assert(err, IsNil)
}
func (s *HBasePutTestSuit) TestPut(c *C) {
g := NewPut([]byte("row"))
g.AddValue([]byte("cf"), []byte("q"), []byte("val"))
msg := g.ToProto()
p, _ := msg.(*proto.MutationProto)
c.Assert(*p.MutateType, Equals, *proto.MutationProto_PUT.Enum())
for _, col := range p.ColumnValue {
for _, v := range col.QualifierValue {
c.Assert(bytes.Compare([]byte("q"), v.Qualifier), Equals, 0)
c.Assert(bytes.Compare([]byte("val"), v.Value), Equals, 0)
}
}
}
func (s *HBasePutTestSuit) TestGetPut(c *C) {
p := NewPut([]byte("1_\xff\xff"))
p2 := NewPut([]byte("1_\xff\xfe"))
p3 := NewPut([]byte("1_\xff\xee"))
p.AddValue([]byte("cf"), []byte("q"), []byte("!"))
p2.AddValue([]byte("cf"), []byte("q"), []byte("!"))
p3.AddValue([]byte("cf"), []byte("q"), []byte("!"))
cli, err := NewClient(getTestZkHosts(), "/hbase")
c.Assert(err, Equals, nil)
ok, err := cli.Put(s.tableName, p)
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
ok, err = cli.Put(s.tableName, p2)
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
ok, err = cli.Put(s.tableName, p3)
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
scan := NewScan([]byte(s.tableName), 100, cli)
scan.StartRow = []byte("1_")
for {
r := scan.Next()
if r == nil {
break
}
}
ok, err = cli.Delete(s.tableName, NewDelete([]byte("1_\xff\xff")))
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
ok, err = cli.Delete(s.tableName, NewDelete([]byte("1_\xff\xfe")))
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
ok, err = cli.Delete(s.tableName, NewDelete([]byte("1_\xff\xee")))
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
}