本文整理汇总了Golang中github.com/tsuna/gohbase.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMultiplePutsGetsSequentially
func TestMultiplePutsGetsSequentially(t *testing.T) {
const num_ops = 100
keyPrefix := "row3"
headers := map[string][]string{"cf": nil}
c := gohbase.NewClient(*host)
err := performNPuts(keyPrefix, num_ops)
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
for i := num_ops - 1; i >= 0; i-- {
key := keyPrefix + fmt.Sprintf("%d", i)
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(headers))
rsp, err := c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
}
if len(rsp.Result.Cell) != 1 {
t.Errorf("Incorrect number of cells returned by Get: %d", len(rsp.Result.Cell))
}
rsp_value := rsp.Result.Cell[0].GetValue()
if !bytes.Equal(rsp_value, []byte(fmt.Sprintf("%d", i))) {
t.Errorf("Get returned an incorrect result. Expected: %v, Got: %v",
[]byte(fmt.Sprintf("%d", i)), rsp_value)
}
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:26,代码来源:integration_test.go
示例2: TestCreateTable
func TestCreateTable(t *testing.T) {
testTableName := "test1_" + getTimestampString()
t.Log("testTableName=" + testTableName)
ac := gohbase.NewAdminClient(*host)
crt := hrpc.NewCreateTable(context.Background(), []byte(testTableName), cFamilies)
if err := ac.CreateTable(crt); err != nil {
t.Errorf("CreateTable returned an error: %v", err)
}
// check in hbase:meta if there's a region for the table
c := gohbase.NewClient(*host)
metaKey := testTableName + ",,"
keyFilter := filter.NewPrefixFilter([]byte(metaKey))
scan, err := hrpc.NewScanStr(context.Background(), metaTableName, hrpc.Filters(keyFilter))
if err != nil {
t.Fatalf("Failed to create Scan request: %s", err)
}
rsp, err := c.Scan(scan)
if err != nil {
t.Errorf("Scan returned an error: %v", err)
}
if len(rsp) != 1 {
t.Errorf("Meta returned %s rows for prefix '%s' , want 1", len(rsp), metaKey)
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:28,代码来源:table_test.go
示例3: TestPutMultipleCells
func TestPutMultipleCells(t *testing.T) {
key := "row2.5"
values := map[string]map[string][]byte{"cf": map[string][]byte{}, "cf2": map[string][]byte{}}
values["cf"]["a"] = []byte("a")
values["cf"]["b"] = []byte("b")
values["cf2"]["a"] = []byte("a")
c := gohbase.NewClient(*host)
putRequest, err := hrpc.NewPutStr(context.Background(), table, key, values)
_, err = c.Put(putRequest)
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
families := map[string][]string{"cf": nil, "cf2": nil}
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(families))
rsp, err := c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
}
cells := rsp.GetResult().Cell
if len(cells) != 3 {
t.Errorf("Get expected 3 cells. Received: %d", len(cells))
}
for _, cell := range cells {
if !bytes.Equal(cell.GetQualifier(), cell.GetValue()) {
t.Errorf("Get returned an incorrect result. Expected: %v, Received: %v",
cell.GetQualifier(), cell.GetValue())
}
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:30,代码来源:integration_test.go
示例4: TestGetMultipleCells
func TestGetMultipleCells(t *testing.T) {
key := "row1.75"
c := gohbase.NewClient(*host, gohbase.FlushInterval(time.Millisecond*2))
err := insertKeyValue(c, key, "cf", []byte("cf"))
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
err = insertKeyValue(c, key, "cf2", []byte("cf2"))
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
families := map[string][]string{"cf": nil, "cf2": nil}
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(families))
rsp, err := c.Get(get)
cells := rsp.GetResult().Cell
num_results := len(cells)
if num_results != 2 {
t.Errorf("Get expected 2 cells. Received: %d", num_results)
}
for _, cell := range cells {
if !bytes.Equal(cell.GetFamily(), cell.GetValue()) {
t.Errorf("Get returned an incorrect result. Expected: %v, Received: %v",
cell.GetFamily(), cell.GetValue())
}
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:27,代码来源:integration_test.go
示例5: main
func main() {
client := gohbase.NewClient(*zkquorum)
err := client.CheckTable(context.Background(), "aeris")
if err != nil {
log.Fatalf("Fail: %s", err)
}
log.Printf("get returned")
}
开发者ID:jfrabaute,项目名称:gohbase,代码行数:8,代码来源:main.go
示例6: TestIncrement
func TestIncrement(t *testing.T) {
c := gohbase.NewClient(*host)
key := "row102"
// test incerement
incRequest, err := hrpc.NewIncStrSingle(context.Background(), table, key, "cf", "a", 1)
result, err := c.Increment(incRequest)
if err != nil {
t.Fatalf("Increment returned an error: %v", err)
}
if result != 1 {
t.Fatalf("Increment's result is %d, want 1", result)
}
incRequest, err = hrpc.NewIncStrSingle(context.Background(), table, key, "cf", "a", 5)
result, err = c.Increment(incRequest)
if err != nil {
t.Fatalf("Increment returned an error: %v", err)
}
if result != 6 {
t.Fatalf("Increment's result is %d, want 6", result)
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:25,代码来源:integration_test.go
示例7: TestChangingRegionServers
// Note: This function currently causes an infinite loop in the client throwing the error -
// 2015/06/19 14:34:11 Encountered an error while reading: Failed to read from the RS: EOF
func TestChangingRegionServers(t *testing.T) {
key := "row8"
val := []byte("1")
headers := map[string][]string{"cf": nil}
if host == nil {
t.Fatal("Host is not set!")
}
c := gohbase.NewClient(*host)
err := insertKeyValue(c, key, "cf", val)
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
// RegionServer 1 hosts all the current regions.
// Now launch servers 2,3
test.LaunchRegionServers([]string{"2", "3"})
// Now (gracefully) stop servers 1,2.
// All regions should now be on server 3.
test.StopRegionServers([]string{"1", "2"})
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(headers))
rsp, err := c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
}
rsp_value := rsp.Result.Cell[0].GetValue()
if !bytes.Equal(rsp_value, val) {
t.Errorf("Get returned an incorrect result. Expected: %v, Received: %v",
val, rsp_value)
}
// Clean up by re-launching RS1 and closing RS3
test.LaunchRegionServers([]string{"1"})
test.StopRegionServers([]string{"3"})
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:37,代码来源:integration_test.go
示例8: TestDeleteTimestamp
func TestDeleteTimestamp(t *testing.T) {
key := "TestDeleteTimestamp"
c := gohbase.NewClient(*host)
var putTs uint64 = 50
timestamp := time.Unix(0, int64(putTs*1e6))
err := insertKeyValue(c, key, "cf", []byte("1"), hrpc.Timestamp(timestamp))
if err != nil {
t.Fatalf("Put failed: %s", err)
}
deleteRequest, err := hrpc.NewDelStr(context.Background(), table, key,
map[string]map[string][]byte{"cf": map[string][]byte{"a": nil}},
hrpc.Timestamp(timestamp))
_, err = c.Delete(deleteRequest)
if err != nil {
t.Fatalf("Delete failed: %s", err)
}
get, err := hrpc.NewGetStr(context.Background(), table, key,
hrpc.Families(map[string][]string{"cf": nil}))
rsp, err := c.Get(get)
if err != nil {
t.Fatalf("Get failed: %s", err)
}
if len(rsp.Cells) != 0 {
t.Errorf("Timestamp wasn't deleted, get result length: %d", len(rsp.Cells))
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:26,代码来源:integration_test.go
示例9: TestGetTimeRangeVersions
func TestGetTimeRangeVersions(t *testing.T) {
key := "TestGetTimeRangeVersions"
c := gohbase.NewClient(*host)
err := insertKeyValue(c, key, "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 50*1e6)))
if err != nil {
t.Fatalf("Put failed: %s", err)
}
err = insertKeyValue(c, key, "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 51*1e6)))
if err != nil {
t.Fatalf("Put failed: %s", err)
}
err = insertKeyValue(c, key, "cf", []byte("1"), hrpc.Timestamp(time.Unix(0, 49*1e6)))
if err != nil {
t.Fatalf("Put failed: %s", err)
}
var maxVersions uint32 = 2
get, err := hrpc.NewGetStr(context.Background(), table, key,
hrpc.Families(map[string][]string{"cf": nil}), hrpc.TimeRange(time.Unix(0, 0),
time.Unix(0, 51*1e6)), hrpc.MaxVersions(maxVersions))
rsp, err := c.Get(get)
if err != nil {
t.Fatalf("Get failed: %s", err)
}
if uint32(len(rsp.Cells)) != maxVersions {
t.Fatalf("Expected versions: %d, Got versions: %d", maxVersions, len(rsp.Cells))
}
getTs1 := *rsp.Cells[0].Timestamp
if getTs1 != 50 {
t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v",
50, getTs1)
}
getTs2 := *rsp.Cells[1].Timestamp
if getTs2 != 49 {
t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v",
49, getTs2)
}
// get with no versions set
get, err = hrpc.NewGetStr(context.Background(), table, key,
hrpc.Families(map[string][]string{"cf": nil}), hrpc.TimeRange(time.Unix(0, 0),
time.Unix(0, 51*1e6)))
rsp, err = c.Get(get)
if err != nil {
t.Fatalf("Get failed: %s", err)
}
if uint32(len(rsp.Cells)) != 1 {
t.Fatalf("Expected versions: %d, Got versions: %d", 1, len(rsp.Cells))
}
getTs1 = *rsp.Cells[0].Timestamp
if getTs1 != 50 {
t.Errorf("Timestamps are not the same. Expected Time: %v, Got Time: %v",
50, getTs1)
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:55,代码来源:integration_test.go
示例10: performNPuts
// Helper function. Given a key_prefix, num_ops, performs num_ops.
func performNPuts(keyPrefix string, num_ops int) error {
c := gohbase.NewClient(*host)
for i := 0; i < num_ops; i++ {
key := keyPrefix + fmt.Sprintf("%d", i)
err := insertKeyValue(c, key, "cf", []byte(fmt.Sprintf("%d", i)))
if err != nil {
return err
}
}
return nil
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:12,代码来源:integration_test.go
示例11: TestCheckAndPutNotPut
func TestCheckAndPutNotPut(t *testing.T) {
key := "row101"
c := gohbase.NewClient(*host)
values := map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("lol")}}
appRequest, err := hrpc.NewAppStr(context.Background(), table, key, values)
_, err = c.CheckAndPut(appRequest, "cf", "a", []byte{})
if err == nil {
t.Error("CheckAndPut: should not allow anything but Put request")
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:11,代码来源:integration_test.go
示例12: testTsunaHbaseClientStablity
func testTsunaHbaseClientStablity(concurrency, interval int) {
client := gohbase.NewClient("172.16.13.94:2181,172.16.13.94:2182,172.16.13.94:2183")
st := time.Now().Unix()
// actions := []string{"get",}
actions := []string{"get", "put", "delete"}
res := map[string]map[string]*int64{}
for _, action := range actions {
total, failed := int64(0), int64(0)
res[action] = map[string]*int64{
"total": &total,
"failed": &failed,
}
}
wg := &sync.WaitGroup{}
wg.Add(concurrency)
failCount := make([]int, concurrency)
for j := 0; j < concurrency; j++ {
go func(seq int) {
defer wg.Done()
for {
actionIndex, _ := IntRange(0, len(actions))
action := actions[actionIndex]
atomic.AddInt64(res[action]["total"], 1)
err := doTest(client, action)
if err != nil {
atomic.AddInt64(res[action]["failed"], 1)
// return
}
if interval > 0 {
time.Sleep(time.Duration(int64(interval)) * time.Millisecond)
}
// fmt.Printf("getRes is %v", getRes)
}
}(j)
}
go func() {
for {
time.Sleep(10 * time.Second)
for action, actionRes := range res {
fmt.Printf("action %s total %d failed %d\n", action, *actionRes["total"], *actionRes["failed"])
}
}
}()
wg.Wait()
failCountSum := 0
for _, curFailCount := range failCount {
failCountSum += curFailCount
}
et := time.Now().Unix()
fmt.Printf("cost: %d, total: %d, failed: %d\n", et-st, 1, failCountSum)
}
开发者ID:fzh890523,项目名称:go_sth,代码行数:51,代码来源:test_hbase_client.go
示例13: TestCheckAndPut
func TestCheckAndPut(t *testing.T) {
c := gohbase.NewClient(*host)
key := "row100"
ef := "cf"
eq := "a"
var castests = []struct {
inValues map[string]map[string][]byte
inExpectedValue []byte
out bool
}{
{map[string]map[string][]byte{"cf": map[string][]byte{"b": []byte("2")}},
nil, true}, // nil instead of empty byte array
{map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("1")}},
[]byte{}, true},
{map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("1")}},
[]byte{}, false},
{map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("2")}},
[]byte("1"), true},
{map[string]map[string][]byte{"cf": map[string][]byte{"b": []byte("2")}},
[]byte("2"), true}, // put diff column
{map[string]map[string][]byte{"cf": map[string][]byte{"b": []byte("2")}},
[]byte{}, false}, // diff column
{map[string]map[string][]byte{"cf": map[string][]byte{
"b": []byte("100"),
"a": []byte("100"),
}}, []byte("2"), true}, // multiple values
}
for _, tt := range castests {
putRequest, err := hrpc.NewPutStr(context.Background(), table, key, tt.inValues)
if err != nil {
t.Fatalf("NewPutStr returned an error: %v", err)
}
casRes, err := c.CheckAndPut(putRequest, ef, eq, tt.inExpectedValue)
if err != nil {
t.Fatalf("CheckAndPut error: %s", err)
}
if casRes != tt.out {
t.Errorf("CheckAndPut with put values=%q and expectedValue=%q returned %v, want %v",
tt.inValues, tt.inExpectedValue, casRes, tt.out)
}
}
// TODO: check the resulting state by performing a Get request
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:50,代码来源:integration_test.go
示例14: BenchmarkGet
func BenchmarkGet(b *testing.B) {
b.ReportAllocs()
keyPrefix := "row10"
err := performNPuts(keyPrefix, b.N)
if err != nil {
b.Errorf("Put returned an error: %v", err)
}
c := gohbase.NewClient(*host)
b.ResetTimer()
headers := map[string][]string{"cf": nil}
for i := 0; i < b.N; i++ {
key := keyPrefix + fmt.Sprintf("%d", i)
get, _ := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(headers))
c.Get(get)
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:16,代码来源:integration_test.go
示例15: TestGetBadColumnFamily
func TestGetBadColumnFamily(t *testing.T) {
key := "row1.625"
c := gohbase.NewClient(*host)
err := insertKeyValue(c, key, "cf", []byte("Bad!"))
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
families := map[string][]string{"badcf": nil}
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(families))
rsp, err := c.Get(get)
if err == nil {
t.Errorf("Get didn't return an error! (It should have)")
}
if rsp.GetResult() != nil {
t.Errorf("Get expected no result. Received: %v", rsp.GetResult())
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:17,代码来源:integration_test.go
示例16: TestCheckAndPutParallel
func TestCheckAndPutParallel(t *testing.T) {
c := gohbase.NewClient(*host)
keyPrefix := "row100.5"
// TODO: Currently have to CheckTable before initiating the requests
// otherwise we face runaway client generation - one for each request.
c.CheckTable(context.Background(), table)
values := map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("1")}}
capTestFunc := func(p *hrpc.Mutate, ch chan bool) {
casRes, err := c.CheckAndPut(p, "cf", "a", []byte{})
if err != nil {
t.Errorf("CheckAndPut error: %s", err)
}
ch <- casRes
}
// make 10 pairs of CheckAndPut requests
for i := 0; i < 10; i++ {
ch := make(chan bool, 2)
putRequest1, err := hrpc.NewPutStr(context.Background(), table, keyPrefix+string(i), values)
if err != nil {
t.Fatalf("NewPutStr returned an error: %v", err)
}
putRequest2, err := hrpc.NewPutStr(context.Background(), table, keyPrefix+string(i), values)
if err != nil {
t.Fatalf("NewPutStr returned an error: %v", err)
}
go capTestFunc(putRequest1, ch)
go capTestFunc(putRequest2, ch)
first := <-ch
second := <-ch
if first && second {
t.Error("CheckAndPut: both requests cannot succeed")
}
if !first && !second {
t.Error("CheckAndPut: both requests cannot fail")
}
}
}
开发者ID:cloudflare,项目名称:gohbase,代码行数:46,代码来源:integration_test.go
示例17: TestGet
func TestGet(t *testing.T) {
key := "row1"
val := []byte("1")
headers := map[string][]string{"cf": nil}
if host == nil {
t.Fatal("Host is not set!")
}
c := gohbase.NewClient(*host)
err := insertKeyValue(c, key, "cf", val)
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(headers))
if err != nil {
t.Fatalf("Failed to create Get request: %s", err)
}
rsp, err := c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
}
rsp_value := rsp.Result.Cell[0].GetValue()
if !bytes.Equal(rsp_value, val) {
t.Errorf("Get returned an incorrect result. Expected: %v, Got: %v",
val, rsp_value)
}
get.ExistsOnly()
rsp, err = c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
} else if !*rsp.Result.Exists {
t.Error("Get claimed that our row didn't exist")
}
ctx, _ := context.WithTimeout(context.Background(), 0)
get, err = hrpc.NewGetStr(ctx, table, key, hrpc.Families(headers))
if err != nil {
t.Fatalf("Failed to create Get request: %s", err)
}
_, err = c.Get(get)
if err != gohbase.ErrDeadline {
t.Errorf("Get ignored the deadline")
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:46,代码来源:integration_test.go
示例18: DeleteTable
// DeleteTable finds the HBase shell via the HBASE_HOME environment variable,
// and disables and drops the given table
func DeleteTable(host, table string) error {
// TODO: We leak this client.
ac := gohbase.NewClient(host, gohbase.Admin())
dit := hrpc.NewDisableTable(context.Background(), []byte(table))
_, err := ac.SendRPC(dit)
if err != nil {
if !strings.Contains(err.Error(), "TableNotEnabledException") {
return err
}
}
det := hrpc.NewDeleteTable(context.Background(), []byte(table))
_, err = ac.SendRPC(det)
if err != nil {
return err
}
return nil
}
开发者ID:jfrabaute,项目名称:gohbase,代码行数:20,代码来源:test.go
示例19: TestGetDoesntExist
func TestGetDoesntExist(t *testing.T) {
key := "row1.5"
c := gohbase.NewClient(*host)
headers := map[string][]string{"cf": nil}
get, err := hrpc.NewGetStr(context.Background(), table, key, hrpc.Families(headers))
rsp, err := c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
} else if results := len(rsp.GetResult().Cell); results != 0 {
t.Errorf("Get expected 0 cells. Received: %d", results)
}
get.ExistsOnly()
rsp, err = c.Get(get)
if err != nil {
t.Errorf("Get returned an error: %v", err)
} else if *rsp.Result.Exists {
t.Error("Get claimed that our non-existent row exists")
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:20,代码来源:integration_test.go
示例20: TestPut
func TestPut(t *testing.T) {
key := "row2"
values := map[string]map[string][]byte{"cf": map[string][]byte{"a": []byte("1")}}
if host == nil {
t.Fatal("Host is not set!")
}
c := gohbase.NewClient(*host)
putRequest, err := hrpc.NewPutStr(context.Background(), table, key, values)
_, err = c.Put(putRequest)
if err != nil {
t.Errorf("Put returned an error: %v", err)
}
ctx, _ := context.WithTimeout(context.Background(), 0)
putRequest, err = hrpc.NewPutStr(ctx, table, key, values)
_, err = c.Put(putRequest)
if err != gohbase.ErrDeadline {
t.Errorf("Put ignored the deadline")
}
}
开发者ID:henrylee2cn,项目名称:gohbase,代码行数:20,代码来源:integration_test.go
注:本文中的github.com/tsuna/gohbase.NewClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论