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 pathget_test.go
93 lines (77 loc) · 1.92 KB
/
get_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
package hbase
import (
"bytes"
"runtime"
"strconv"
"sync"
. "github.com/pingcap/check"
"github.com/pingcap/go-hbase/proto"
)
type HBaseGetTestSuit struct {
cli HBaseClient
tableName string
}
var _ = Suite(&HBaseGetTestSuit{})
func (s *HBaseGetTestSuit) SetUpTest(c *C) {
var err error
s.cli, err = NewClient(getTestZkHosts(), "/hbase")
c.Assert(err, IsNil)
s.tableName = "t1"
tblDesc := NewTableDesciptor(s.tableName)
cf := NewColumnFamilyDescriptor("cf")
tblDesc.AddColumnDesc(cf)
err = s.cli.CreateTable(tblDesc, nil)
c.Assert(err, IsNil)
}
func (s *HBaseGetTestSuit) 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 *HBaseGetTestSuit) TestGet(c *C) {
g := NewGet([]byte("row"))
g.AddFamily([]byte("cf"))
g.AddColumn([]byte("cf"), []byte("c"))
g.AddColumn([]byte("cf"), []byte("v"))
g.AddFamily([]byte("cf1"))
msg := g.ToProto()
p, _ := msg.(*proto.Get)
c.Assert(p.Column, HasLen, 2)
for _, col := range p.Column {
if bytes.Compare([]byte("cf"), col.Family) == 0 {
c.Assert(col.Qualifier, HasLen, 2)
} else {
c.Assert(col.Qualifier, HasLen, 0)
}
}
}
func (s *HBaseGetTestSuit) TestGetWithClient(c *C) {
// get item not exists
g := NewGet([]byte("nosuchrow"))
r, err := s.cli.Get("nosuchtable", g)
c.Assert(err, NotNil)
c.Assert(r, IsNil)
r, err = s.cli.Get("t1", g)
c.Assert(r, IsNil)
c.Assert(err, IsNil)
}
func (s *HBaseGetTestSuit) TestConcurrentGet(c *C) {
runtime.GOMAXPROCS(runtime.NumCPU())
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
p := NewPut([]byte("test"))
p.AddValue([]byte("cf"), []byte("q"), []byte(strconv.Itoa(i)))
b, err := s.cli.Put(s.tableName, p)
c.Assert(b, IsTrue)
c.Assert(err, IsNil)
}(i)
}
wg.Wait()
g := NewGet([]byte("test"))
_, err := s.cli.Get(s.tableName, g)
c.Assert(err, IsNil)
}