Ejemplo n.º 1
0
func TestMultiplePutsGetsSequentially(t *testing.T) {
	const num_ops = 100
	keyPrefix := "row3"
	headers := map[string][]string{"cf": nil}
	c := gohbase.NewClient(*host, gohbase.FlushInterval(time.Millisecond))
	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.Cells) != 1 {
			t.Errorf("Incorrect number of cells returned by Get: %d", len(rsp.Cells))
		}
		rsp_value := rsp.Cells[0].Value
		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)
		}
	}
}
Ejemplo n.º 2
0
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())
		}
	}
}
Ejemplo n.º 3
0
func main() {
	client := gohbase.NewClient("localhost", gohbase.RpcQueueSize(1), gohbase.FlushInterval(time.Nanosecond))

	t := time.Now()
	for i := 0; i < 100; i++ {
		// Values maps a ColumnFamily -> Qualifiers -> Values.
		values := map[string]map[string][]byte{"cf": map[string][]byte{"ab": []byte("kmztest")}}
		putRequest, err := hrpc.NewPutStr(context.Background(), "test", "key"+strconv.Itoa(i), values)
		checkErr(err)
		_, err = client.Put(putRequest)
		checkErr(err)
	}
	fmt.Println(float64(time.Now().UnixNano()-t.UnixNano()) / 1000000)

	fmt.Println("=====================")

	getRequest, err := hrpc.NewGetStr(context.Background(), "test", "row")
	checkErr(err)
	getRsp, err := client.Get(getRequest)
	checkErr(err)
	fmt.Println(getRsp)

}