forked from pingcap/go-hbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
del_test.go
94 lines (77 loc) · 2.27 KB
/
del_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
package hbase
import (
. "github.com/pingcap/check"
"github.com/pingcap/go-hbase/proto"
)
type HBaseDelTestSuit struct {
cli HBaseClient
tableName string
}
var _ = Suite(&HBaseDelTestSuit{})
func (s *HBaseDelTestSuit) 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 *HBaseDelTestSuit) 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 *HBaseDelTestSuit) TestDel(c *C) {
d := NewDelete([]byte("hello"))
d.AddFamily([]byte("cf"))
d.AddFamily([]byte("cf1"))
msg := d.ToProto()
p, ok := msg.(*proto.MutationProto)
c.Assert(ok, IsTrue)
c.Assert(string(p.Row), Equals, "hello")
c.Assert(*p.MutateType, Equals, *proto.MutationProto_DELETE.Enum())
cv := p.GetColumnValue()
c.Assert(cv, HasLen, 2)
for _, v := range cv {
c.Assert(v.QualifierValue, HasLen, 1)
c.Assert(*v.QualifierValue[0].DeleteType, Equals, *proto.MutationProto_DELETE_FAMILY.Enum())
}
d = NewDelete([]byte("hello"))
d.AddStringColumn("cf\x00", "q")
d.AddStringColumn("cf", "q")
d.AddStringColumn("cf", "q")
msg = d.ToProto()
p, _ = msg.(*proto.MutationProto)
cv = p.GetColumnValue()
c.Assert(cv, HasLen, 2)
for _, v := range cv {
c.Assert(v.QualifierValue, HasLen, 1)
c.Assert(*v.QualifierValue[0].DeleteType, Equals, *proto.MutationProto_DELETE_MULTIPLE_VERSIONS.Enum())
}
}
func (s *HBaseDelTestSuit) TestDelWithClient(c *C) {
// Test put a new value.
p := NewPut([]byte("test"))
p.AddValue([]byte("cf"), []byte("q"), []byte("val"))
ok, err := s.cli.Put(s.tableName, p)
c.Assert(ok, IsTrue)
c.Assert(err, IsNil)
g := NewGet([]byte("test"))
g.AddStringFamily("cf")
r, err := s.cli.Get(s.tableName, g)
c.Assert(err, IsNil)
c.Assert(string(r.Columns["cf:q"].Value), Equals, "val")
// Test delte the value.
d := NewDelete([]byte("test"))
d.AddColumn([]byte("cf"), []byte("q"))
b, err := s.cli.Delete(s.tableName, d)
c.Assert(err, IsNil)
c.Assert(b, IsTrue)
r, err = s.cli.Get(s.tableName, g)
c.Assert(err, IsNil)
c.Assert(r, IsNil)
}