Exemplo n.º 1
0
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))
	}
}
Exemplo n.º 2
0
func doTest(client gohbase.Client, action string) (err error) {

	switch action {
	case "get":
		var getReq *hrpc.Get
		getReq, err = hrpc.NewGetStr(context.Background(), "t1", "10001")
		if err != nil {
			fmt.Printf("hrpc.NewGetStr failed, err is %v", err)
			return
		}
		_, err = client.Get(getReq)
		if err != nil {
			fmt.Printf("client.Get failed, err is %v", err)
			return
		}
	case "put":
		var putReq *hrpc.Mutate
		rowID, _ := IntRange(0, 3000000)
		putReq, err = hrpc.NewPutStr(context.Background(), "t1", strconv.Itoa(rowID), map[string]map[string][]byte{
			"fam1": map[string][]byte{
				"col1": []byte("testvalue"),
			},
		})
		if err != nil {
			fmt.Printf("hrpc.NewPutStr failed, err is %v", err)
			return
		}
		_, err = client.Put(putReq)
		if err != nil {
			fmt.Printf("client.Put failed, err is %v", err)
			return
		}
	case "delete":
		var delReq *hrpc.Mutate
		rowID, _ := IntRange(0, 3000000)
		delReq, err = hrpc.NewDelStr(context.Background(), "t1", strconv.Itoa(rowID), map[string]map[string][]byte{
			"fam1": map[string][]byte{
				"col1": []byte("testvalue"),
			},
		})
		if err != nil {
			fmt.Printf("hrpc.NewDelStr failed, err is %v", err)
			return
		}
		_, err = client.Delete(delReq)
		if err != nil {
			fmt.Printf("client.Del failed, err is %v", err)
			return
		}
	}
	return
}